Coverage Report

Created: 2025-10-13 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glib/glib/pcre/pcre_xclass.c
Line
Count
Source
1
/*************************************************
2
*      Perl-Compatible Regular Expressions       *
3
*************************************************/
4
5
/* PCRE is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language.
7
8
                       Written by Philip Hazel
9
           Copyright (c) 1997-2012 University of Cambridge
10
11
-----------------------------------------------------------------------------
12
Redistribution and use in source and binary forms, with or without
13
modification, 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
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
-----------------------------------------------------------------------------
38
*/
39
40
41
/* This module contains an internal function that is used to match an extended
42
class. It is used by both pcre_exec() and pcre_def_exec(). */
43
44
45
#include "config.h"
46
47
#include "pcre_internal.h"
48
49
50
/*************************************************
51
*       Match character against an XCLASS        *
52
*************************************************/
53
54
/* This function is called to match a character against an extended class that
55
might contain values > 255 and/or Unicode properties.
56
57
Arguments:
58
  c           the character
59
  data        points to the flag byte of the XCLASS data
60
61
Returns:      TRUE if character matches, else FALSE
62
*/
63
64
BOOL
65
PRIV(xclass)(int c, const pcre_uchar *data, BOOL utf)
66
0
{
67
0
int t;
68
0
BOOL negated = (*data & XCL_NOT) != 0;
69
70
0
(void)utf;
71
0
#ifdef COMPILE_PCRE8
72
/* In 8 bit mode, this must always be TRUE. Help the compiler to know that. */
73
0
utf = TRUE;
74
0
#endif
75
76
/* Character values < 256 are matched against a bitmap, if one is present. If
77
not, we still carry on, because there may be ranges that start below 256 in the
78
additional data. */
79
80
0
if (c < 256)
81
0
  {
82
0
  if ((*data & XCL_MAP) != 0 &&
83
0
    (((pcre_uint8 *)(data + 1))[c/8] & (1 << (c&7))) != 0)
84
0
    return !negated; /* char found */
85
0
  }
86
87
/* First skip the bit map if present. Then match against the list of Unicode
88
properties or large chars or ranges that end with a large char. We won't ever
89
encounter XCL_PROP or XCL_NOTPROP when UCP support is not compiled. */
90
91
0
if ((*data++ & XCL_MAP) != 0) data += 32 / sizeof(pcre_uchar);
92
93
0
while ((t = *data++) != XCL_END)
94
0
  {
95
0
  int x, y;
96
0
  if (t == XCL_SINGLE)
97
0
    {
98
0
#ifdef SUPPORT_UTF
99
0
    if (utf)
100
0
      {
101
0
      GETCHARINC(x, data); /* macro generates multiple statements */
102
0
      }
103
0
    else
104
0
#endif
105
0
      x = *data++;
106
0
    if (c == x) return !negated;
107
0
    }
108
0
  else if (t == XCL_RANGE)
109
0
    {
110
0
#ifdef SUPPORT_UTF
111
0
    if (utf)
112
0
      {
113
0
      GETCHARINC(x, data); /* macro generates multiple statements */
114
0
      GETCHARINC(y, data); /* macro generates multiple statements */
115
0
      }
116
0
    else
117
0
#endif
118
0
      {
119
0
      x = *data++;
120
0
      y = *data++;
121
0
      }
122
0
    if (c >= x && c <= y) return !negated;
123
0
    }
124
125
0
#ifdef SUPPORT_UCP
126
0
  else  /* XCL_PROP & XCL_NOTPROP */
127
0
    {
128
0
    const pcre_uint8 chartype = UCD_CHARTYPE(c);
129
130
0
    switch(*data)
131
0
      {
132
0
      case PT_ANY:
133
0
      if (t == XCL_PROP) return !negated;
134
0
      break;
135
136
0
      case PT_LAMP:
137
0
      if ((chartype == ucp_Lu || chartype == ucp_Ll ||
138
0
           chartype == ucp_Lt) == (t == XCL_PROP)) return !negated;
139
0
      break;
140
141
0
      case PT_GC:
142
0
      if ((data[1] == PRIV(ucp_gentype)[chartype]) == (t == XCL_PROP))
143
0
        return !negated;
144
0
      break;
145
146
0
      case PT_PC:
147
0
      if ((data[1] == chartype) == (t == XCL_PROP)) return !negated;
148
0
      break;
149
150
0
      case PT_SC:
151
0
      if ((data[1] == UCD_SCRIPT(c)) == (t == XCL_PROP)) return !negated;
152
0
      break;
153
154
0
      case PT_ALNUM:
155
0
      if ((PRIV(ucp_gentype)[chartype] == ucp_L ||
156
0
           PRIV(ucp_gentype)[chartype] == ucp_N) == (t == XCL_PROP))
157
0
        return !negated;
158
0
      break;
159
160
0
      case PT_SPACE:    /* Perl space */
161
0
      if ((PRIV(ucp_gentype)[chartype] == ucp_Z ||
162
0
           c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
163
0
             == (t == XCL_PROP))
164
0
        return !negated;
165
0
      break;
166
167
0
      case PT_PXSPACE:  /* POSIX space */
168
0
      if ((PRIV(ucp_gentype)[chartype] == ucp_Z ||
169
0
           c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
170
0
           c == CHAR_FF || c == CHAR_CR) == (t == XCL_PROP))
171
0
        return !negated;
172
0
      break;
173
174
0
      case PT_WORD:
175
0
      if ((PRIV(ucp_gentype)[chartype] == ucp_L ||
176
0
           PRIV(ucp_gentype)[chartype] == ucp_N || c == CHAR_UNDERSCORE)
177
0
             == (t == XCL_PROP))
178
0
        return !negated;
179
0
      break;
180
181
      /* This should never occur, but compilers may mutter if there is no
182
      default. */
183
184
0
      default:
185
0
      return FALSE;
186
0
      }
187
188
0
    data += 2;
189
0
    }
190
0
#endif  /* SUPPORT_UCP */
191
0
  }
192
193
0
return negated;   /* char did not match */
194
0
}
195
196
/* End of pcre_xclass.c */