1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/pcre/pcre_xclass.c Tue Jul 28 17:51:34 2009 -0400
1.3 @@ -0,0 +1,146 @@
1.4 +/*************************************************
1.5 +* Perl-Compatible Regular Expressions *
1.6 +*************************************************/
1.7 +
1.8 +/* PCRE is a library of functions to support regular expressions whose syntax
1.9 +and semantics are as close as possible to those of the Perl 5 language.
1.10 +
1.11 + Written by Philip Hazel
1.12 + Copyright (c) 1997-2009 University of Cambridge
1.13 +
1.14 +-----------------------------------------------------------------------------
1.15 +Redistribution and use in source and binary forms, with or without
1.16 +modification, are permitted provided that the following conditions are met:
1.17 +
1.18 + * Redistributions of source code must retain the above copyright notice,
1.19 + this list of conditions and the following disclaimer.
1.20 +
1.21 + * Redistributions in binary form must reproduce the above copyright
1.22 + notice, this list of conditions and the following disclaimer in the
1.23 + documentation and/or other materials provided with the distribution.
1.24 +
1.25 + * Neither the name of the University of Cambridge nor the names of its
1.26 + contributors may be used to endorse or promote products derived from
1.27 + this software without specific prior written permission.
1.28 +
1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1.30 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.31 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.32 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
1.33 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1.34 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1.35 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1.36 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1.37 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1.38 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1.39 +POSSIBILITY OF SUCH DAMAGE.
1.40 +-----------------------------------------------------------------------------
1.41 +*/
1.42 +
1.43 +
1.44 +/* This module contains an internal function that is used to match an extended
1.45 +class. It is used by both pcre_exec() and pcre_def_exec(). */
1.46 +
1.47 +
1.48 +#ifdef HAVE_CONFIG_H
1.49 +#include "config.h"
1.50 +#endif
1.51 +
1.52 +#include "pcre_internal.h"
1.53 +
1.54 +
1.55 +/*************************************************
1.56 +* Match character against an XCLASS *
1.57 +*************************************************/
1.58 +
1.59 +/* This function is called to match a character against an extended class that
1.60 +might contain values > 255 and/or Unicode properties.
1.61 +
1.62 +Arguments:
1.63 + c the character
1.64 + data points to the flag byte of the XCLASS data
1.65 +
1.66 +Returns: TRUE if character matches, else FALSE
1.67 +*/
1.68 +
1.69 +BOOL
1.70 +_pcre_xclass(int c, const uschar *data)
1.71 +{
1.72 +int t;
1.73 +BOOL negated = (*data & XCL_NOT) != 0;
1.74 +
1.75 +/* Character values < 256 are matched against a bitmap, if one is present. If
1.76 +not, we still carry on, because there may be ranges that start below 256 in the
1.77 +additional data. */
1.78 +
1.79 +if (c < 256)
1.80 + {
1.81 + if ((*data & XCL_MAP) != 0 && (data[1 + c/8] & (1 << (c&7))) != 0)
1.82 + return !negated; /* char found */
1.83 + }
1.84 +
1.85 +/* First skip the bit map if present. Then match against the list of Unicode
1.86 +properties or large chars or ranges that end with a large char. We won't ever
1.87 +encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */
1.88 +
1.89 +if ((*data++ & XCL_MAP) != 0) data += 32;
1.90 +
1.91 +while ((t = *data++) != XCL_END)
1.92 + {
1.93 + int x, y;
1.94 + if (t == XCL_SINGLE)
1.95 + {
1.96 + GETCHARINC(x, data);
1.97 + if (c == x) return !negated;
1.98 + }
1.99 + else if (t == XCL_RANGE)
1.100 + {
1.101 + GETCHARINC(x, data);
1.102 + GETCHARINC(y, data);
1.103 + if (c >= x && c <= y) return !negated;
1.104 + }
1.105 +
1.106 +#ifdef SUPPORT_UCP
1.107 + else /* XCL_PROP & XCL_NOTPROP */
1.108 + {
1.109 + const ucd_record *prop = GET_UCD(c);
1.110 +
1.111 + switch(*data)
1.112 + {
1.113 + case PT_ANY:
1.114 + if (t == XCL_PROP) return !negated;
1.115 + break;
1.116 +
1.117 + case PT_LAMP:
1.118 + if ((prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || prop->chartype == ucp_Lt) ==
1.119 + (t == XCL_PROP)) return !negated;
1.120 + break;
1.121 +
1.122 + case PT_GC:
1.123 + if ((data[1] == _pcre_ucp_gentype[prop->chartype]) == (t == XCL_PROP)) return !negated;
1.124 + break;
1.125 +
1.126 + case PT_PC:
1.127 + if ((data[1] == prop->chartype) == (t == XCL_PROP)) return !negated;
1.128 + break;
1.129 +
1.130 + case PT_SC:
1.131 + if ((data[1] == prop->script) == (t == XCL_PROP)) return !negated;
1.132 + break;
1.133 +
1.134 + /* This should never occur, but compilers may mutter if there is no
1.135 + default. */
1.136 +
1.137 + default:
1.138 + return FALSE;
1.139 + }
1.140 +
1.141 + data += 2;
1.142 + }
1.143 +#endif /* SUPPORT_UCP */
1.144 + }
1.145 +
1.146 +return negated; /* char did not match */
1.147 +}
1.148 +
1.149 +/* End of pcre_xclass.c */