| OLD | NEW |
| (Empty) |
| 1 /* This is JavaScriptCore's variant of the PCRE library. While this library | |
| 2 started out as a copy of PCRE, many of the features of PCRE have been | |
| 3 removed. This library now supports only the regular expression features | |
| 4 required by the JavaScript language specification, and has only the functions | |
| 5 needed by JavaScriptCore and the rest of WebKit. | |
| 6 | |
| 7 Originally written by Philip Hazel | |
| 8 Copyright (c) 1997-2006 University of Cambridge | |
| 9 Copyright (C) 2002, 2004, 2006, 2007 Apple Inc. All rights reserved. | |
| 10 | |
| 11 ----------------------------------------------------------------------------- | |
| 12 Redistribution and use in source and binary forms, with or without | |
| 13 modification, are permitted provided that the following conditions are met: | |
| 14 | |
| 15 * Redistributions of source code must retain the above copyright notice, | |
| 16 this list of conditions and the following disclaimer. | |
| 17 | |
| 18 * Redistributions in binary form must reproduce the above copyright | |
| 19 notice, this list of conditions and the following disclaimer in the | |
| 20 documentation and/or other materials provided with the distribution. | |
| 21 | |
| 22 * Neither the name of the University of Cambridge nor the names of its | |
| 23 contributors may be used to endorse or promote products derived from | |
| 24 this software without specific prior written permission. | |
| 25 | |
| 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 28 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 29 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
| 30 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 33 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 34 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 36 POSSIBILITY OF SUCH DAMAGE. | |
| 37 ----------------------------------------------------------------------------- | |
| 38 */ | |
| 39 | |
| 40 /* This module contains an internal function that is used to match an extended | |
| 41 class (one that contains characters whose values are > 255). */ | |
| 42 | |
| 43 #include "pcre_internal.h" | |
| 44 | |
| 45 namespace dart { namespace jscre { | |
| 46 | |
| 47 /************************************************* | |
| 48 * Match character against an XCLASS * | |
| 49 *************************************************/ | |
| 50 | |
| 51 /* This function is called to match a character against an extended class that | |
| 52 might contain values > 255. | |
| 53 | |
| 54 Arguments: | |
| 55 c the character | |
| 56 data points to the flag byte of the XCLASS data | |
| 57 | |
| 58 Returns: true if character matches, else false | |
| 59 */ | |
| 60 | |
| 61 /* Get the next UTF-8 character, advancing the pointer. This is called when we | |
| 62 know we are in UTF-8 mode. */ | |
| 63 | |
| 64 static inline void getUTF8CharAndAdvancePointer(int& c, const unsigned char*& su
bjectPtr) | |
| 65 { | |
| 66 c = *subjectPtr++; | |
| 67 if ((c & 0xc0) == 0xc0) { | |
| 68 int gcaa = kjs_pcre_utf8_table4[c & 0x3f]; /* Number of additional byte
s */ | |
| 69 int gcss = 6 * gcaa; | |
| 70 c = (c & kjs_pcre_utf8_table3[gcaa]) << gcss; | |
| 71 while (gcaa-- > 0) { | |
| 72 gcss -= 6; | |
| 73 c |= (*subjectPtr++ & 0x3f) << gcss; | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 bool kjs_pcre_xclass(int c, const unsigned char* data) | |
| 79 { | |
| 80 bool negated = (*data & XCL_NOT); | |
| 81 | |
| 82 /* Character values < 256 are matched against a bitmap, if one is present. I
f | |
| 83 not, we still carry on, because there may be ranges that start below 256 in
the | |
| 84 additional data. */ | |
| 85 | |
| 86 if (c < 256) { | |
| 87 if ((*data & XCL_MAP) != 0 && (data[1 + c/8] & (1 << (c&7))) != 0) | |
| 88 return !negated; /* char found */ | |
| 89 } | |
| 90 | |
| 91 /* First skip the bit map if present. Then match against the list of Unicode | |
| 92 properties or large chars or ranges that end with a large char. We won't ev
er | |
| 93 encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */ | |
| 94 | |
| 95 if ((*data++ & XCL_MAP) != 0) | |
| 96 data += 32; | |
| 97 | |
| 98 int t; | |
| 99 while ((t = *data++) != XCL_END) { | |
| 100 if (t == XCL_SINGLE) { | |
| 101 int x; | |
| 102 getUTF8CharAndAdvancePointer(x, data); | |
| 103 if (c == x) | |
| 104 return !negated; | |
| 105 } | |
| 106 else if (t == XCL_RANGE) { | |
| 107 int x, y; | |
| 108 getUTF8CharAndAdvancePointer(x, data); | |
| 109 getUTF8CharAndAdvancePointer(y, data); | |
| 110 if (c >= x && c <= y) | |
| 111 return !negated; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 return negated; /* char did not match */ | |
| 116 } | |
| 117 | |
| 118 } } // namespace dart::jscre | |
| OLD | NEW |