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

Diff of /code/trunk/pcre_xclass.c

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

revision 835 by ph10, Thu Jun 3 19:18:24 2010 UTC revision 836 by ph10, Wed Dec 28 17:16:11 2011 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-2010 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 64  Returns:      TRUE if character matches, Line 64  Returns:      TRUE if character matches,
64  */  */
65    
66  BOOL  BOOL
67  _pcre_xclass(int c, const uschar *data)  PRIV(xclass)(int c, const pcre_uchar *data, BOOL utf)
68  {  {
69  int t;  int t;
70  BOOL negated = (*data & XCL_NOT) != 0;  BOOL negated = (*data & XCL_NOT) != 0;
71    
72    (void)utf;
73    #ifdef COMPILE_PCRE8
74    /* In 8 bit mode, this must always be TRUE. Help the compiler to know that. */
75    utf = TRUE;
76    #endif
77    
78  /* Character values < 256 are matched against a bitmap, if one is present. If  /* Character values < 256 are matched against a bitmap, if one is present. If
79  not, we still carry on, because there may be ranges that start below 256 in the  not, we still carry on, because there may be ranges that start below 256 in the
80  additional data. */  additional data. */
81    
82  if (c < 256)  if (c < 256)
83    {    {
84    if ((*data & XCL_MAP) != 0 && (data[1 + c/8] & (1 << (c&7))) != 0)    if ((*data & XCL_MAP) != 0 &&
85      return !negated;   /* char found */      (((pcre_uint8 *)(data + 1))[c/8] & (1 << (c&7))) != 0)
86        return !negated; /* char found */
87    }    }
88    
89  /* First skip the bit map if present. Then match against the list of Unicode  /* First skip the bit map if present. Then match against the list of Unicode
90  properties or large chars or ranges that end with a large char. We won't ever  properties or large chars or ranges that end with a large char. We won't ever
91  encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */  encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */
92    
93  if ((*data++ & XCL_MAP) != 0) data += 32;  if ((*data++ & XCL_MAP) != 0) data += 32 / sizeof(pcre_uchar);
94    
95  while ((t = *data++) != XCL_END)  while ((t = *data++) != XCL_END)
96    {    {
97    int x, y;    int x, y;
98    if (t == XCL_SINGLE)    if (t == XCL_SINGLE)
99      {      {
100      GETCHARINC(x, data);  #ifdef SUPPORT_UTF
101        if (utf)
102          {
103          GETCHARINC(x, data); /* macro generates multiple statements */
104          }
105        else
106    #endif
107          x = *data++;
108      if (c == x) return !negated;      if (c == x) return !negated;
109      }      }
110    else if (t == XCL_RANGE)    else if (t == XCL_RANGE)
111      {      {
112      GETCHARINC(x, data);  #ifdef SUPPORT_UTF
113      GETCHARINC(y, data);      if (utf)
114          {
115          GETCHARINC(x, data); /* macro generates multiple statements */
116          GETCHARINC(y, data); /* macro generates multiple statements */
117          }
118        else
119    #endif
120          {
121          x = *data++;
122          y = *data++;
123          }
124      if (c >= x && c <= y) return !negated;      if (c >= x && c <= y) return !negated;
125      }      }
126    
# Line 117  while ((t = *data++) != XCL_END) Line 141  while ((t = *data++) != XCL_END)
141        break;        break;
142    
143        case PT_GC:        case PT_GC:
144        if ((data[1] == _pcre_ucp_gentype[prop->chartype]) == (t == XCL_PROP))        if ((data[1] == PRIV(ucp_gentype)[prop->chartype]) == (t == XCL_PROP))
145          return !negated;          return !negated;
146        break;        break;
147    
# Line 130  while ((t = *data++) != XCL_END) Line 154  while ((t = *data++) != XCL_END)
154        break;        break;
155    
156        case PT_ALNUM:        case PT_ALNUM:
157        if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
158             _pcre_ucp_gentype[prop->chartype] == ucp_N) == (t == XCL_PROP))             PRIV(ucp_gentype)[prop->chartype] == ucp_N) == (t == XCL_PROP))
159          return !negated;          return !negated;
160        break;        break;
161    
162        case PT_SPACE:    /* Perl space */        case PT_SPACE:    /* Perl space */
163        if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
164             c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)             c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
165               == (t == XCL_PROP))               == (t == XCL_PROP))
166          return !negated;          return !negated;
167        break;        break;
168    
169        case PT_PXSPACE:  /* POSIX space */        case PT_PXSPACE:  /* POSIX space */
170        if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
171             c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||             c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
172             c == CHAR_FF || c == CHAR_CR) == (t == XCL_PROP))             c == CHAR_FF || c == CHAR_CR) == (t == XCL_PROP))
173          return !negated;          return !negated;
174        break;        break;
175    
176        case PT_WORD:        case PT_WORD:
177        if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||        if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
178             _pcre_ucp_gentype[prop->chartype] == ucp_N || c == CHAR_UNDERSCORE)             PRIV(ucp_gentype)[prop->chartype] == ucp_N || c == CHAR_UNDERSCORE)
179               == (t == XCL_PROP))               == (t == XCL_PROP))
180          return !negated;          return !negated;
181        break;        break;

Legend:
Removed from v.835  
changed lines
  Added in v.836

  ViewVC Help
Powered by ViewVC 1.1.5