]>
git.saurik.com Git - apple/javascriptcore.git/blob - pcre/pcre_ucp_searchfuncs.cpp
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.
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.
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
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.
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.
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 -----------------------------------------------------------------------------
41 /* This module contains code for searching the table of Unicode character
45 #include "pcre_internal.h"
47 #include "ucpinternal.h" /* Internal table details */
48 #include "ucptable.cpp" /* The table itself */
50 /*************************************************
51 * Search table and return other case *
52 *************************************************/
54 /* If the given character is a letter, and there is another case for the
55 letter, return the other case. Otherwise, return -1.
60 Returns: the other case or -1 if none
63 int jsc_pcre_ucp_othercase(unsigned c
)
66 int top
= sizeof(ucp_table
) / sizeof(cnode
);
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. */
77 mid
= (bot
+ top
) >> 1;
78 if (c
== (ucp_table
[mid
].f0
& f0_charmask
))
80 if (c
< (ucp_table
[mid
].f0
& f0_charmask
))
83 if ((ucp_table
[mid
].f0
& f0_rangeflag
) && (c
<= (ucp_table
[mid
].f0
& f0_charmask
) + (ucp_table
[mid
].f1
& f1_rangemask
)))
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. */
92 if (ucp_table
[mid
].f0
& f0_rangeflag
)
95 int offset
= ucp_table
[mid
].f1
& f1_casemask
;
96 if (offset
& f1_caseneg
)
98 return !offset
? -1 : c
+ offset
;