| 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 | |
| 41 /* This module contains code for searching the table of Unicode character | |
| 42 properties. */ | |
| 43 | |
| 44 #include "pcre_internal.h" | |
| 45 | |
| 46 #include "ucpinternal.h" /* Internal table details */ | |
| 47 #include "ucptable.cpp" /* The table itself */ | |
| 48 | |
| 49 namespace v8 { namespace jscre { | |
| 50 | |
| 51 /************************************************* | |
| 52 * Search table and return other case * | |
| 53 *************************************************/ | |
| 54 | |
| 55 /* If the given character is a letter, and there is another case for the | |
| 56 letter, return the other case. Otherwise, return -1. | |
| 57 | |
| 58 Arguments: | |
| 59 c the character value | |
| 60 | |
| 61 Returns: the other case or -1 if none | |
| 62 */ | |
| 63 | |
| 64 int kjs_pcre_ucp_othercase(unsigned c) | |
| 65 { | |
| 66 int bot = 0; | |
| 67 int top = sizeof(ucp_table) / sizeof(cnode); | |
| 68 int mid; | |
| 69 | |
| 70 /* The table is searched using a binary chop. You might think that using | |
| 71 intermediate variables to hold some of the common expressions would speed | |
| 72 things up, but tests with gcc 3.4.4 on Linux showed that, on the contrary,
it | |
| 73 makes things a lot slower. */ | |
| 74 | |
| 75 for (;;) { | |
| 76 if (top <= bot) | |
| 77 return -1; | |
| 78 mid = (bot + top) >> 1; | |
| 79 if (c == (ucp_table[mid].f0 & f0_charmask)) | |
| 80 break; | |
| 81 if (c < (ucp_table[mid].f0 & f0_charmask)) | |
| 82 top = mid; | |
| 83 else { | |
| 84 if ((ucp_table[mid].f0 & f0_rangeflag) && (c <= (ucp_table[mid].f0 &
f0_charmask) + (ucp_table[mid].f1 & f1_rangemask))) | |
| 85 break; | |
| 86 bot = mid + 1; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 /* Found an entry in the table. Return -1 for a range entry. Otherwise retur
n | |
| 91 the other case if there is one, else -1. */ | |
| 92 | |
| 93 if (ucp_table[mid].f0 & f0_rangeflag) | |
| 94 return -1; | |
| 95 | |
| 96 int offset = ucp_table[mid].f1 & f1_casemask; | |
| 97 if (offset & f1_caseneg) | |
| 98 offset |= f1_caseneg; | |
| 99 return !offset ? -1 : c + offset; | |
| 100 } | |
| 101 | |
| 102 } } // namespace v8::jscre | |
| OLD | NEW |