/[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 852 by zherczeg, Thu Jan 5 19:18:12 2012 UTC code/trunk/pcre32_ord2utf32.c revision 1055 by chpe, Tue Oct 16 15:53:30 2012 UTC
# 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  #ifdef HAVE_CONFIG_H
45  #include "config.h"  #include "config.h"
46  #endif  #endif
47    
48    /* Generate code with 32 bit character support. */
49    #define COMPILE_PCRE32
50    
51  #include "pcre_internal.h"  #include "pcre_internal.h"
52    
53    #define MASK (0x1fffffu)
54    
55  /*************************************************  /*************************************************
56  *           Maintain reference count             *  *       Convert character value to UTF-32         *
57  *************************************************/  *************************************************/
58    
59  /* 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
60  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!  
61    
62  Arguments:  Arguments:
63    argument_re   points to compiled code    cvalue     the character value
64    adjust        value to add to the count    buffer     pointer to buffer for result - at least 1 pcre_uchars long
65    
66  Returns:        the (possibly updated) count value (a non-negative number), or  Returns:     number of characters placed in the buffer
                 a negative error number  
67  */  */
68    
69  #ifdef COMPILE_PCRE8  int
70  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer)
 pcre_refcount(pcre *argument_re, int adjust)  
 #else  
 PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  
 pcre16_refcount(pcre16 *argument_re, int adjust)  
 #endif  
71  {  {
72  REAL_PCRE *re = (REAL_PCRE *)argument_re;  #ifdef SUPPORT_UTF
73  if (re == NULL) return PCRE_ERROR_NULL;  
74  if (re->magic_number != MAGIC_NUMBER) return PCRE_ERROR_BADMAGIC;  cvalue &= MASK;
75  if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;  
76  re->ref_count = (-adjust > re->ref_count)? 0 :  /* Checking invalid cvalue character, encoded as invalid UTF-32 character */
77                  (adjust + re->ref_count > 65535)? 65535 :  if ((cvalue & 0xfffff800u) == 0xd800u || cvalue >= 0x110000u)
78                  re->ref_count + adjust;    cvalue = 0xfffeu;
79  return re->ref_count;  
80    *buffer = (pcre_uchar)cvalue;
81    return 1;
82    
83    #else /* SUPPORT_UTF */
84    (void)(cvalue);  /* Keep compiler happy; this function won't ever be */
85    (void)(buffer);  /* called when SUPPORT_UTF is not defined. */
86    return 0;
87    #endif /* SUPPORT_UTF */
88  }  }
89    
90  /* End of pcre_refcount.c */  /* End of pcre32_ord2utf32.c */

Legend:
Removed from v.852  
changed lines
  Added in v.1055

  ViewVC Help
Powered by ViewVC 1.1.5