1/* This is JavaScriptCore's variant of the PCRE library. While this library
2started out as a copy of PCRE, many of the features of PCRE have been
3removed. This library now supports only the regular expression features
4required by the JavaScript language specification, and has only the functions
5needed 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, 2008, 2009 Apple Inc. All rights reserved.
10
11-----------------------------------------------------------------------------
12Redistribution and use in source and binary forms, with or without
13modification, 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
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36POSSIBILITY OF SUCH DAMAGE.
37-----------------------------------------------------------------------------
38*/
39
40
41/* This module contains code for searching the table of Unicode character
42properties. */
43
44#include "config.h"
45#include "pcre_internal.h"
46
47#include "ucpinternal.h" /* Internal table details */
48#include "ucptable.cpp" /* The table itself */
49
50/*************************************************
51* Search table and return other case *
52*************************************************/
53
54/* If the given character is a letter, and there is another case for the
55letter, return the other case. Otherwise, return -1.
56
57Arguments:
58 c the character value
59
60Returns: the other case or -1 if none
61*/
62
63int jsc_pcre_ucp_othercase(unsigned c)
64{
65 int bot = 0;
66 int top = sizeof(ucp_table) / sizeof(cnode);
67 int mid;
68
69 /* The table is searched using a binary chop. You might think that using
70 intermediate variables to hold some of the common expressions would speed
71 things up, but tests with gcc 3.4.4 on Linux showed that, on the contrary, it
72 makes things a lot slower. */
73
74 for (;;) {
75 if (top <= bot)
76 return -1;
77 mid = (bot + top) >> 1;
78 if (c == (ucp_table[mid].f0 & f0_charmask))
79 break;
80 if (c < (ucp_table[mid].f0 & f0_charmask))
81 top = mid;
82 else {
83 if ((ucp_table[mid].f0 & f0_rangeflag) && (c <= (ucp_table[mid].f0 & f0_charmask) + (ucp_table[mid].f1 & f1_rangemask)))
84 break;
85 bot = mid + 1;
86 }
87 }
88
89 /* Found an entry in the table. Return -1 for a range entry. Otherwise return
90 the other case if there is one, else -1. */
91
92 if (ucp_table[mid].f0 & f0_rangeflag)
93 return -1;
94
95 int offset = ucp_table[mid].f1 & f1_casemask;
96 if (offset & f1_caseneg)
97 offset |= f1_caseneg;
98 return !offset ? -1 : c + offset;
99}
100

source code of qtscript/src/3rdparty/javascriptcore/JavaScriptCore/pcre/pcre_ucp_searchfuncs.cpp