00001 /************************************************* 00002 * Perl-Compatible Regular Expressions * 00003 *************************************************/ 00004 00005 /* PCRE is a library of functions to support regular expressions whose syntax 00006 and semantics are as close as possible to those of the Perl 5 language. 00007 00008 Written by Philip Hazel 00009 Copyright (c) 1997-2009 University of Cambridge 00010 00011 ----------------------------------------------------------------------------- 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 00015 * Redistributions of source code must retain the above copyright notice, 00016 this list of conditions and the following disclaimer. 00017 00018 * Redistributions in binary form must reproduce the above copyright 00019 notice, this list of conditions and the following disclaimer in the 00020 documentation and/or other materials provided with the distribution. 00021 00022 * Neither the name of the University of Cambridge nor the names of its 00023 contributors may be used to endorse or promote products derived from 00024 this software without specific prior written permission. 00025 00026 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00027 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00030 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00031 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00032 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00033 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00034 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00035 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00036 POSSIBILITY OF SUCH DAMAGE. 00037 ----------------------------------------------------------------------------- 00038 */ 00039 00040 00041 /* This module contains an internal function that is used to match an extended 00042 class. It is used by both pcre_exec() and pcre_def_exec(). */ 00043 00044 00045 #ifdef HAVE_CONFIG_H 00046 #include "config.h" 00047 #else if defined(_WINDOWS) 00048 #include <spl/configwin32.h> 00049 #endif 00050 00051 00052 #include "pcre_internal.h" 00053 00054 00055 /************************************************* 00056 * Match character against an XCLASS * 00057 *************************************************/ 00058 00059 /* This function is called to match a character against an extended class that 00060 might contain values > 255 and/or Unicode properties. 00061 00062 Arguments: 00063 c the character 00064 data points to the flag byte of the XCLASS data 00065 00066 Returns: TRUE if character matches, else FALSE 00067 */ 00068 00069 BOOL 00070 _pcre_xclass(int c, const uschar *data) 00071 { 00072 int t; 00073 BOOL negated = (*data & XCL_NOT) != 0; 00074 00075 /* Character values < 256 are matched against a bitmap, if one is present. If 00076 not, we still carry on, because there may be ranges that start below 256 in the 00077 additional data. */ 00078 00079 if (c < 256) 00080 { 00081 if ((*data & XCL_MAP) != 0 && (data[1 + c/8] & (1 << (c&7))) != 0) 00082 return !negated; /* char found */ 00083 } 00084 00085 /* First skip the bit map if present. Then match against the list of Unicode 00086 properties or large chars or ranges that end with a large char. We won't ever 00087 encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */ 00088 00089 if ((*data++ & XCL_MAP) != 0) data += 32; 00090 00091 while ((t = *data++) != XCL_END) 00092 { 00093 int x, y; 00094 if (t == XCL_SINGLE) 00095 { 00096 GETCHARINC(x, data); 00097 if (c == x) return !negated; 00098 } 00099 else if (t == XCL_RANGE) 00100 { 00101 GETCHARINC(x, data); 00102 GETCHARINC(y, data); 00103 if (c >= x && c <= y) return !negated; 00104 } 00105 00106 #ifdef SUPPORT_UCP 00107 else /* XCL_PROP & XCL_NOTPROP */ 00108 { 00109 const ucd_record *prop = GET_UCD(c); 00110 00111 switch(*data) 00112 { 00113 case PT_ANY: 00114 if (t == XCL_PROP) return !negated; 00115 break; 00116 00117 case PT_LAMP: 00118 if ((prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || prop->chartype == ucp_Lt) == 00119 (t == XCL_PROP)) return !negated; 00120 break; 00121 00122 case PT_GC: 00123 if ((data[1] == _pcre_ucp_gentype[prop->chartype]) == (t == XCL_PROP)) return !negated; 00124 break; 00125 00126 case PT_PC: 00127 if ((data[1] == prop->chartype) == (t == XCL_PROP)) return !negated; 00128 break; 00129 00130 case PT_SC: 00131 if ((data[1] == prop->script) == (t == XCL_PROP)) return !negated; 00132 break; 00133 00134 /* This should never occur, but compilers may mutter if there is no 00135 default. */ 00136 00137 default: 00138 return FALSE; 00139 } 00140 00141 data += 2; 00142 } 00143 #endif /* SUPPORT_UCP */ 00144 } 00145 00146 return negated; /* char did not match */ 00147 } 00148 00149 /* End of pcre_xclass.c */