/[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 836 by ph10, Wed Dec 28 17:16:11 2011 UTC code/trunk/pcre32_ord2utf32.c revision 1083 by chpe, Tue Oct 16 15:55:24 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  #include "pcre_internal.h"  /* Generate code with 32 bit character support. */
49    #define COMPILE_PCRE32
50    
51    #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  #ifdef COMPILE_PCRE8  int
68  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  
 pcre_refcount(pcre *argument_re, int adjust)  
 #endif  
69  {  {
70  real_pcre *re = (real_pcre *)argument_re;  #ifdef SUPPORT_UTF
71  if (re == NULL) return PCRE_ERROR_NULL;  
72  if (re->magic_number != MAGIC_NUMBER) return PCRE_ERROR_BADMAGIC;  cvalue &= UTF32_MASK;
73  if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;  
74  re->ref_count = (-adjust > re->ref_count)? 0 :  /* Checking invalid cvalue character, encoded as invalid UTF-32 character */
75                  (adjust + re->ref_count > 65535)? 65535 :  if ((cvalue & 0xfffff800u) == 0xd800u || cvalue >= 0x110000u)
76                  re->ref_count + adjust;    cvalue = 0xfffeu;
77  return re->ref_count;  
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.836  
changed lines
  Added in v.1083

  ViewVC Help
Powered by ViewVC 1.1.5