dvander@2762: /************************************************* dvander@2762: * Perl-Compatible Regular Expressions * dvander@2762: *************************************************/ dvander@2762: dvander@2762: /* PCRE is a library of functions to support regular expressions whose syntax dvander@2762: and semantics are as close as possible to those of the Perl 5 language. dvander@2762: dvander@2762: Written by Philip Hazel dvander@2762: Copyright (c) 1997-2009 University of Cambridge dvander@2762: dvander@2762: ----------------------------------------------------------------------------- dvander@2762: Redistribution and use in source and binary forms, with or without dvander@2762: modification, are permitted provided that the following conditions are met: dvander@2762: dvander@2762: * Redistributions of source code must retain the above copyright notice, dvander@2762: this list of conditions and the following disclaimer. dvander@2762: dvander@2762: * Redistributions in binary form must reproduce the above copyright dvander@2762: notice, this list of conditions and the following disclaimer in the dvander@2762: documentation and/or other materials provided with the distribution. dvander@2762: dvander@2762: * Neither the name of the University of Cambridge nor the names of its dvander@2762: contributors may be used to endorse or promote products derived from dvander@2762: this software without specific prior written permission. dvander@2762: dvander@2762: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" dvander@2762: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE dvander@2762: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE dvander@2762: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE dvander@2762: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR dvander@2762: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF dvander@2762: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS dvander@2762: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN dvander@2762: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) dvander@2762: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE dvander@2762: POSSIBILITY OF SUCH DAMAGE. dvander@2762: ----------------------------------------------------------------------------- dvander@2762: */ dvander@2762: dvander@2762: dvander@2762: /* This module contains an internal function that is used to match an extended dvander@2762: class. It is used by both pcre_exec() and pcre_def_exec(). */ dvander@2762: dvander@2762: dvander@2762: #ifdef HAVE_CONFIG_H dvander@2762: #include "config.h" dvander@2762: #endif dvander@2762: dvander@2762: #include "pcre_internal.h" dvander@2762: dvander@2762: dvander@2762: /************************************************* dvander@2762: * Match character against an XCLASS * dvander@2762: *************************************************/ dvander@2762: dvander@2762: /* This function is called to match a character against an extended class that dvander@2762: might contain values > 255 and/or Unicode properties. dvander@2762: dvander@2762: Arguments: dvander@2762: c the character dvander@2762: data points to the flag byte of the XCLASS data dvander@2762: dvander@2762: Returns: TRUE if character matches, else FALSE dvander@2762: */ dvander@2762: dvander@2762: BOOL dvander@2762: _pcre_xclass(int c, const uschar *data) dvander@2762: { dvander@2762: int t; dvander@2762: BOOL negated = (*data & XCL_NOT) != 0; dvander@2762: dvander@2762: /* Character values < 256 are matched against a bitmap, if one is present. If dvander@2762: not, we still carry on, because there may be ranges that start below 256 in the dvander@2762: additional data. */ dvander@2762: dvander@2762: if (c < 256) dvander@2762: { dvander@2762: if ((*data & XCL_MAP) != 0 && (data[1 + c/8] & (1 << (c&7))) != 0) dvander@2762: return !negated; /* char found */ dvander@2762: } dvander@2762: dvander@2762: /* First skip the bit map if present. Then match against the list of Unicode dvander@2762: properties or large chars or ranges that end with a large char. We won't ever dvander@2762: encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */ dvander@2762: dvander@2762: if ((*data++ & XCL_MAP) != 0) data += 32; dvander@2762: dvander@2762: while ((t = *data++) != XCL_END) dvander@2762: { dvander@2762: int x, y; dvander@2762: if (t == XCL_SINGLE) dvander@2762: { dvander@2762: GETCHARINC(x, data); dvander@2762: if (c == x) return !negated; dvander@2762: } dvander@2762: else if (t == XCL_RANGE) dvander@2762: { dvander@2762: GETCHARINC(x, data); dvander@2762: GETCHARINC(y, data); dvander@2762: if (c >= x && c <= y) return !negated; dvander@2762: } dvander@2762: dvander@2762: #ifdef SUPPORT_UCP dvander@2762: else /* XCL_PROP & XCL_NOTPROP */ dvander@2762: { dvander@2762: const ucd_record *prop = GET_UCD(c); dvander@2762: dvander@2762: switch(*data) dvander@2762: { dvander@2762: case PT_ANY: dvander@2762: if (t == XCL_PROP) return !negated; dvander@2762: break; dvander@2762: dvander@2762: case PT_LAMP: dvander@2762: if ((prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || prop->chartype == ucp_Lt) == dvander@2762: (t == XCL_PROP)) return !negated; dvander@2762: break; dvander@2762: dvander@2762: case PT_GC: dvander@2762: if ((data[1] == _pcre_ucp_gentype[prop->chartype]) == (t == XCL_PROP)) return !negated; dvander@2762: break; dvander@2762: dvander@2762: case PT_PC: dvander@2762: if ((data[1] == prop->chartype) == (t == XCL_PROP)) return !negated; dvander@2762: break; dvander@2762: dvander@2762: case PT_SC: dvander@2762: if ((data[1] == prop->script) == (t == XCL_PROP)) return !negated; dvander@2762: break; dvander@2762: dvander@2762: /* This should never occur, but compilers may mutter if there is no dvander@2762: default. */ dvander@2762: dvander@2762: default: dvander@2762: return FALSE; dvander@2762: } dvander@2762: dvander@2762: data += 2; dvander@2762: } dvander@2762: #endif /* SUPPORT_UCP */ dvander@2762: } dvander@2762: dvander@2762: return negated; /* char did not match */ dvander@2762: } dvander@2762: dvander@2762: /* End of pcre_xclass.c */