/[pcre]/code/trunk/pcre32_ord2utf32.c
ViewVC logotype

Diff of /code/trunk/pcre32_ord2utf32.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

code/trunk/pcre_refcount.c revision 199 by ph10, Tue Jul 31 14:39:09 2007 UTC code/trunk/pcre32_ord2utf32.c revision 1083 by chpe, Tue Oct 16 15:55:24 2012 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2012 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 38  POSSIBILITY OF SUCH DAMAGE. Line 38  POSSIBILITY OF SUCH DAMAGE.
38  */  */
39    
40    
41  /* This module contains the external function pcre_refcount(), which is an  /* This file contains a private PCRE function that converts an ordinal
42  auxiliary function that can be used to maintain a reference count in a compiled  character value into a UTF32 string. */
 pattern data block. This might be helpful in applications where the block is  
 shared by different users. */  
43    
44    #ifdef HAVE_CONFIG_H
45    #include "config.h"
46    #endif
47    
48  #ifdef HAVE_CONFIG_H  /* Generate code with 32 bit character support. */
49  #include <config.h>  #define COMPILE_PCRE32
 #endif  
50    
51  #include "pcre_internal.h"  #include "pcre_internal.h"
52    
   
53  /*************************************************  /*************************************************
54  *           Maintain reference count             *  *       Convert character value to UTF-32         *
55  *************************************************/  *************************************************/
56    
57  /* The reference count is a 16-bit field, initialized to zero. It is not  /* This function takes an integer value in the range 0 - 0x10ffff
58  possible to transfer a non-zero count from one host to a different host that  and encodes it as a UTF-32 character in 1 pcre_uchars.
 has a different byte order - though I can't see why anyone in their right mind  
 would ever want to do that!  
59    
60  Arguments:  Arguments:
61    argument_re   points to compiled code    cvalue     the character value
62    adjust        value to add to the count    buffer     pointer to buffer for result - at least 1 pcre_uchars long
63    
64  Returns:        the (possibly updated) count value (a non-negative number), or  Returns:     number of characters placed in the buffer
                 a negative error number  
65  */  */
66    
67  PCRE_EXP_DEFN int  int
68  pcre_refcount(pcre *argument_re, int adjust)  PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer)
69  {  {
70  real_pcre *re = (real_pcre *)argument_re;  #ifdef SUPPORT_UTF
71  if (re == NULL) return PCRE_ERROR_NULL;  
72  re->ref_count = (-adjust > re->ref_count)? 0 :  cvalue &= UTF32_MASK;
73                  (adjust + re->ref_count > 65535)? 65535 :  
74                  re->ref_count + adjust;  /* Checking invalid cvalue character, encoded as invalid UTF-32 character */
75  return re->ref_count;  if ((cvalue & 0xfffff800u) == 0xd800u || cvalue >= 0x110000u)
76      cvalue = 0xfffeu;
77    
78    *buffer = (pcre_uchar)cvalue;
79    return 1;
80    
81    #else /* SUPPORT_UTF */
82    (void)(cvalue);  /* Keep compiler happy; this function won't ever be */
83    (void)(buffer);  /* called when SUPPORT_UTF is not defined. */
84    return 0;
85    #endif /* SUPPORT_UTF */
86  }  }
87    
88  /* End of pcre_refcount.c */  /* End of pcre32_ord2utf32.c */

Legend:
Removed from v.199  
changed lines
  Added in v.1083

  ViewVC Help
Powered by ViewVC 1.1.5