monotone

monotone Mtn Source Tree

Root/pcre/pcre_xclass.c

1/*************************************************
2* Perl-Compatible Regular Expressions *
3*************************************************/
4
5/* PCRE is a library of functions to support regular expressions whose syntax
6and semantics are as close as possible to those of the Perl 5 language.
7
8 Written by Philip Hazel
9 Copyright (c) 1997-2008 University of Cambridge
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 an internal function that is used to match an extended
42class (one that contains characters whose values are > 255). It is used by both
43pcre_exec() and pcre_def_exec(). */
44
45
46#include "pcre_config.h"
47
48#include "pcre_internal.h"
49
50
51/*************************************************
52* Match character against an XCLASS *
53*************************************************/
54
55/* This function is called to match a character against an extended class that
56might contain values > 255.
57
58Arguments:
59 c the character
60 data points to the flag byte of the XCLASS data
61
62Returns: TRUE if character matches, else FALSE
63*/
64
65BOOL
66_pcre_xclass(int c, const uschar *data)
67{
68int t;
69BOOL negated = (*data & XCL_NOT) != 0;
70
71/* Character values < 256 are matched against a bitmap, if one is present. If
72not, we still carry on, because there may be ranges that start below 256 in the
73additional data. */
74
75if (c < 256)
76 {
77 if ((*data & XCL_MAP) != 0 && (data[1 + c/8] & (1 << (c&7))) != 0)
78 return !negated; /* char found */
79 }
80
81/* First skip the bit map if present. Then match against the list of Unicode
82properties or large chars or ranges that end with a large char. We won't ever
83encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */
84
85if ((*data++ & XCL_MAP) != 0) data += 32;
86
87while ((t = *data++) != XCL_END)
88 {
89 int x, y;
90 if (t == XCL_SINGLE)
91 {
92 GETCHARINC(x, data);
93 if (c == x) return !negated;
94 }
95 else if (t == XCL_RANGE)
96 {
97 GETCHARINC(x, data);
98 GETCHARINC(y, data);
99 if (c >= x && c <= y) return !negated;
100 }
101
102#ifdef SUPPORT_UCP
103 else /* XCL_PROP & XCL_NOTPROP */
104 {
105 int chartype, script;
106 int category = _pcre_ucp_findprop(c, &chartype, &script);
107
108 switch(*data)
109 {
110 case PT_ANY:
111 if (t == XCL_PROP) return !negated;
112 break;
113
114 case PT_LAMP:
115 if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) ==
116 (t == XCL_PROP)) return !negated;
117 break;
118
119 case PT_GC:
120 if ((data[1] == category) == (t == XCL_PROP)) return !negated;
121 break;
122
123 case PT_PC:
124 if ((data[1] == chartype) == (t == XCL_PROP)) return !negated;
125 break;
126
127 case PT_SC:
128 if ((data[1] == script) == (t == XCL_PROP)) return !negated;
129 break;
130
131 /* This should never occur, but compilers may mutter if there is no
132 default. */
133
134 default:
135 return FALSE;
136 }
137
138 data += 2;
139 }
140#endif /* SUPPORT_UCP */
141 }
142
143return negated; /* char did not match */
144}
145
146/* End of pcre_xclass.c */

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status