00001 /* This is JavaScriptCore's variant of the PCRE library. While this library 00002 started out as a copy of PCRE, many of the features of PCRE have been 00003 removed. This library now supports only the regular expression features 00004 required by the JavaScript language specification, and has only the functions 00005 needed by JavaScriptCore and the rest of WebKit. 00006 00007 Originally written by Philip Hazel 00008 Copyright (c) 1997-2006 University of Cambridge 00009 Copyright (C) 2002, 2004, 2006, 2007 Apple Inc. All rights reserved. 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 code for searching the table of Unicode character 00042 properties. */ 00043 00044 #include "pcre_internal.h" 00045 00046 #include "ucpinternal.h" /* Internal table details */ 00047 #include "ucptable.cpp" /* The table itself */ 00048 00049 /************************************************* 00050 * Search table and return other case * 00051 *************************************************/ 00052 00053 /* If the given character is a letter, and there is another case for the 00054 letter, return the other case. Otherwise, return -1. 00055 00056 Arguments: 00057 c the character value 00058 00059 Returns: the other case or -1 if none 00060 */ 00061 00062 int kjs_pcre_ucp_othercase(unsigned c) 00063 { 00064 int bot = 0; 00065 int top = sizeof(ucp_table) / sizeof(cnode); 00066 int mid; 00067 00068 /* The table is searched using a binary chop. You might think that using 00069 intermediate variables to hold some of the common expressions would speed 00070 things up, but tests with gcc 3.4.4 on Linux showed that, on the contrary, it 00071 makes things a lot slower. */ 00072 00073 for (;;) { 00074 if (top <= bot) 00075 return -1; 00076 mid = (bot + top) >> 1; 00077 if (c == (ucp_table[mid].f0 & f0_charmask)) 00078 break; 00079 if (c < (ucp_table[mid].f0 & f0_charmask)) 00080 top = mid; 00081 else { 00082 if ((ucp_table[mid].f0 & f0_rangeflag) && (c <= (ucp_table[mid].f0 & f0_charmask) + (ucp_table[mid].f1 & f1_rangemask))) 00083 break; 00084 bot = mid + 1; 00085 } 00086 } 00087 00088 /* Found an entry in the table. Return -1 for a range entry. Otherwise return 00089 the other case if there is one, else -1. */ 00090 00091 if (ucp_table[mid].f0 & f0_rangeflag) 00092 return -1; 00093 00094 int offset = ucp_table[mid].f1 & f1_casemask; 00095 if (offset & f1_caseneg) 00096 offset |= f1_caseneg; 00097 return !offset ? -1 : c + offset; 00098 }