rugged 1.9.4 → 1.9.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +1 -1
  4. data/vendor/libgit2/COPYING +83 -11
  5. data/vendor/libgit2/cmake/SelectRegex.cmake +8 -3
  6. data/vendor/libgit2/deps/pcre2/CMakeLists.txt +110 -0
  7. data/vendor/libgit2/deps/pcre2/LICENCE.md +104 -0
  8. data/vendor/libgit2/deps/pcre2/config.h.in +54 -0
  9. data/vendor/libgit2/deps/pcre2/pcre2.h +1079 -0
  10. data/vendor/libgit2/deps/pcre2/pcre2_auto_possess.c +1416 -0
  11. data/vendor/libgit2/deps/{pcre/pcre_chartables.c → pcre2/pcre2_chartables.c} +41 -47
  12. data/vendor/libgit2/deps/{pcre/pcre_ord2utf8.c → pcre2/pcre2_chkdint.c} +36 -36
  13. data/vendor/libgit2/deps/pcre2/pcre2_compile.c +11345 -0
  14. data/vendor/libgit2/deps/pcre2/pcre2_compile.h +356 -0
  15. data/vendor/libgit2/deps/pcre2/pcre2_compile_cgroup.c +632 -0
  16. data/vendor/libgit2/deps/pcre2/pcre2_compile_class.c +2777 -0
  17. data/vendor/libgit2/deps/pcre2/pcre2_config.c +250 -0
  18. data/vendor/libgit2/deps/pcre2/pcre2_context.c +557 -0
  19. data/vendor/libgit2/deps/pcre2/pcre2_convert.c +1263 -0
  20. data/vendor/libgit2/deps/{pcre/pcre_dfa_exec.c → pcre2/pcre2_dfa_match.c} +1402 -943
  21. data/vendor/libgit2/deps/pcre2/pcre2_error.c +384 -0
  22. data/vendor/libgit2/deps/pcre2/pcre2_extuni.c +159 -0
  23. data/vendor/libgit2/deps/pcre2/pcre2_find_bracket.c +217 -0
  24. data/vendor/libgit2/deps/pcre2/pcre2_fuzzsupport.c +844 -0
  25. data/vendor/libgit2/deps/pcre2/pcre2_internal.h +2353 -0
  26. data/vendor/libgit2/deps/pcre2/pcre2_intmodedep.h +1044 -0
  27. data/vendor/libgit2/deps/pcre2/pcre2_maketables.c +177 -0
  28. data/vendor/libgit2/deps/pcre2/pcre2_match.c +8244 -0
  29. data/vendor/libgit2/deps/pcre2/pcre2_match_data.c +184 -0
  30. data/vendor/libgit2/deps/pcre2/pcre2_match_next.c +171 -0
  31. data/vendor/libgit2/deps/{pcre/pcre_newline.c → pcre2/pcre2_newline.c} +92 -63
  32. data/vendor/libgit2/deps/{pcre/pcre_refcount.c → pcre2/pcre2_ord2utf.c} +64 -38
  33. data/vendor/libgit2/deps/pcre2/pcre2_pattern_info.c +430 -0
  34. data/vendor/libgit2/deps/pcre2/pcre2_printint_inc.h +1098 -0
  35. data/vendor/libgit2/deps/pcre2/pcre2_script_run.c +344 -0
  36. data/vendor/libgit2/deps/pcre2/pcre2_serialize.c +284 -0
  37. data/vendor/libgit2/deps/pcre2/pcre2_string_utils.c +199 -0
  38. data/vendor/libgit2/deps/pcre2/pcre2_study.c +2087 -0
  39. data/vendor/libgit2/deps/pcre2/pcre2_substitute.c +1761 -0
  40. data/vendor/libgit2/deps/pcre2/pcre2_substring.c +553 -0
  41. data/vendor/libgit2/deps/pcre2/pcre2_tables.c +310 -0
  42. data/vendor/libgit2/deps/pcre2/pcre2_ucd.c +5805 -0
  43. data/vendor/libgit2/deps/pcre2/pcre2_ucp.h +408 -0
  44. data/vendor/libgit2/deps/pcre2/pcre2_ucptables_inc.h +1596 -0
  45. data/vendor/libgit2/deps/pcre2/pcre2_util.h +179 -0
  46. data/vendor/libgit2/deps/pcre2/pcre2_valid_utf.c +397 -0
  47. data/vendor/libgit2/deps/pcre2/pcre2_xclass.c +547 -0
  48. data/vendor/libgit2/include/git2/common.h +13 -1
  49. data/vendor/libgit2/include/git2/version.h +2 -2
  50. data/vendor/libgit2/src/libgit2/blame.c +6 -0
  51. data/vendor/libgit2/src/libgit2/delta.c +8 -0
  52. data/vendor/libgit2/src/libgit2/indexer.c +3 -2
  53. data/vendor/libgit2/src/libgit2/settings.c +9 -0
  54. data/vendor/libgit2/src/libgit2/streams/openssl.c +4 -1
  55. data/vendor/libgit2/src/libgit2/submodule.c +77 -12
  56. data/vendor/libgit2/src/libgit2/transports/http.c +4 -4
  57. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +2 -1
  58. data/vendor/libgit2/src/util/fs_path.h +10 -10
  59. data/vendor/libgit2/src/util/regexp.c +27 -12
  60. data/vendor/libgit2/src/util/regexp.h +7 -2
  61. metadata +44 -37
  62. data/vendor/libgit2/deps/pcre/CMakeLists.txt +0 -140
  63. data/vendor/libgit2/deps/pcre/COPYING +0 -5
  64. data/vendor/libgit2/deps/pcre/LICENCE +0 -93
  65. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +0 -22
  66. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +0 -17
  67. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +0 -58
  68. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +0 -29
  69. data/vendor/libgit2/deps/pcre/config.h.in +0 -57
  70. data/vendor/libgit2/deps/pcre/pcre.h +0 -641
  71. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +0 -319
  72. data/vendor/libgit2/deps/pcre/pcre_compile.c +0 -9815
  73. data/vendor/libgit2/deps/pcre/pcre_config.c +0 -190
  74. data/vendor/libgit2/deps/pcre/pcre_exec.c +0 -7173
  75. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +0 -245
  76. data/vendor/libgit2/deps/pcre/pcre_get.c +0 -669
  77. data/vendor/libgit2/deps/pcre/pcre_globals.c +0 -86
  78. data/vendor/libgit2/deps/pcre/pcre_internal.h +0 -2787
  79. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +0 -11913
  80. data/vendor/libgit2/deps/pcre/pcre_maketables.c +0 -156
  81. data/vendor/libgit2/deps/pcre/pcre_printint.c +0 -834
  82. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +0 -211
  83. data/vendor/libgit2/deps/pcre/pcre_study.c +0 -1686
  84. data/vendor/libgit2/deps/pcre/pcre_tables.c +0 -727
  85. data/vendor/libgit2/deps/pcre/pcre_ucd.c +0 -3644
  86. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +0 -301
  87. data/vendor/libgit2/deps/pcre/pcre_version.c +0 -98
  88. data/vendor/libgit2/deps/pcre/pcre_xclass.c +0 -268
  89. data/vendor/libgit2/deps/pcre/pcreposix.c +0 -420
  90. data/vendor/libgit2/deps/pcre/pcreposix.h +0 -117
  91. data/vendor/libgit2/deps/pcre/ucp.h +0 -224
@@ -0,0 +1,2777 @@
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
+ Original API code Copyright (c) 1997-2012 University of Cambridge
10
+ New API code Copyright (c) 2016-2024 University of Cambridge
11
+
12
+ -----------------------------------------------------------------------------
13
+ Redistribution and use in source and binary forms, with or without
14
+ modification, are permitted provided that the following conditions are met:
15
+
16
+ * Redistributions of source code must retain the above copyright notice,
17
+ this list of conditions and the following disclaimer.
18
+
19
+ * Redistributions in binary form must reproduce the above copyright
20
+ notice, this list of conditions and the following disclaimer in the
21
+ documentation and/or other materials provided with the distribution.
22
+
23
+ * Neither the name of the University of Cambridge nor the names of its
24
+ contributors may be used to endorse or promote products derived from
25
+ this software without specific prior written permission.
26
+
27
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
+ POSSIBILITY OF SUCH DAMAGE.
38
+ -----------------------------------------------------------------------------
39
+ */
40
+
41
+
42
+ #include "pcre2_compile.h"
43
+
44
+
45
+
46
+ typedef struct {
47
+ /* Option bits for eclass. */
48
+ uint32_t options;
49
+ uint32_t xoptions;
50
+ /* Rarely used members. */
51
+ int *errorcodeptr;
52
+ compile_block *cb;
53
+ /* Bitmap is needed. */
54
+ BOOL needs_bitmap;
55
+ } eclass_context;
56
+
57
+ /* Checks the allowed tokens at the end of a class structure in debug mode.
58
+ When a new token is not processed by all loops, and the token is equals to
59
+ a) one of the cases here:
60
+ the compiler will complain about a duplicated case value.
61
+ b) none of the cases here:
62
+ the loop without the handler will stop with an assertion failure. */
63
+
64
+ #ifdef PCRE2_DEBUG
65
+ #define CLASS_END_CASES(meta) \
66
+ default: \
67
+ PCRE2_ASSERT((meta) <= META_END); \
68
+ PCRE2_FALLTHROUGH /* Fall through */ \
69
+ case META_CLASS: \
70
+ case META_CLASS_NOT: \
71
+ case META_CLASS_EMPTY: \
72
+ case META_CLASS_EMPTY_NOT: \
73
+ case META_CLASS_END: \
74
+ case META_ECLASS_AND: \
75
+ case META_ECLASS_OR: \
76
+ case META_ECLASS_SUB: \
77
+ case META_ECLASS_XOR: \
78
+ case META_ECLASS_NOT:
79
+ #else
80
+ #define CLASS_END_CASES(meta) \
81
+ default:
82
+ #endif
83
+
84
+ #ifdef SUPPORT_WIDE_CHARS
85
+
86
+ /* Heapsort algorithm. */
87
+
88
+ static void do_heapify(uint32_t *buffer, size_t size, size_t i)
89
+ {
90
+ size_t max;
91
+ size_t left;
92
+ size_t right;
93
+ uint32_t tmp1, tmp2;
94
+
95
+ while (TRUE)
96
+ {
97
+ max = i;
98
+ left = (i << 1) + 2;
99
+ right = left + 2;
100
+
101
+ if (left < size && buffer[left] > buffer[max]) max = left;
102
+ if (right < size && buffer[right] > buffer[max]) max = right;
103
+ if (i == max) return;
104
+
105
+ /* Swap items. */
106
+ tmp1 = buffer[i];
107
+ tmp2 = buffer[i + 1];
108
+ buffer[i] = buffer[max];
109
+ buffer[i + 1] = buffer[max + 1];
110
+ buffer[max] = tmp1;
111
+ buffer[max + 1] = tmp2;
112
+ i = max;
113
+ }
114
+ }
115
+
116
+ #ifdef SUPPORT_UNICODE
117
+
118
+ #define PARSE_CLASS_UTF 0x1
119
+ #define PARSE_CLASS_CASELESS_UTF 0x2
120
+ #define PARSE_CLASS_RESTRICTED_UTF 0x4
121
+ #define PARSE_CLASS_TURKISH_UTF 0x8
122
+
123
+ /* Get the range of nocase characters which includes the
124
+ 'c' character passed as argument, or directly follows 'c'. */
125
+
126
+ static const uint32_t*
127
+ get_nocase_range(uint32_t c)
128
+ {
129
+ uint32_t left = 0;
130
+ uint32_t right = PRIV(ucd_nocase_ranges_size);
131
+ uint32_t middle;
132
+
133
+ if (c > MAX_UTF_CODE_POINT) return PRIV(ucd_nocase_ranges) + right;
134
+
135
+ while (TRUE)
136
+ {
137
+ /* Range end of the middle element. */
138
+ middle = ((left + right) >> 1) | 0x1;
139
+
140
+ if (PRIV(ucd_nocase_ranges)[middle] <= c)
141
+ left = middle + 1;
142
+ else if (middle > 1 && PRIV(ucd_nocase_ranges)[middle - 2] > c)
143
+ right = middle - 1;
144
+ else
145
+ return PRIV(ucd_nocase_ranges) + (middle - 1);
146
+ }
147
+ }
148
+
149
+ /* Get the list of othercase characters, which belongs to the passed range.
150
+ Create ranges from these characters, and append them to the buffer argument. */
151
+
152
+ static size_t
153
+ utf_caseless_extend(uint32_t start, uint32_t end, uint32_t options,
154
+ uint32_t *buffer)
155
+ {
156
+ uint32_t new_start = start;
157
+ uint32_t new_end = end;
158
+ uint32_t c = start;
159
+ const uint32_t *list;
160
+ uint32_t tmp[3];
161
+ size_t result = 2;
162
+ const uint32_t *skip_range = get_nocase_range(c);
163
+ uint32_t skip_start = skip_range[0];
164
+
165
+ #if PCRE2_CODE_UNIT_WIDTH == 8
166
+ PCRE2_ASSERT(options & PARSE_CLASS_UTF);
167
+ #endif
168
+
169
+ #if PCRE2_CODE_UNIT_WIDTH == 32
170
+ if (end > MAX_UTF_CODE_POINT) end = MAX_UTF_CODE_POINT;
171
+ #endif
172
+
173
+ while (c <= end)
174
+ {
175
+ uint32_t co;
176
+
177
+ if (c > skip_start)
178
+ {
179
+ c = skip_range[1];
180
+ skip_range += 2;
181
+ skip_start = skip_range[0];
182
+ continue;
183
+ }
184
+
185
+ /* Compute caseless set. */
186
+
187
+ if ((options & (PARSE_CLASS_TURKISH_UTF|PARSE_CLASS_RESTRICTED_UTF)) ==
188
+ PARSE_CLASS_TURKISH_UTF &&
189
+ UCD_ANY_I(c))
190
+ {
191
+ co = PRIV(ucd_turkish_dotted_i_caseset) + (UCD_DOTTED_I(c)? 0 : 3);
192
+ }
193
+ else if ((co = UCD_CASESET(c)) != 0 &&
194
+ (options & PARSE_CLASS_RESTRICTED_UTF) != 0 &&
195
+ PRIV(ucd_caseless_sets)[co] < 128)
196
+ {
197
+ co = 0; /* Ignore the caseless set if it's restricted. */
198
+ }
199
+
200
+ if (co != 0)
201
+ list = PRIV(ucd_caseless_sets) + co;
202
+ else
203
+ {
204
+ co = UCD_OTHERCASE(c);
205
+ list = tmp;
206
+ tmp[0] = c;
207
+ tmp[1] = NOTACHAR;
208
+
209
+ if (co != c)
210
+ {
211
+ tmp[1] = co;
212
+ tmp[2] = NOTACHAR;
213
+ }
214
+ }
215
+ c++;
216
+
217
+ /* Add characters. */
218
+ do
219
+ {
220
+ #if PCRE2_CODE_UNIT_WIDTH == 16
221
+ if (!(options & PARSE_CLASS_UTF) && *list > 0xffff) continue;
222
+ #endif
223
+
224
+ if (*list < new_start)
225
+ {
226
+ if (*list + 1 == new_start)
227
+ {
228
+ new_start--;
229
+ continue;
230
+ }
231
+ }
232
+ else if (*list > new_end)
233
+ {
234
+ if (*list - 1 == new_end)
235
+ {
236
+ new_end++;
237
+ continue;
238
+ }
239
+ }
240
+ else continue;
241
+
242
+ result += 2;
243
+ if (buffer != NULL)
244
+ {
245
+ buffer[0] = *list;
246
+ buffer[1] = *list;
247
+ buffer += 2;
248
+ }
249
+ }
250
+ while (*(++list) != NOTACHAR);
251
+ }
252
+
253
+ if (buffer != NULL)
254
+ {
255
+ buffer[0] = new_start;
256
+ buffer[1] = new_end;
257
+ buffer += 2;
258
+ (void)buffer;
259
+ }
260
+ return result;
261
+ }
262
+
263
+ #endif
264
+
265
+ /* Add a character list to a buffer. */
266
+
267
+ static size_t
268
+ append_char_list(const uint32_t *p, uint32_t *buffer)
269
+ {
270
+ const uint32_t *n;
271
+ size_t result = 0;
272
+
273
+ while (*p != NOTACHAR)
274
+ {
275
+ n = p;
276
+ while (n[0] == n[1] - 1) n++;
277
+
278
+ PCRE2_ASSERT(*p < 0xffff);
279
+
280
+ if (buffer != NULL)
281
+ {
282
+ buffer[0] = *p;
283
+ buffer[1] = *n;
284
+ buffer += 2;
285
+ }
286
+
287
+ result += 2;
288
+ p = n + 1;
289
+ }
290
+
291
+ return result;
292
+ }
293
+
294
+ static uint32_t
295
+ get_highest_char(uint32_t options)
296
+ {
297
+ (void)options; /* Avoid compiler warning. */
298
+
299
+ #if PCRE2_CODE_UNIT_WIDTH == 8
300
+ return MAX_UTF_CODE_POINT;
301
+ #else
302
+ #ifdef SUPPORT_UNICODE
303
+ return GET_MAX_CHAR_VALUE((options & PARSE_CLASS_UTF) != 0);
304
+ #else
305
+ return MAX_UCHAR_VALUE;
306
+ #endif
307
+ #endif
308
+ }
309
+
310
+ /* Add a negated character list to a buffer. */
311
+ static size_t
312
+ append_negated_char_list(const uint32_t *p, uint32_t options, uint32_t *buffer)
313
+ {
314
+ const uint32_t *n;
315
+ uint32_t start = 0;
316
+ size_t result = 2;
317
+
318
+ PCRE2_ASSERT(*p > 0);
319
+
320
+ while (*p != NOTACHAR)
321
+ {
322
+ n = p;
323
+ while (n[0] == n[1] - 1) n++;
324
+
325
+ PCRE2_ASSERT(*p < 0xffff);
326
+
327
+ if (buffer != NULL)
328
+ {
329
+ buffer[0] = start;
330
+ buffer[1] = *p - 1;
331
+ buffer += 2;
332
+ }
333
+
334
+ result += 2;
335
+ start = *n + 1;
336
+ p = n + 1;
337
+ }
338
+
339
+ if (buffer != NULL)
340
+ {
341
+ buffer[0] = start;
342
+ buffer[1] = get_highest_char(options);
343
+ buffer += 2;
344
+ (void)buffer;
345
+ }
346
+
347
+ return result;
348
+ }
349
+
350
+ static uint32_t *
351
+ append_non_ascii_range(uint32_t options, uint32_t *buffer)
352
+ {
353
+ if (buffer == NULL) return NULL;
354
+
355
+ buffer[0] = 0x100;
356
+ buffer[1] = get_highest_char(options);
357
+ return buffer + 2;
358
+ }
359
+
360
+ static size_t
361
+ parse_class(uint32_t *ptr, uint32_t options, uint32_t *buffer)
362
+ {
363
+ size_t total_size = 0;
364
+ size_t size;
365
+ uint32_t meta_arg;
366
+ uint32_t start_char;
367
+
368
+ while (TRUE)
369
+ {
370
+ switch (META_CODE(*ptr))
371
+ {
372
+ case META_ESCAPE:
373
+ meta_arg = META_DATA(*ptr);
374
+ switch (meta_arg)
375
+ {
376
+ case ESC_D:
377
+ case ESC_W:
378
+ case ESC_S:
379
+ buffer = append_non_ascii_range(options, buffer);
380
+ total_size += 2;
381
+ break;
382
+
383
+ case ESC_h:
384
+ size = append_char_list(PRIV(hspace_list), buffer);
385
+ total_size += size;
386
+ if (buffer != NULL) buffer += size;
387
+ break;
388
+
389
+ case ESC_H:
390
+ size = append_negated_char_list(PRIV(hspace_list), options, buffer);
391
+ total_size += size;
392
+ if (buffer != NULL) buffer += size;
393
+ break;
394
+
395
+ case ESC_v:
396
+ size = append_char_list(PRIV(vspace_list), buffer);
397
+ total_size += size;
398
+ if (buffer != NULL) buffer += size;
399
+ break;
400
+
401
+ case ESC_V:
402
+ size = append_negated_char_list(PRIV(vspace_list), options, buffer);
403
+ total_size += size;
404
+ if (buffer != NULL) buffer += size;
405
+ break;
406
+
407
+ case ESC_p:
408
+ case ESC_P:
409
+ ptr++;
410
+ if (meta_arg == ESC_p && (*ptr >> 16) == PT_ANY)
411
+ {
412
+ if (buffer != NULL)
413
+ {
414
+ buffer[0] = 0;
415
+ buffer[1] = get_highest_char(options);
416
+ buffer += 2;
417
+ }
418
+ total_size += 2;
419
+ }
420
+ break;
421
+ }
422
+ ptr++;
423
+ continue;
424
+ case META_POSIX_NEG:
425
+ buffer = append_non_ascii_range(options, buffer);
426
+ total_size += 2;
427
+ ptr += 2;
428
+ continue;
429
+ case META_POSIX:
430
+ ptr += 2;
431
+ continue;
432
+ case META_BIGVALUE:
433
+ /* Character literal */
434
+ ptr++;
435
+ break;
436
+ CLASS_END_CASES(*ptr)
437
+ if (*ptr >= META_END) return total_size;
438
+ break;
439
+ }
440
+
441
+ start_char = *ptr;
442
+
443
+ if (ptr[1] == META_RANGE_LITERAL || ptr[1] == META_RANGE_ESCAPED)
444
+ {
445
+ ptr += 2;
446
+ PCRE2_ASSERT(*ptr < META_END || *ptr == META_BIGVALUE);
447
+
448
+ if (*ptr == META_BIGVALUE) ptr++;
449
+
450
+ #ifdef EBCDIC
451
+ #error "Missing EBCDIC support"
452
+ #endif
453
+ }
454
+
455
+ #ifdef SUPPORT_UNICODE
456
+ if (options & PARSE_CLASS_CASELESS_UTF)
457
+ {
458
+ size = utf_caseless_extend(start_char, *ptr++, options, buffer);
459
+ if (buffer != NULL) buffer += size;
460
+ total_size += size;
461
+ continue;
462
+ }
463
+ #endif
464
+
465
+ if (buffer != NULL)
466
+ {
467
+ buffer[0] = start_char;
468
+ buffer[1] = *ptr;
469
+ buffer += 2;
470
+ }
471
+
472
+ ptr++;
473
+ total_size += 2;
474
+ }
475
+
476
+ return total_size;
477
+ }
478
+
479
+ /* Extra uint32_t values for storing the lengths of range lists in
480
+ the worst case. Two uint32_t lengths and a range end for a range
481
+ starting before 255 */
482
+ #define CHAR_LIST_EXTRA_SIZE 3
483
+
484
+ /* Starting character values for each character list. */
485
+
486
+ static const uint32_t char_list_starts[] = {
487
+ #if PCRE2_CODE_UNIT_WIDTH == 32
488
+ XCL_CHAR_LIST_HIGH_32_START,
489
+ #endif
490
+ #if PCRE2_CODE_UNIT_WIDTH == 32 || defined SUPPORT_UNICODE
491
+ XCL_CHAR_LIST_LOW_32_START,
492
+ #endif
493
+ XCL_CHAR_LIST_HIGH_16_START,
494
+ /* Must be terminated by XCL_CHAR_LIST_LOW_16_START,
495
+ which also represents the end of the bitset. */
496
+ XCL_CHAR_LIST_LOW_16_START,
497
+ };
498
+
499
+ static class_ranges *
500
+ compile_optimize_class(uint32_t *start_ptr, uint32_t options,
501
+ uint32_t xoptions, compile_block *cb)
502
+ {
503
+ class_ranges* cranges;
504
+ uint32_t *ptr;
505
+ uint32_t *buffer;
506
+ uint32_t *dst;
507
+ uint32_t class_options = 0;
508
+ size_t range_list_size = 0, total_size, i;
509
+ uint32_t tmp1, tmp2;
510
+ const uint32_t *char_list_next;
511
+ uint16_t *next_char;
512
+ uint32_t char_list_start, char_list_end;
513
+ uint32_t range_start, range_end;
514
+
515
+ #ifdef SUPPORT_UNICODE
516
+ if (options & PCRE2_UTF)
517
+ class_options |= PARSE_CLASS_UTF;
518
+
519
+ if ((options & PCRE2_CASELESS) && (options & (PCRE2_UTF|PCRE2_UCP)))
520
+ class_options |= PARSE_CLASS_CASELESS_UTF;
521
+
522
+ if (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT)
523
+ class_options |= PARSE_CLASS_RESTRICTED_UTF;
524
+
525
+ if (xoptions & PCRE2_EXTRA_TURKISH_CASING)
526
+ class_options |= PARSE_CLASS_TURKISH_UTF;
527
+ #else
528
+ (void)options; /* Avoid compiler warning. */
529
+ (void)xoptions; /* Avoid compiler warning. */
530
+ #endif
531
+
532
+ /* Compute required space for the range. */
533
+
534
+ range_list_size = parse_class(start_ptr, class_options, NULL);
535
+ PCRE2_ASSERT((range_list_size & 0x1) == 0);
536
+
537
+ /* Allocate buffer. The total_size also represents the end of the buffer. */
538
+
539
+ total_size = range_list_size +
540
+ ((range_list_size >= 2) ? CHAR_LIST_EXTRA_SIZE : 0);
541
+
542
+ cranges = cb->cx->memctl.malloc(
543
+ sizeof(class_ranges) + total_size * sizeof(uint32_t),
544
+ cb->cx->memctl.memory_data);
545
+
546
+ if (cranges == NULL) return NULL;
547
+
548
+ cranges->header.next = NULL;
549
+ #ifdef PCRE2_DEBUG
550
+ cranges->header.type = CDATA_CRANGE;
551
+ #endif
552
+ cranges->range_list_size = (uint16_t)range_list_size;
553
+ cranges->char_lists_types = 0;
554
+ cranges->char_lists_size = 0;
555
+ cranges->char_lists_start = 0;
556
+
557
+ if (range_list_size == 0) return cranges;
558
+
559
+ buffer = (uint32_t*)(cranges + 1);
560
+ parse_class(start_ptr, class_options, buffer);
561
+
562
+ /* Using <= instead of == to help static analysis. */
563
+ if (range_list_size <= 2) return cranges;
564
+
565
+ /* In-place sorting of ranges. */
566
+
567
+ i = (((range_list_size >> 2) - 1) << 1);
568
+ while (TRUE)
569
+ {
570
+ do_heapify(buffer, range_list_size, i);
571
+ if (i == 0) break;
572
+ i -= 2;
573
+ }
574
+
575
+ i = range_list_size - 2;
576
+ while (TRUE)
577
+ {
578
+ tmp1 = buffer[i];
579
+ tmp2 = buffer[i + 1];
580
+ buffer[i] = buffer[0];
581
+ buffer[i + 1] = buffer[1];
582
+ buffer[0] = tmp1;
583
+ buffer[1] = tmp2;
584
+
585
+ do_heapify(buffer, i, 0);
586
+ if (i == 0) break;
587
+ i -= 2;
588
+ }
589
+
590
+ /* Merge ranges whenever possible. */
591
+ dst = buffer;
592
+ ptr = buffer + 2;
593
+ range_list_size -= 2;
594
+
595
+ /* The second condition is a very rare corner case, where the end of the last
596
+ range is the maximum character. This range cannot be extended further. */
597
+
598
+ while (range_list_size > 0 && dst[1] != ~(uint32_t)0)
599
+ {
600
+ if (dst[1] + 1 < ptr[0])
601
+ {
602
+ dst += 2;
603
+ dst[0] = ptr[0];
604
+ dst[1] = ptr[1];
605
+ }
606
+ else if (dst[1] < ptr[1]) dst[1] = ptr[1];
607
+
608
+ ptr += 2;
609
+ range_list_size -= 2;
610
+ }
611
+
612
+ PCRE2_ASSERT(dst[1] <= get_highest_char(class_options));
613
+
614
+ /* When the number of ranges are less than six,
615
+ they are not converted to range lists. */
616
+
617
+ ptr = buffer;
618
+ while (ptr < dst && ptr[1] < 0x100) ptr += 2;
619
+ if (dst - ptr < (2 * (6 - 1)))
620
+ {
621
+ cranges->range_list_size = (uint16_t)(dst + 2 - buffer);
622
+ return cranges;
623
+ }
624
+
625
+ /* Compute character lists structures. */
626
+
627
+ char_list_next = char_list_starts;
628
+ char_list_start = *char_list_next++;
629
+ #if PCRE2_CODE_UNIT_WIDTH == 32
630
+ char_list_end = XCL_CHAR_LIST_HIGH_32_END;
631
+ #elif defined SUPPORT_UNICODE
632
+ char_list_end = XCL_CHAR_LIST_LOW_32_END;
633
+ #else
634
+ char_list_end = XCL_CHAR_LIST_HIGH_16_END;
635
+ #endif
636
+ next_char = (uint16_t*)(buffer + total_size);
637
+
638
+ tmp1 = 0;
639
+ tmp2 = ((sizeof(char_list_starts) / sizeof(uint32_t)) - 1) * XCL_TYPE_BIT_LEN;
640
+ PCRE2_ASSERT(tmp2 <= 3 * XCL_TYPE_BIT_LEN && tmp2 >= XCL_TYPE_BIT_LEN);
641
+ range_start = dst[0];
642
+ range_end = dst[1];
643
+
644
+ while (TRUE)
645
+ {
646
+ if (range_start >= char_list_start)
647
+ {
648
+ if (range_start == range_end || range_end < char_list_end)
649
+ {
650
+ tmp1++;
651
+ next_char--;
652
+
653
+ if (char_list_start < XCL_CHAR_LIST_LOW_32_START)
654
+ *next_char = (uint16_t)((range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END);
655
+ else
656
+ *(uint32_t*)(--next_char) =
657
+ (range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END;
658
+ }
659
+
660
+ if (range_start < range_end)
661
+ {
662
+ if (range_start > char_list_start)
663
+ {
664
+ tmp1++;
665
+ next_char--;
666
+
667
+ if (char_list_start < XCL_CHAR_LIST_LOW_32_START)
668
+ *next_char = (uint16_t)(range_start << XCL_CHAR_SHIFT);
669
+ else
670
+ *(uint32_t*)(--next_char) = (range_start << XCL_CHAR_SHIFT);
671
+ }
672
+ else
673
+ cranges->char_lists_types |= XCL_BEGIN_WITH_RANGE << tmp2;
674
+ }
675
+
676
+ PCRE2_ASSERT((uint32_t*)next_char >= dst + 2);
677
+
678
+ if (dst > buffer)
679
+ {
680
+ dst -= 2;
681
+ range_start = dst[0];
682
+ range_end = dst[1];
683
+ continue;
684
+ }
685
+
686
+ range_start = 0;
687
+ range_end = 0;
688
+ }
689
+
690
+ if (range_end >= char_list_start)
691
+ {
692
+ PCRE2_ASSERT(range_start < char_list_start);
693
+
694
+ if (range_end < char_list_end)
695
+ {
696
+ tmp1++;
697
+ next_char--;
698
+
699
+ if (char_list_start < XCL_CHAR_LIST_LOW_32_START)
700
+ *next_char = (uint16_t)((range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END);
701
+ else
702
+ *(uint32_t*)(--next_char) =
703
+ (range_end << XCL_CHAR_SHIFT) | XCL_CHAR_END;
704
+
705
+ PCRE2_ASSERT((uint32_t*)next_char >= dst + 2);
706
+ }
707
+
708
+ cranges->char_lists_types |= XCL_BEGIN_WITH_RANGE << tmp2;
709
+ }
710
+
711
+ if (tmp1 >= XCL_ITEM_COUNT_MASK)
712
+ {
713
+ cranges->char_lists_types |= XCL_ITEM_COUNT_MASK << tmp2;
714
+ next_char--;
715
+
716
+ if (char_list_start < XCL_CHAR_LIST_LOW_32_START)
717
+ *next_char = (uint16_t)tmp1;
718
+ else
719
+ *(uint32_t*)(--next_char) = tmp1;
720
+ }
721
+ else
722
+ cranges->char_lists_types |= tmp1 << tmp2;
723
+
724
+ if (range_start < XCL_CHAR_LIST_LOW_16_START) break;
725
+
726
+ PCRE2_ASSERT(tmp2 >= XCL_TYPE_BIT_LEN);
727
+ char_list_end = char_list_start - 1;
728
+ char_list_start = *char_list_next++;
729
+ tmp1 = 0;
730
+ tmp2 -= XCL_TYPE_BIT_LEN;
731
+ }
732
+
733
+ if (dst[0] < XCL_CHAR_LIST_LOW_16_START) dst += 2;
734
+ PCRE2_ASSERT((uint16_t*)dst <= next_char);
735
+
736
+ cranges->char_lists_size =
737
+ (size_t)((uint8_t*)(buffer + total_size) - (uint8_t*)next_char);
738
+ cranges->char_lists_start = (size_t)((uint8_t*)next_char - (uint8_t*)buffer);
739
+ cranges->range_list_size = (uint16_t)(dst - buffer);
740
+ return cranges;
741
+ }
742
+
743
+ #endif /* SUPPORT_WIDE_CHARS */
744
+
745
+ #ifdef SUPPORT_UNICODE
746
+
747
+ void PRIV(update_classbits)(uint32_t ptype, uint32_t pdata, BOOL negated,
748
+ uint8_t *classbits)
749
+ {
750
+ /* Update PRIV(xclass) when this function is changed. */
751
+ int c, chartype;
752
+ const ucd_record *prop;
753
+ uint32_t gentype;
754
+ BOOL set_bit;
755
+
756
+ if (ptype == PT_ANY)
757
+ {
758
+ if (!negated) memset(classbits, 0xff, 32);
759
+ return;
760
+ }
761
+
762
+ for (c = 0; c < 256; c++)
763
+ {
764
+ prop = GET_UCD(c);
765
+ set_bit = FALSE;
766
+ (void)set_bit;
767
+
768
+ switch (ptype)
769
+ {
770
+ case PT_LAMP:
771
+ chartype = prop->chartype;
772
+ set_bit = (chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt);
773
+ break;
774
+
775
+ case PT_GC:
776
+ set_bit = (PRIV(ucp_gentype)[prop->chartype] == pdata);
777
+ break;
778
+
779
+ case PT_PC:
780
+ set_bit = (prop->chartype == pdata);
781
+ break;
782
+
783
+ case PT_SC:
784
+ set_bit = (prop->script == pdata);
785
+ break;
786
+
787
+ case PT_SCX:
788
+ set_bit = (prop->script == pdata ||
789
+ MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), pdata) != 0);
790
+ break;
791
+
792
+ case PT_ALNUM:
793
+ gentype = PRIV(ucp_gentype)[prop->chartype];
794
+ set_bit = (gentype == ucp_L || gentype == ucp_N);
795
+ break;
796
+
797
+ case PT_SPACE: /* Perl space */
798
+ case PT_PXSPACE: /* POSIX space */
799
+ switch(c)
800
+ {
801
+ HSPACE_BYTE_CASES:
802
+ VSPACE_BYTE_CASES:
803
+ set_bit = TRUE;
804
+ break;
805
+
806
+ default:
807
+ set_bit = (PRIV(ucp_gentype)[prop->chartype] == ucp_Z);
808
+ break;
809
+ }
810
+ break;
811
+
812
+ case PT_WORD:
813
+ chartype = prop->chartype;
814
+ gentype = PRIV(ucp_gentype)[chartype];
815
+ set_bit = (gentype == ucp_L || gentype == ucp_N ||
816
+ chartype == ucp_Mn || chartype == ucp_Pc);
817
+ break;
818
+
819
+ case PT_UCNC:
820
+ set_bit = (c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
821
+ c == CHAR_GRAVE_ACCENT || c >= 0xa0);
822
+ break;
823
+
824
+ case PT_BIDICL:
825
+ set_bit = (UCD_BIDICLASS_PROP(prop) == pdata);
826
+ break;
827
+
828
+ case PT_BOOL:
829
+ set_bit = MAPBIT(PRIV(ucd_boolprop_sets) +
830
+ UCD_BPROPS_PROP(prop), pdata) != 0;
831
+ break;
832
+
833
+ case PT_PXGRAPH:
834
+ chartype = prop->chartype;
835
+ gentype = PRIV(ucp_gentype)[chartype];
836
+ set_bit = (gentype != ucp_Z && (gentype != ucp_C || chartype == ucp_Cf));
837
+ break;
838
+
839
+ case PT_PXPRINT:
840
+ chartype = prop->chartype;
841
+ set_bit = (chartype != ucp_Zl && chartype != ucp_Zp &&
842
+ (PRIV(ucp_gentype)[chartype] != ucp_C || chartype == ucp_Cf));
843
+ break;
844
+
845
+ case PT_PXPUNCT:
846
+ gentype = PRIV(ucp_gentype)[prop->chartype];
847
+ set_bit = (gentype == ucp_P || (c < 128 && gentype == ucp_S));
848
+ break;
849
+
850
+ default:
851
+ PCRE2_ASSERT(ptype == PT_PXXDIGIT);
852
+ set_bit = (c >= CHAR_0 && c <= CHAR_9) ||
853
+ (c >= CHAR_A && c <= CHAR_F) ||
854
+ (c >= CHAR_a && c <= CHAR_f);
855
+ break;
856
+ }
857
+
858
+ if (negated) set_bit = !set_bit;
859
+ if (set_bit) *classbits |= (uint8_t)(1 << (c & 0x7));
860
+ if ((c & 0x7) == 0x7) classbits++;
861
+ }
862
+ }
863
+
864
+ #endif /* SUPPORT_UNICODE */
865
+
866
+
867
+
868
+ #ifdef SUPPORT_WIDE_CHARS
869
+
870
+ /*************************************************
871
+ * XClass related properties *
872
+ *************************************************/
873
+
874
+ /* XClass needs to be generated. */
875
+ #define XCLASS_REQUIRED 0x1
876
+ /* XClass has 8 bit character. */
877
+ #define XCLASS_HAS_8BIT_CHARS 0x2
878
+ /* XClass has properties. */
879
+ #define XCLASS_HAS_PROPS 0x4
880
+ /* XClass has character lists. */
881
+ #define XCLASS_HAS_CHAR_LISTS 0x8
882
+ /* XClass matches to all >= 256 characters. */
883
+ #define XCLASS_HIGH_ANY 0x10
884
+
885
+ #endif
886
+
887
+
888
+ /*************************************************
889
+ * Internal entry point for add range to class *
890
+ *************************************************/
891
+
892
+ /* This function sets the overall range for characters < 256.
893
+ It also handles non-utf case folding.
894
+
895
+ Arguments:
896
+ options the options bits
897
+ xoptions the extra options bits
898
+ cb compile data
899
+ start start of range character
900
+ end end of range character
901
+
902
+ Returns: cb->classbits is updated
903
+ */
904
+
905
+ static void
906
+ add_to_class(uint32_t options, uint32_t xoptions, compile_block *cb,
907
+ uint32_t start, uint32_t end)
908
+ {
909
+ uint8_t *classbits = cb->classbits.classbits;
910
+ uint32_t c, byte_start, byte_end;
911
+ uint32_t classbits_end = (end <= 0xff ? end : 0xff);
912
+
913
+ #ifndef SUPPORT_UNICODE
914
+ (void)xoptions; /* Avoid compiler warning. */
915
+ #endif
916
+
917
+ /* If caseless matching is required, scan the range and process alternate
918
+ cases. In Unicode, there are 8-bit characters that have alternate cases that
919
+ are greater than 255 and vice-versa (though these may be ignored if caseless
920
+ restriction is in force). Sometimes we can just extend the original range. */
921
+
922
+ if ((options & PCRE2_CASELESS) != 0)
923
+ {
924
+ #ifdef SUPPORT_UNICODE
925
+ /* UTF mode. This branch is taken if we don't support wide characters (e.g.
926
+ 8-bit library, without UTF), but we do treat those characters as Unicode
927
+ (if UCP flag is set). In this case, we only need to expand the character class
928
+ set to include the case pairs which are in the 0-255 codepoint range. */
929
+ if ((options & (PCRE2_UTF|PCRE2_UCP)) != 0)
930
+ {
931
+ BOOL turkish_i = (xoptions & (PCRE2_EXTRA_TURKISH_CASING|PCRE2_EXTRA_CASELESS_RESTRICT)) ==
932
+ PCRE2_EXTRA_TURKISH_CASING;
933
+ if (start < 128)
934
+ {
935
+ uint32_t lo_end = (classbits_end < 127 ? classbits_end : 127);
936
+ for (c = start; c <= lo_end; c++)
937
+ {
938
+ if (turkish_i && UCD_ANY_I(c)) continue;
939
+ SETBIT(classbits, cb->fcc[c]);
940
+ }
941
+ }
942
+ if (classbits_end >= 128)
943
+ {
944
+ uint32_t hi_start = (start > 128 ? start : 128);
945
+ for (c = hi_start; c <= classbits_end; c++)
946
+ {
947
+ uint32_t co = UCD_OTHERCASE(c);
948
+ if (co <= 0xff) SETBIT(classbits, co);
949
+ }
950
+ }
951
+ }
952
+
953
+ else
954
+ #endif /* SUPPORT_UNICODE */
955
+
956
+ /* Not UTF mode */
957
+ {
958
+ for (c = start; c <= classbits_end; c++)
959
+ SETBIT(classbits, cb->fcc[c]);
960
+ }
961
+ }
962
+
963
+ /* Use the bitmap for characters < 256. Otherwise use extra data. */
964
+
965
+ byte_start = (start + 7) >> 3;
966
+ byte_end = (classbits_end + 1) >> 3;
967
+
968
+ if (byte_start >= byte_end)
969
+ {
970
+ for (c = start; c <= classbits_end; c++)
971
+ /* Regardless of start, c will always be <= 255. */
972
+ SETBIT(classbits, c);
973
+ return;
974
+ }
975
+
976
+ for (c = byte_start; c < byte_end; c++)
977
+ classbits[c] = 0xff;
978
+
979
+ byte_start <<= 3;
980
+ byte_end <<= 3;
981
+
982
+ for (c = start; c < byte_start; c++)
983
+ SETBIT(classbits, c);
984
+
985
+ for (c = byte_end; c <= classbits_end; c++)
986
+ SETBIT(classbits, c);
987
+ }
988
+
989
+
990
+ #if PCRE2_CODE_UNIT_WIDTH == 8
991
+ /*************************************************
992
+ * Internal entry point for add list to class *
993
+ *************************************************/
994
+
995
+ /* This function is used for adding a list of horizontal or vertical whitespace
996
+ characters to a class. The list must be in order so that ranges of characters
997
+ can be detected and handled appropriately. This function sets the overall range
998
+ so that the internal functions can try to avoid duplication when handling
999
+ case-independence.
1000
+
1001
+ Arguments:
1002
+ options the options bits
1003
+ xoptions the extra options bits
1004
+ cb contains pointers to tables etc.
1005
+ p points to row of 32-bit values, terminated by NOTACHAR
1006
+
1007
+ Returns: cb->classbits is updated
1008
+ */
1009
+
1010
+ static void
1011
+ add_list_to_class(uint32_t options, uint32_t xoptions, compile_block *cb,
1012
+ const uint32_t *p)
1013
+ {
1014
+ while (p[0] < 256)
1015
+ {
1016
+ unsigned int n = 0;
1017
+
1018
+ while(p[n+1] == p[0] + n + 1) n++;
1019
+ add_to_class(options, xoptions, cb, p[0], p[n]);
1020
+
1021
+ p += n + 1;
1022
+ }
1023
+ }
1024
+
1025
+
1026
+
1027
+ /*************************************************
1028
+ * Add characters not in a list to a class *
1029
+ *************************************************/
1030
+
1031
+ /* This function is used for adding the complement of a list of horizontal or
1032
+ vertical whitespace to a class. The list must be in order.
1033
+
1034
+ Arguments:
1035
+ options the options bits
1036
+ xoptions the extra options bits
1037
+ cb contains pointers to tables etc.
1038
+ p points to row of 32-bit values, terminated by NOTACHAR
1039
+
1040
+ Returns: cb->classbits is updated
1041
+ */
1042
+
1043
+ static void
1044
+ add_not_list_to_class(uint32_t options, uint32_t xoptions, compile_block *cb,
1045
+ const uint32_t *p)
1046
+ {
1047
+ if (p[0] > 0)
1048
+ add_to_class(options, xoptions, cb, 0, p[0] - 1);
1049
+ while (p[0] < 256)
1050
+ {
1051
+ while (p[1] == p[0] + 1) p++;
1052
+ add_to_class(options, xoptions, cb, p[0] + 1, (p[1] > 255) ? 255 : p[1] - 1);
1053
+ p++;
1054
+ }
1055
+ }
1056
+ #endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
1057
+
1058
+
1059
+
1060
+ /*************************************************
1061
+ * Main entry-point to compile a character class *
1062
+ *************************************************/
1063
+
1064
+ /* This function consumes a "leaf", which is a set of characters that will
1065
+ become a single OP_CLASS OP_NCLASS, OP_XCLASS, or OP_ALLANY. */
1066
+
1067
+ uint32_t *
1068
+ PRIV(compile_class_not_nested)(uint32_t options, uint32_t xoptions,
1069
+ uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class, BOOL* has_bitmap,
1070
+ int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr)
1071
+ {
1072
+ uint32_t *pptr = start_ptr;
1073
+ PCRE2_UCHAR *code = *pcode;
1074
+ BOOL should_flip_negation;
1075
+ const uint8_t *cbits = cb->cbits;
1076
+ /* Some functions such as add_to_class() or eclass processing
1077
+ expects that the bitset is stored in cb->classbits.classbits. */
1078
+ uint8_t *const classbits = cb->classbits.classbits;
1079
+ int i;
1080
+
1081
+ #ifdef SUPPORT_UNICODE
1082
+ BOOL utf = (options & PCRE2_UTF) != 0;
1083
+ #else /* No Unicode support */
1084
+ BOOL utf = FALSE;
1085
+ #endif
1086
+
1087
+ /* Helper variables for OP_XCLASS opcode (for characters > 255). */
1088
+
1089
+ #ifdef SUPPORT_WIDE_CHARS
1090
+ uint32_t xclass_props;
1091
+ PCRE2_UCHAR *class_uchardata;
1092
+ class_ranges* cranges;
1093
+ #else
1094
+ (void)has_bitmap; /* Avoid compiler warning. */
1095
+ (void)errorcodeptr; /* Avoid compiler warning. */
1096
+ (void)lengthptr; /* Avoid compiler warning. */
1097
+ #endif
1098
+
1099
+ /* If an XClass contains a negative special such as \S, we need to flip the
1100
+ negation flag at the end, so that support for characters > 255 works correctly
1101
+ (they are all included in the class). An XClass may need to insert specific
1102
+ matching or non-matching code for wide characters.
1103
+ */
1104
+
1105
+ should_flip_negation = FALSE;
1106
+
1107
+ /* XClass will be used when characters > 255 might match. */
1108
+
1109
+ #ifdef SUPPORT_WIDE_CHARS
1110
+ xclass_props = 0;
1111
+
1112
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1113
+ cranges = NULL;
1114
+
1115
+ if (utf)
1116
+ #endif
1117
+ {
1118
+ if (lengthptr != NULL)
1119
+ {
1120
+ cranges = compile_optimize_class(pptr, options, xoptions, cb);
1121
+
1122
+ if (cranges == NULL)
1123
+ {
1124
+ *errorcodeptr = ERR21;
1125
+ return NULL;
1126
+ }
1127
+
1128
+ /* Caching the pre-processed character ranges. */
1129
+ if (cb->last_data != NULL)
1130
+ cb->last_data->next = &cranges->header;
1131
+ else
1132
+ cb->first_data = &cranges->header;
1133
+
1134
+ cb->last_data = &cranges->header;
1135
+ }
1136
+ else
1137
+ {
1138
+ /* Reuse the pre-processed character ranges. */
1139
+ cranges = (class_ranges*)cb->first_data;
1140
+ PCRE2_ASSERT(cranges != NULL && cranges->header.type == CDATA_CRANGE);
1141
+ cb->first_data = cranges->header.next;
1142
+ }
1143
+
1144
+ if (cranges->range_list_size > 0)
1145
+ {
1146
+ const uint32_t *ranges = (const uint32_t*)(cranges + 1);
1147
+
1148
+ if (ranges[0] <= 255)
1149
+ xclass_props |= XCLASS_HAS_8BIT_CHARS;
1150
+
1151
+ if (ranges[cranges->range_list_size - 1] == GET_MAX_CHAR_VALUE(utf) &&
1152
+ ranges[cranges->range_list_size - 2] <= 256)
1153
+ xclass_props |= XCLASS_HIGH_ANY;
1154
+ }
1155
+ }
1156
+
1157
+ class_uchardata = code + LINK_SIZE + 2; /* For XCLASS items */
1158
+ #endif /* SUPPORT_WIDE_CHARS */
1159
+
1160
+ /* Initialize the 256-bit (32-byte) bit map to all zeros. We build the map
1161
+ in a temporary bit of memory, in case the class contains fewer than two
1162
+ 8-bit characters because in that case the compiled code doesn't use the bit
1163
+ map. */
1164
+
1165
+ memset(classbits, 0, 32);
1166
+
1167
+ /* Process items until end_ptr is reached. */
1168
+
1169
+ while (TRUE)
1170
+ {
1171
+ uint32_t meta = *(pptr++);
1172
+ BOOL local_negate;
1173
+ int posix_class;
1174
+ int taboffset, tabopt;
1175
+ class_bits_storage pbits;
1176
+ uint32_t escape, c;
1177
+ int i;
1178
+
1179
+ /* Handle POSIX classes such as [:alpha:] etc. */
1180
+ switch (META_CODE(meta))
1181
+ {
1182
+ case META_POSIX:
1183
+ case META_POSIX_NEG:
1184
+
1185
+ local_negate = (meta == META_POSIX_NEG);
1186
+ posix_class = *(pptr++);
1187
+
1188
+ if (local_negate) should_flip_negation = TRUE; /* Note negative special */
1189
+
1190
+ /* If matching is caseless, upper and lower are converted to alpha.
1191
+ This relies on the fact that the class table starts with alpha,
1192
+ lower, upper as the first 3 entries. */
1193
+
1194
+ if ((options & PCRE2_CASELESS) != 0 && posix_class <= 2)
1195
+ posix_class = 0;
1196
+
1197
+ /* When PCRE2_UCP is set, some of the POSIX classes are converted to
1198
+ different escape sequences that use Unicode properties \p or \P.
1199
+ Others that are not available via \p or \P have to generate
1200
+ XCL_PROP/XCL_NOTPROP directly, which is done here. */
1201
+
1202
+ #ifdef SUPPORT_UNICODE
1203
+ /* TODO This entire block of code here appears to be unreachable!? I simply
1204
+ can't see how it can be hit, given that the frontend parser doesn't emit
1205
+ META_POSIX for GRAPH/PRINT/PUNCT when UCP is set. */
1206
+ if ((options & PCRE2_UCP) != 0 &&
1207
+ (xoptions & PCRE2_EXTRA_ASCII_POSIX) == 0)
1208
+ {
1209
+ uint32_t ptype;
1210
+
1211
+ switch(posix_class)
1212
+ {
1213
+ case PC_GRAPH:
1214
+ case PC_PRINT:
1215
+ case PC_PUNCT:
1216
+ ptype = (posix_class == PC_GRAPH)? PT_PXGRAPH :
1217
+ (posix_class == PC_PRINT)? PT_PXPRINT : PT_PXPUNCT;
1218
+
1219
+ PRIV(update_classbits)(ptype, 0, local_negate, classbits);
1220
+
1221
+ if ((xclass_props & XCLASS_HIGH_ANY) == 0)
1222
+ {
1223
+ if (lengthptr != NULL)
1224
+ *lengthptr += 3;
1225
+ else
1226
+ {
1227
+ *class_uchardata++ = local_negate? XCL_NOTPROP : XCL_PROP;
1228
+ *class_uchardata++ = (PCRE2_UCHAR)ptype;
1229
+ *class_uchardata++ = 0;
1230
+ }
1231
+ xclass_props |= XCLASS_REQUIRED | XCLASS_HAS_PROPS;
1232
+ }
1233
+ continue;
1234
+
1235
+ /* For the other POSIX classes (ex: ascii) we are going to
1236
+ fall through to the non-UCP case and build a bit map for
1237
+ characters with code points less than 256. However, if we are in
1238
+ a negated POSIX class, characters with code points greater than
1239
+ 255 must either all match or all not match, depending on whether
1240
+ the whole class is not or is negated. For example, for
1241
+ [[:^ascii:]... they must all match, whereas for [^[:^ascii:]...
1242
+ they must not.
1243
+
1244
+ In the special case where there are no xclass items, this is
1245
+ automatically handled by the use of OP_CLASS or OP_NCLASS, but an
1246
+ explicit range is needed for OP_XCLASS. Setting a flag here
1247
+ causes the range to be generated later when it is known that
1248
+ OP_XCLASS is required. In the 8-bit library this is relevant only in
1249
+ utf mode, since no wide characters can exist otherwise. */
1250
+
1251
+ default:
1252
+ break;
1253
+ }
1254
+ }
1255
+ #endif /* SUPPORT_UNICODE */
1256
+
1257
+ /* In the non-UCP case, or when UCP makes no difference, we build the
1258
+ bit map for the POSIX class in a chunk of local store because we may
1259
+ be adding and subtracting from it, and we don't want to subtract bits
1260
+ that may be in the main map already. At the end we or the result into
1261
+ the bit map that is being built. */
1262
+
1263
+ posix_class *= 3;
1264
+
1265
+ /* Copy in the first table (always present) */
1266
+
1267
+ memcpy(pbits.classbits, cbits + PRIV(posix_class_maps)[posix_class], 32);
1268
+
1269
+ /* If there is a second table, add or remove it as required. */
1270
+
1271
+ taboffset = PRIV(posix_class_maps)[posix_class + 1];
1272
+ tabopt = PRIV(posix_class_maps)[posix_class + 2];
1273
+
1274
+ if (taboffset >= 0)
1275
+ {
1276
+ if (tabopt >= 0)
1277
+ for (i = 0; i < 32; i++)
1278
+ pbits.classbits[i] |= cbits[i + taboffset];
1279
+ else
1280
+ for (i = 0; i < 32; i++)
1281
+ pbits.classbits[i] &= (uint8_t)(~cbits[i + taboffset]);
1282
+ }
1283
+
1284
+ /* Now see if we need to remove any special characters. An option
1285
+ value of 1 removes vertical space and 2 removes underscore. */
1286
+
1287
+ if (tabopt < 0) tabopt = -tabopt;
1288
+ #ifdef EBCDIC
1289
+ {
1290
+ uint8_t posix_vertical[4] = { CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR };
1291
+ uint8_t posix_underscore = CHAR_UNDERSCORE;
1292
+ uint8_t *chars = NULL;
1293
+ int n = 0;
1294
+
1295
+ if (tabopt == 1) { chars = posix_vertical; n = 4; }
1296
+ else if (tabopt == 2) { chars = &posix_underscore; n = 1; }
1297
+
1298
+ for (; n > 0; ++chars, --n)
1299
+ pbits.classbits[*chars/8] &= ~(1u << (*chars&7));
1300
+ }
1301
+ #else
1302
+ if (tabopt == 1) pbits.classbits[1] &= ~0x3c;
1303
+ else if (tabopt == 2) pbits.classbits[11] &= 0x7f;
1304
+ #endif
1305
+
1306
+ /* Add the POSIX table or its complement into the main table that is
1307
+ being built and we are done. */
1308
+
1309
+ {
1310
+ uint32_t *classwords = cb->classbits.classwords;
1311
+
1312
+ if (local_negate)
1313
+ for (i = 0; i < 8; i++)
1314
+ classwords[i] |= (uint32_t)(~pbits.classwords[i]);
1315
+ else
1316
+ for (i = 0; i < 8; i++)
1317
+ classwords[i] |= pbits.classwords[i];
1318
+ }
1319
+
1320
+ #ifdef SUPPORT_WIDE_CHARS
1321
+ /* Every class contains at least one < 256 character. */
1322
+ xclass_props |= XCLASS_HAS_8BIT_CHARS;
1323
+ #endif
1324
+ continue; /* End of POSIX handling */
1325
+
1326
+ /* Other than POSIX classes, the only items we should encounter are
1327
+ \d-type escapes and literal characters (possibly as ranges). */
1328
+ case META_BIGVALUE:
1329
+ meta = *(pptr++);
1330
+ break;
1331
+
1332
+ case META_ESCAPE:
1333
+ escape = META_DATA(meta);
1334
+
1335
+ switch(escape)
1336
+ {
1337
+ case ESC_d:
1338
+ for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_digit];
1339
+ break;
1340
+
1341
+ case ESC_D:
1342
+ should_flip_negation = TRUE;
1343
+ for (i = 0; i < 32; i++)
1344
+ classbits[i] |= (uint8_t)(~cbits[i+cbit_digit]);
1345
+ break;
1346
+
1347
+ case ESC_w:
1348
+ for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_word];
1349
+ break;
1350
+
1351
+ case ESC_W:
1352
+ should_flip_negation = TRUE;
1353
+ for (i = 0; i < 32; i++)
1354
+ classbits[i] |= (uint8_t)(~cbits[i+cbit_word]);
1355
+ break;
1356
+
1357
+ /* Perl 5.004 onwards omitted VT from \s, but restored it at Perl
1358
+ 5.18. Before PCRE 8.34, we had to preserve the VT bit if it was
1359
+ previously set by something earlier in the character class.
1360
+ Luckily, the value of CHAR_VT is 0x0b in both ASCII and EBCDIC, so
1361
+ we could just adjust the appropriate bit. From PCRE 8.34 we no
1362
+ longer treat \s and \S specially. */
1363
+
1364
+ case ESC_s:
1365
+ for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_space];
1366
+ break;
1367
+
1368
+ case ESC_S:
1369
+ should_flip_negation = TRUE;
1370
+ for (i = 0; i < 32; i++)
1371
+ classbits[i] |= (uint8_t)(~cbits[i+cbit_space]);
1372
+ break;
1373
+
1374
+ /* When adding the horizontal or vertical space lists to a class, or
1375
+ their complements, disable PCRE2_CASELESS, because it justs wastes
1376
+ time, and in the "not-x" UTF cases can create unwanted duplicates in
1377
+ the XCLASS list (provoked by characters that have more than one other
1378
+ case and by both cases being in the same "not-x" sublist). */
1379
+
1380
+ case ESC_h:
1381
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1382
+ #ifdef SUPPORT_UNICODE
1383
+ if (cranges != NULL) break;
1384
+ #endif
1385
+ add_list_to_class(options & ~PCRE2_CASELESS, xoptions,
1386
+ cb, PRIV(hspace_list));
1387
+ #else
1388
+ PCRE2_ASSERT(cranges != NULL);
1389
+ #endif
1390
+ break;
1391
+
1392
+ case ESC_H:
1393
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1394
+ #ifdef SUPPORT_UNICODE
1395
+ if (cranges != NULL) break;
1396
+ #endif
1397
+ add_not_list_to_class(options & ~PCRE2_CASELESS, xoptions,
1398
+ cb, PRIV(hspace_list));
1399
+ #else
1400
+ PCRE2_ASSERT(cranges != NULL);
1401
+ #endif
1402
+ break;
1403
+
1404
+ case ESC_v:
1405
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1406
+ #ifdef SUPPORT_UNICODE
1407
+ if (cranges != NULL) break;
1408
+ #endif
1409
+ add_list_to_class(options & ~PCRE2_CASELESS, xoptions,
1410
+ cb, PRIV(vspace_list));
1411
+ #else
1412
+ PCRE2_ASSERT(cranges != NULL);
1413
+ #endif
1414
+ break;
1415
+
1416
+ case ESC_V:
1417
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1418
+ #ifdef SUPPORT_UNICODE
1419
+ if (cranges != NULL) break;
1420
+ #endif
1421
+ add_not_list_to_class(options & ~PCRE2_CASELESS, xoptions,
1422
+ cb, PRIV(vspace_list));
1423
+ #else
1424
+ PCRE2_ASSERT(cranges != NULL);
1425
+ #endif
1426
+ break;
1427
+
1428
+ /* If Unicode is not supported, \P and \p are not allowed and are
1429
+ faulted at parse time, so will never appear here. */
1430
+
1431
+ #ifdef SUPPORT_UNICODE
1432
+ case ESC_p:
1433
+ case ESC_P:
1434
+ {
1435
+ uint32_t ptype = *pptr >> 16;
1436
+ uint32_t pdata = *(pptr++) & 0xffff;
1437
+
1438
+ /* The "Any" is processed by PRIV(update_classbits)(). */
1439
+ if (ptype == PT_ANY)
1440
+ {
1441
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1442
+ if (!utf && escape == ESC_p) memset(classbits, 0xff, 32);
1443
+ #endif
1444
+ continue;
1445
+ }
1446
+
1447
+ PRIV(update_classbits)(ptype, pdata, (escape == ESC_P), classbits);
1448
+
1449
+ if ((xclass_props & XCLASS_HIGH_ANY) == 0)
1450
+ {
1451
+ if (lengthptr != NULL)
1452
+ *lengthptr += 3;
1453
+ else
1454
+ {
1455
+ *class_uchardata++ = (escape == ESC_p)? XCL_PROP : XCL_NOTPROP;
1456
+ *class_uchardata++ = ptype;
1457
+ *class_uchardata++ = pdata;
1458
+ }
1459
+ xclass_props |= XCLASS_REQUIRED | XCLASS_HAS_PROPS;
1460
+ }
1461
+ }
1462
+ continue;
1463
+ #endif
1464
+ }
1465
+
1466
+ #ifdef SUPPORT_WIDE_CHARS
1467
+ /* Every non-property class contains at least one < 256 character. */
1468
+ xclass_props |= XCLASS_HAS_8BIT_CHARS;
1469
+ #endif
1470
+ /* End handling \d-type escapes */
1471
+ continue;
1472
+
1473
+ CLASS_END_CASES(meta)
1474
+ /* Literals. */
1475
+ if (meta < META_END) break;
1476
+ /* Non-literals: end of class contents. */
1477
+ goto END_PROCESSING;
1478
+ }
1479
+
1480
+ /* A literal character may be followed by a range meta. At parse time
1481
+ there are checks for out-of-order characters, for ranges where the two
1482
+ characters are equal, and for hyphens that cannot indicate a range. At
1483
+ this point, therefore, no checking is needed. */
1484
+
1485
+ c = meta;
1486
+
1487
+ /* Remember if \r or \n were explicitly used */
1488
+
1489
+ if (c == CHAR_CR || c == CHAR_NL) cb->external_flags |= PCRE2_HASCRORLF;
1490
+
1491
+ /* Process a character range */
1492
+
1493
+ if (*pptr == META_RANGE_LITERAL || *pptr == META_RANGE_ESCAPED)
1494
+ {
1495
+ uint32_t d;
1496
+
1497
+ #ifdef EBCDIC
1498
+ BOOL range_is_literal = (*pptr == META_RANGE_LITERAL);
1499
+ #endif
1500
+ ++pptr;
1501
+ d = *(pptr++);
1502
+ if (d == META_BIGVALUE) d = *(pptr++);
1503
+
1504
+ /* Remember an explicit \r or \n, and add the range to the class. */
1505
+
1506
+ if (d == CHAR_CR || d == CHAR_NL) cb->external_flags |= PCRE2_HASCRORLF;
1507
+
1508
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1509
+ #ifdef SUPPORT_UNICODE
1510
+ if (cranges != NULL) continue;
1511
+ xclass_props |= XCLASS_HAS_8BIT_CHARS;
1512
+ #endif
1513
+
1514
+ /* In an EBCDIC environment, Perl treats alphabetic ranges specially
1515
+ because there are holes in the encoding, and simply using the range
1516
+ A-Z (for example) would include the characters in the holes. This
1517
+ applies only to literal ranges; [\xC1-\xE9] is different to [A-Z]. */
1518
+
1519
+ #ifdef EBCDIC
1520
+ if (range_is_literal &&
1521
+ (cb->ctypes[c] & ctype_letter) != 0 &&
1522
+ (cb->ctypes[d] & ctype_letter) != 0 &&
1523
+ (c <= CHAR_z) == (d <= CHAR_z))
1524
+ {
1525
+ uint32_t uc = (d <= CHAR_z)? 0 : 64;
1526
+ uint32_t C = c - uc;
1527
+ uint32_t D = d - uc;
1528
+
1529
+ if (C <= CHAR_i)
1530
+ {
1531
+ add_to_class(options, xoptions, cb, C + uc,
1532
+ ((D < CHAR_i)? D : CHAR_i) + uc);
1533
+ C = CHAR_j;
1534
+ }
1535
+
1536
+ if (C <= D && C <= CHAR_r)
1537
+ {
1538
+ add_to_class(options, xoptions, cb, C + uc,
1539
+ ((D < CHAR_r)? D : CHAR_r) + uc);
1540
+ C = CHAR_s;
1541
+ }
1542
+
1543
+ if (C <= D)
1544
+ add_to_class(options, xoptions, cb, C + uc, D + uc);
1545
+ }
1546
+ else
1547
+ #endif
1548
+ /* Not an EBCDIC special range */
1549
+
1550
+ add_to_class(options, xoptions, cb, c, d);
1551
+ #else
1552
+ PCRE2_ASSERT(cranges != NULL);
1553
+ #endif
1554
+ continue;
1555
+ } /* End of range handling */
1556
+
1557
+ /* Character ranges are ignored when class_ranges is present. */
1558
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1559
+ #ifdef SUPPORT_UNICODE
1560
+ if (cranges != NULL) continue;
1561
+ xclass_props |= XCLASS_HAS_8BIT_CHARS;
1562
+ #endif
1563
+ /* Handle a single character. */
1564
+
1565
+ add_to_class(options, xoptions, cb, meta, meta);
1566
+ #else
1567
+ PCRE2_ASSERT(cranges != NULL);
1568
+ #endif
1569
+ } /* End of main class-processing loop */
1570
+
1571
+ END_PROCESSING:
1572
+
1573
+ #ifdef SUPPORT_WIDE_CHARS
1574
+ PCRE2_ASSERT((xclass_props & XCLASS_HAS_PROPS) == 0 ||
1575
+ (xclass_props & XCLASS_HIGH_ANY) == 0);
1576
+
1577
+ if (cranges != NULL)
1578
+ {
1579
+ uint32_t *range = (uint32_t*)(cranges + 1);
1580
+ uint32_t *end = range + cranges->range_list_size;
1581
+
1582
+ while (range < end && range[0] < 256)
1583
+ {
1584
+ PCRE2_ASSERT((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0);
1585
+ /* Add range to bitset. If we are in UTF or UCP mode, then clear the
1586
+ caseless bit, because the cranges handle caselessness (only) in this
1587
+ condition; see the condition for PARSE_CLASS_CASELESS_UTF in
1588
+ compile_optimize_class(). */
1589
+ add_to_class(((options & (PCRE2_UTF|PCRE2_UCP)) != 0)?
1590
+ (options & ~PCRE2_CASELESS) : options, xoptions, cb, range[0], range[1]);
1591
+
1592
+ if (range[1] > 255) break;
1593
+ range += 2;
1594
+ }
1595
+
1596
+ if (cranges->char_lists_size > 0)
1597
+ {
1598
+ /* The cranges structure is still used and freed later. */
1599
+ PCRE2_ASSERT((xclass_props & XCLASS_HIGH_ANY) == 0);
1600
+ xclass_props |= XCLASS_REQUIRED | XCLASS_HAS_CHAR_LISTS;
1601
+ }
1602
+ else
1603
+ {
1604
+ if ((xclass_props & XCLASS_HIGH_ANY) != 0)
1605
+ {
1606
+ PCRE2_ASSERT(range + 2 == end && range[0] <= 256 &&
1607
+ range[1] >= GET_MAX_CHAR_VALUE(utf));
1608
+ should_flip_negation = TRUE;
1609
+ range = end;
1610
+ }
1611
+
1612
+ while (range < end)
1613
+ {
1614
+ uint32_t range_start = range[0];
1615
+ uint32_t range_end = range[1];
1616
+
1617
+ range += 2;
1618
+ xclass_props |= XCLASS_REQUIRED;
1619
+
1620
+ if (range_start < 256) range_start = 256;
1621
+
1622
+ if (lengthptr != NULL)
1623
+ {
1624
+ #ifdef SUPPORT_UNICODE
1625
+ if (utf)
1626
+ {
1627
+ *lengthptr += 1;
1628
+
1629
+ if (range_start < range_end)
1630
+ *lengthptr += PRIV(ord2utf)(range_start, class_uchardata);
1631
+
1632
+ *lengthptr += PRIV(ord2utf)(range_end, class_uchardata);
1633
+ continue;
1634
+ }
1635
+ #endif /* SUPPORT_UNICODE */
1636
+
1637
+ *lengthptr += range_start < range_end ? 3 : 2;
1638
+ continue;
1639
+ }
1640
+
1641
+ #ifdef SUPPORT_UNICODE
1642
+ if (utf)
1643
+ {
1644
+ if (range_start < range_end)
1645
+ {
1646
+ *class_uchardata++ = XCL_RANGE;
1647
+ class_uchardata += PRIV(ord2utf)(range_start, class_uchardata);
1648
+ }
1649
+ else
1650
+ *class_uchardata++ = XCL_SINGLE;
1651
+
1652
+ class_uchardata += PRIV(ord2utf)(range_end, class_uchardata);
1653
+ continue;
1654
+ }
1655
+ #endif /* SUPPORT_UNICODE */
1656
+
1657
+ /* Without UTF support, character values are constrained
1658
+ by the bit length, and can only be > 256 for 16-bit and
1659
+ 32-bit libraries. */
1660
+ #if PCRE2_CODE_UNIT_WIDTH != 8
1661
+ if (range_start < range_end)
1662
+ {
1663
+ *class_uchardata++ = XCL_RANGE;
1664
+ *class_uchardata++ = range_start;
1665
+ }
1666
+ else
1667
+ *class_uchardata++ = XCL_SINGLE;
1668
+
1669
+ *class_uchardata++ = range_end;
1670
+ #endif /* PCRE2_CODE_UNIT_WIDTH == 8 */
1671
+ }
1672
+
1673
+ if (lengthptr == NULL)
1674
+ cb->cx->memctl.free(cranges, cb->cx->memctl.memory_data);
1675
+ }
1676
+ }
1677
+ #endif /* SUPPORT_WIDE_CHARS */
1678
+
1679
+ /* If there are characters with values > 255, or Unicode property settings
1680
+ (\p or \P), we have to compile an extended class, with its own opcode,
1681
+ unless there were no property settings and there was a negated special such
1682
+ as \S in the class, and PCRE2_UCP is not set, because in that case all
1683
+ characters > 255 are in or not in the class, so any that were explicitly
1684
+ given as well can be ignored.
1685
+
1686
+ In the UCP case, if certain negated POSIX classes (ex: [:^ascii:]) were
1687
+ were present in a class, we either have to match or not match all wide
1688
+ characters (depending on whether the whole class is or is not negated).
1689
+ This requirement is indicated by match_all_or_no_wide_chars being true.
1690
+ We do this by including an explicit range, which works in both cases.
1691
+ This applies only in UTF and 16-bit and 32-bit non-UTF modes, since there
1692
+ cannot be any wide characters in 8-bit non-UTF mode.
1693
+
1694
+ When there *are* properties in a positive UTF-8 or any 16-bit or 32_bit
1695
+ class where \S etc is present without PCRE2_UCP, causing an extended class
1696
+ to be compiled, we make sure that all characters > 255 are included by
1697
+ forcing match_all_or_no_wide_chars to be true.
1698
+
1699
+ If, when generating an xclass, there are no characters < 256, we can omit
1700
+ the bitmap in the actual compiled code. */
1701
+
1702
+ #ifdef SUPPORT_WIDE_CHARS /* Defined for 16/32 bits, or 8-bit with Unicode */
1703
+ if ((xclass_props & XCLASS_REQUIRED) != 0)
1704
+ {
1705
+ PCRE2_UCHAR *previous = code;
1706
+
1707
+ if ((xclass_props & XCLASS_HAS_CHAR_LISTS) == 0)
1708
+ *class_uchardata++ = XCL_END; /* Marks the end of extra data */
1709
+ *code++ = OP_XCLASS;
1710
+ code += LINK_SIZE;
1711
+ *code = negate_class? XCL_NOT:0;
1712
+ if ((xclass_props & XCLASS_HAS_PROPS) != 0) *code |= XCL_HASPROP;
1713
+
1714
+ /* If the map is required, move up the extra data to make room for it;
1715
+ otherwise just move the code pointer to the end of the extra data. */
1716
+
1717
+ if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0 || has_bitmap != NULL)
1718
+ {
1719
+ if (negate_class)
1720
+ {
1721
+ uint32_t *classwords = cb->classbits.classwords;
1722
+ for (i = 0; i < 8; i++) classwords[i] = ~classwords[i];
1723
+ }
1724
+
1725
+ if (has_bitmap == NULL)
1726
+ {
1727
+ *code++ |= XCL_MAP;
1728
+ (void)memmove(code + (32 / sizeof(PCRE2_UCHAR)), code,
1729
+ CU2BYTES(class_uchardata - code));
1730
+ memcpy(code, classbits, 32);
1731
+ code = class_uchardata + (32 / sizeof(PCRE2_UCHAR));
1732
+ }
1733
+ else
1734
+ {
1735
+ code = class_uchardata;
1736
+ if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0)
1737
+ *has_bitmap = TRUE;
1738
+ }
1739
+ }
1740
+ else code = class_uchardata;
1741
+
1742
+ if ((xclass_props & XCLASS_HAS_CHAR_LISTS) != 0)
1743
+ {
1744
+ /* Char lists size is an even number, because all items are 16 or 32
1745
+ bit values. The character list data is always aligned to 32 bits. */
1746
+ size_t char_lists_size = cranges->char_lists_size;
1747
+ PCRE2_ASSERT((char_lists_size & 0x1) == 0 &&
1748
+ (cb->char_lists_size & 0x3) == 0);
1749
+
1750
+ if (lengthptr != NULL)
1751
+ {
1752
+ char_lists_size = CLIST_ALIGN_TO(char_lists_size, sizeof(uint32_t));
1753
+
1754
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1755
+ *lengthptr += 2 + LINK_SIZE;
1756
+ #else
1757
+ *lengthptr += 1 + LINK_SIZE;
1758
+ #endif
1759
+
1760
+ cb->char_lists_size += char_lists_size;
1761
+
1762
+ char_lists_size /= sizeof(PCRE2_UCHAR);
1763
+
1764
+ /* Storage space for character lists is included
1765
+ in the maximum pattern size. */
1766
+ if (*lengthptr > MAX_PATTERN_SIZE ||
1767
+ MAX_PATTERN_SIZE - *lengthptr < char_lists_size)
1768
+ {
1769
+ *errorcodeptr = ERR20; /* Pattern is too large */
1770
+ return NULL;
1771
+ }
1772
+ }
1773
+ else
1774
+ {
1775
+ uint8_t *data;
1776
+
1777
+ PCRE2_ASSERT(cranges->char_lists_types <= XCL_TYPE_MASK);
1778
+ #if PCRE2_CODE_UNIT_WIDTH == 8
1779
+ /* Encode as high / low bytes. */
1780
+ code[0] = (uint8_t)(XCL_LIST |
1781
+ (cranges->char_lists_types >> 8));
1782
+ code[1] = (uint8_t)cranges->char_lists_types;
1783
+ code += 2;
1784
+ #else
1785
+ *code++ = (PCRE2_UCHAR)(XCL_LIST | cranges->char_lists_types);
1786
+ #endif
1787
+
1788
+ /* Character lists are stored in backwards direction from
1789
+ byte code start. The non-dfa/dfa matchers can access these
1790
+ lists using the byte code start stored in match blocks.
1791
+ Each list is aligned to 32 bit with an optional unused
1792
+ 16 bit value at the beginning of the character list. */
1793
+
1794
+ cb->char_lists_size += char_lists_size;
1795
+ data = (uint8_t*)cb->start_code - cb->char_lists_size;
1796
+
1797
+ memcpy(data, (uint8_t*)(cranges + 1) + cranges->char_lists_start,
1798
+ char_lists_size);
1799
+
1800
+ /* Since character lists total size is less than MAX_PATTERN_SIZE,
1801
+ their starting offset fits into a value which size is LINK_SIZE. */
1802
+
1803
+ char_lists_size = cb->char_lists_size;
1804
+ PUT(code, 0, (uint32_t)(char_lists_size >> 1));
1805
+ code += LINK_SIZE;
1806
+
1807
+ #if defined PCRE2_DEBUG || defined SUPPORT_VALGRIND
1808
+ if ((char_lists_size & 0x2) != 0)
1809
+ {
1810
+ /* In debug the unused 16 bit value is set
1811
+ to a fixed value and marked unused. */
1812
+ ((uint16_t*)data)[-1] = 0x5555;
1813
+ #ifdef SUPPORT_VALGRIND
1814
+ VALGRIND_MAKE_MEM_NOACCESS(data - 2, 2);
1815
+ #endif
1816
+ }
1817
+ #endif
1818
+
1819
+ cb->char_lists_size =
1820
+ CLIST_ALIGN_TO(char_lists_size, sizeof(uint32_t));
1821
+
1822
+ cb->cx->memctl.free(cranges, cb->cx->memctl.memory_data);
1823
+ }
1824
+ }
1825
+
1826
+ /* Now fill in the complete length of the item */
1827
+
1828
+ PUT(previous, 1, (int)(code - previous));
1829
+ goto DONE; /* End of class handling */
1830
+ }
1831
+ #endif /* SUPPORT_WIDE_CHARS */
1832
+
1833
+ /* If there are no characters > 255, or they are all to be included or
1834
+ excluded, set the opcode to OP_CLASS or OP_NCLASS, depending on whether the
1835
+ whole class was negated and whether there were negative specials such as \S
1836
+ (non-UCP) in the class. Then copy the 32-byte map into the code vector,
1837
+ negating it if necessary. */
1838
+
1839
+ if (negate_class)
1840
+ {
1841
+ uint32_t *classwords = cb->classbits.classwords;
1842
+
1843
+ for (i = 0; i < 8; i++) classwords[i] = ~classwords[i];
1844
+ }
1845
+
1846
+ if ((SELECT_VALUE8(!utf, 0) || negate_class != should_flip_negation) &&
1847
+ cb->classbits.classwords[0] == ~(uint32_t)0)
1848
+ {
1849
+ const uint32_t *classwords = cb->classbits.classwords;
1850
+ int i;
1851
+
1852
+ for (i = 0; i < 8; i++)
1853
+ if (classwords[i] != ~(uint32_t)0) break;
1854
+
1855
+ if (i == 8)
1856
+ {
1857
+ *code++ = OP_ALLANY;
1858
+ goto DONE; /* End of class handling */
1859
+ }
1860
+ }
1861
+
1862
+ *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;
1863
+ memcpy(code, classbits, 32);
1864
+ code += 32 / sizeof(PCRE2_UCHAR);
1865
+
1866
+ DONE:
1867
+ *pcode = code;
1868
+ return pptr - 1;
1869
+ }
1870
+
1871
+
1872
+
1873
+ /* ===================================================================*/
1874
+ /* Here follows a block of ECLASS-compiling functions. You may well want to
1875
+ read them from top to bottom; they are ordered from leafmost (at the top) to
1876
+ outermost parser (at the bottom of the file). */
1877
+
1878
+ /* This function folds one operand using the negation operator.
1879
+ The new, combined chunk of stack code is written out to *pop_info. */
1880
+
1881
+ static void
1882
+ fold_negation(eclass_op_info *pop_info, PCRE2_SIZE *lengthptr,
1883
+ BOOL preserve_classbits)
1884
+ {
1885
+ int i;
1886
+
1887
+ /* If the chunk of stack code is already composed of multiple ops, we won't
1888
+ descend in and try and propagate the negation down the tree. (That would lead
1889
+ to O(n^2) compile-time, which could be exploitable with a malicious regex -
1890
+ although maybe that's not really too much of a worry in a library that offers
1891
+ an exponential-time matching function!) */
1892
+
1893
+ if (pop_info->op_single_type == 0)
1894
+ {
1895
+ if (lengthptr != NULL)
1896
+ *lengthptr += 1;
1897
+ else
1898
+ pop_info->code_start[pop_info->length] = ECL_NOT;
1899
+ pop_info->length += 1;
1900
+ }
1901
+
1902
+ /* Otherwise, it's a nice single-op item, so we can easily fold in the negation
1903
+ without needing to produce an ECL_NOT. */
1904
+
1905
+ else if (pop_info->op_single_type == ECL_ANY ||
1906
+ pop_info->op_single_type == ECL_NONE)
1907
+ {
1908
+ pop_info->op_single_type = (pop_info->op_single_type == ECL_NONE)?
1909
+ ECL_ANY : ECL_NONE;
1910
+ if (lengthptr == NULL)
1911
+ *(pop_info->code_start) = pop_info->op_single_type;
1912
+ }
1913
+ else
1914
+ {
1915
+ PCRE2_ASSERT(pop_info->op_single_type == ECL_XCLASS &&
1916
+ pop_info->length >= 1 + LINK_SIZE + 1);
1917
+ if (lengthptr == NULL)
1918
+ pop_info->code_start[1 + LINK_SIZE] ^= XCL_NOT;
1919
+ }
1920
+
1921
+ if (!preserve_classbits)
1922
+ {
1923
+ for (i = 0; i < 8; i++)
1924
+ pop_info->bits.classwords[i] = ~pop_info->bits.classwords[i];
1925
+ }
1926
+ }
1927
+
1928
+
1929
+
1930
+ /* This function folds together two operands using a binary operator.
1931
+ The new, combined chunk of stack code is written out to *lhs_op_info. */
1932
+
1933
+ static void
1934
+ fold_binary(int op, eclass_op_info *lhs_op_info, eclass_op_info *rhs_op_info,
1935
+ PCRE2_SIZE *lengthptr)
1936
+ {
1937
+ int i;
1938
+
1939
+ switch (op)
1940
+ {
1941
+ /* ECL_AND truth table:
1942
+
1943
+ LHS RHS RESULT
1944
+ ----------------
1945
+ ANY * RHS
1946
+ * ANY LHS
1947
+ NONE * NONE
1948
+ * NONE NONE
1949
+ X Y X & Y
1950
+ */
1951
+
1952
+ case ECL_AND:
1953
+ if (rhs_op_info->op_single_type == ECL_ANY)
1954
+ {
1955
+ /* no-op: drop the RHS */
1956
+ }
1957
+ else if (lhs_op_info->op_single_type == ECL_ANY)
1958
+ {
1959
+ /* no-op: drop the LHS, and memmove the RHS into its place */
1960
+ if (lengthptr == NULL)
1961
+ memmove(lhs_op_info->code_start, rhs_op_info->code_start,
1962
+ CU2BYTES(rhs_op_info->length));
1963
+ lhs_op_info->length = rhs_op_info->length;
1964
+ lhs_op_info->op_single_type = rhs_op_info->op_single_type;
1965
+ }
1966
+ else if (rhs_op_info->op_single_type == ECL_NONE)
1967
+ {
1968
+ /* the result is ECL_NONE: write into the LHS */
1969
+ if (lengthptr == NULL)
1970
+ lhs_op_info->code_start[0] = ECL_NONE;
1971
+ lhs_op_info->length = 1;
1972
+ lhs_op_info->op_single_type = ECL_NONE;
1973
+ }
1974
+ else if (lhs_op_info->op_single_type == ECL_NONE)
1975
+ {
1976
+ /* the result is ECL_NONE: drop the RHS */
1977
+ }
1978
+ else
1979
+ {
1980
+ /* Both of LHS & RHS are either ECL_XCLASS, or compound operations. */
1981
+ if (lengthptr != NULL)
1982
+ *lengthptr += 1;
1983
+ else
1984
+ {
1985
+ PCRE2_ASSERT(rhs_op_info->code_start ==
1986
+ lhs_op_info->code_start + lhs_op_info->length);
1987
+ rhs_op_info->code_start[rhs_op_info->length] = ECL_AND;
1988
+ }
1989
+ lhs_op_info->length += rhs_op_info->length + 1;
1990
+ lhs_op_info->op_single_type = 0;
1991
+ }
1992
+
1993
+ for (i = 0; i < 8; i++)
1994
+ lhs_op_info->bits.classwords[i] &= rhs_op_info->bits.classwords[i];
1995
+ break;
1996
+
1997
+ /* ECL_OR truth table:
1998
+
1999
+ LHS RHS RESULT
2000
+ ----------------
2001
+ ANY * ANY
2002
+ * ANY ANY
2003
+ NONE * RHS
2004
+ * NONE LHS
2005
+ X Y X | Y
2006
+ */
2007
+
2008
+ case ECL_OR:
2009
+ if (rhs_op_info->op_single_type == ECL_NONE)
2010
+ {
2011
+ /* no-op: drop the RHS */
2012
+ }
2013
+ else if (lhs_op_info->op_single_type == ECL_NONE)
2014
+ {
2015
+ /* no-op: drop the LHS, and memmove the RHS into its place */
2016
+ if (lengthptr == NULL)
2017
+ memmove(lhs_op_info->code_start, rhs_op_info->code_start,
2018
+ CU2BYTES(rhs_op_info->length));
2019
+ lhs_op_info->length = rhs_op_info->length;
2020
+ lhs_op_info->op_single_type = rhs_op_info->op_single_type;
2021
+ }
2022
+ else if (rhs_op_info->op_single_type == ECL_ANY)
2023
+ {
2024
+ /* the result is ECL_ANY: write into the LHS */
2025
+ if (lengthptr == NULL)
2026
+ lhs_op_info->code_start[0] = ECL_ANY;
2027
+ lhs_op_info->length = 1;
2028
+ lhs_op_info->op_single_type = ECL_ANY;
2029
+ }
2030
+ else if (lhs_op_info->op_single_type == ECL_ANY)
2031
+ {
2032
+ /* the result is ECL_ANY: drop the RHS */
2033
+ }
2034
+ else
2035
+ {
2036
+ /* Both of LHS & RHS are either ECL_XCLASS, or compound operations. */
2037
+ if (lengthptr != NULL)
2038
+ *lengthptr += 1;
2039
+ else
2040
+ {
2041
+ PCRE2_ASSERT(rhs_op_info->code_start ==
2042
+ lhs_op_info->code_start + lhs_op_info->length);
2043
+ rhs_op_info->code_start[rhs_op_info->length] = ECL_OR;
2044
+ }
2045
+ lhs_op_info->length += rhs_op_info->length + 1;
2046
+ lhs_op_info->op_single_type = 0;
2047
+ }
2048
+
2049
+ for (i = 0; i < 8; i++)
2050
+ lhs_op_info->bits.classwords[i] |= rhs_op_info->bits.classwords[i];
2051
+ break;
2052
+
2053
+ /* ECL_XOR truth table:
2054
+
2055
+ LHS RHS RESULT
2056
+ ----------------
2057
+ ANY * !RHS
2058
+ * ANY !LHS
2059
+ NONE * RHS
2060
+ * NONE LHS
2061
+ X Y X ^ Y
2062
+ */
2063
+
2064
+ case ECL_XOR:
2065
+ if (rhs_op_info->op_single_type == ECL_NONE)
2066
+ {
2067
+ /* no-op: drop the RHS */
2068
+ }
2069
+ else if (lhs_op_info->op_single_type == ECL_NONE)
2070
+ {
2071
+ /* no-op: drop the LHS, and memmove the RHS into its place */
2072
+ if (lengthptr == NULL)
2073
+ memmove(lhs_op_info->code_start, rhs_op_info->code_start,
2074
+ CU2BYTES(rhs_op_info->length));
2075
+ lhs_op_info->length = rhs_op_info->length;
2076
+ lhs_op_info->op_single_type = rhs_op_info->op_single_type;
2077
+ }
2078
+ else if (rhs_op_info->op_single_type == ECL_ANY)
2079
+ {
2080
+ /* the result is !LHS: fold in the negation, and drop the RHS */
2081
+ /* Preserve the classbits, because we promise to deal with them later. */
2082
+ fold_negation(lhs_op_info, lengthptr, TRUE);
2083
+ }
2084
+ else if (lhs_op_info->op_single_type == ECL_ANY)
2085
+ {
2086
+ /* the result is !RHS: drop the LHS, memmove the RHS into its place, and
2087
+ fold in the negation */
2088
+ if (lengthptr == NULL)
2089
+ memmove(lhs_op_info->code_start, rhs_op_info->code_start,
2090
+ CU2BYTES(rhs_op_info->length));
2091
+ lhs_op_info->length = rhs_op_info->length;
2092
+ lhs_op_info->op_single_type = rhs_op_info->op_single_type;
2093
+
2094
+ /* Preserve the classbits, because we promise to deal with them later. */
2095
+ fold_negation(lhs_op_info, lengthptr, TRUE);
2096
+ }
2097
+ else
2098
+ {
2099
+ /* Both of LHS & RHS are either ECL_XCLASS, or compound operations. */
2100
+ if (lengthptr != NULL)
2101
+ *lengthptr += 1;
2102
+ else
2103
+ {
2104
+ PCRE2_ASSERT(rhs_op_info->code_start ==
2105
+ lhs_op_info->code_start + lhs_op_info->length);
2106
+ rhs_op_info->code_start[rhs_op_info->length] = ECL_XOR;
2107
+ }
2108
+ lhs_op_info->length += rhs_op_info->length + 1;
2109
+ lhs_op_info->op_single_type = 0;
2110
+ }
2111
+
2112
+ for (i = 0; i < 8; i++)
2113
+ lhs_op_info->bits.classwords[i] ^= rhs_op_info->bits.classwords[i];
2114
+ break;
2115
+
2116
+ /* LCOV_EXCL_START */
2117
+ default:
2118
+ PCRE2_DEBUG_UNREACHABLE();
2119
+ break;
2120
+ /* LCOV_EXCL_STOP */
2121
+ }
2122
+ }
2123
+
2124
+
2125
+
2126
+ static BOOL
2127
+ compile_eclass_nested(eclass_context *context, BOOL negated,
2128
+ uint32_t **pptr, PCRE2_UCHAR **pcode,
2129
+ eclass_op_info *pop_info, PCRE2_SIZE *lengthptr);
2130
+
2131
+ /* This function consumes a group of implicitly-unioned class elements.
2132
+ These can be characters, ranges, properties, or nested classes, as long
2133
+ as they are all joined by being placed adjacently. */
2134
+
2135
+ static BOOL
2136
+ compile_class_operand(eclass_context *context, BOOL negated,
2137
+ uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info,
2138
+ PCRE2_SIZE *lengthptr)
2139
+ {
2140
+ uint32_t *ptr = *pptr;
2141
+ uint32_t *prev_ptr;
2142
+ PCRE2_UCHAR *code = *pcode;
2143
+ PCRE2_UCHAR *code_start = code;
2144
+ PCRE2_SIZE prev_length = (lengthptr != NULL)? *lengthptr : 0;
2145
+ PCRE2_SIZE extra_length;
2146
+ uint32_t meta = META_CODE(*ptr);
2147
+ int i;
2148
+
2149
+ switch (meta)
2150
+ {
2151
+ case META_CLASS_EMPTY_NOT:
2152
+ case META_CLASS_EMPTY:
2153
+ ++ptr;
2154
+ pop_info->length = 1;
2155
+ if ((meta == META_CLASS_EMPTY) == negated)
2156
+ {
2157
+ *code++ = pop_info->op_single_type = ECL_ANY;
2158
+ memset(pop_info->bits.classbits, 0xff, 32);
2159
+ }
2160
+ else
2161
+ {
2162
+ *code++ = pop_info->op_single_type = ECL_NONE;
2163
+ memset(pop_info->bits.classbits, 0, 32);
2164
+ }
2165
+ break;
2166
+
2167
+ case META_CLASS:
2168
+ case META_CLASS_NOT:
2169
+ if ((*ptr & CLASS_IS_ECLASS) != 0)
2170
+ {
2171
+ if (!compile_eclass_nested(context, negated, &ptr, &code,
2172
+ pop_info, lengthptr))
2173
+ return FALSE;
2174
+
2175
+ PCRE2_ASSERT(*ptr == META_CLASS_END);
2176
+ ptr++;
2177
+ goto DONE;
2178
+ }
2179
+
2180
+ ptr++;
2181
+ PCRE2_FALLTHROUGH /* Fall through */
2182
+
2183
+ default:
2184
+ /* Scan forward characters, ranges, and properties.
2185
+ For example: inside [a-z_ -- m] we don't have brackets around "a-z_" but
2186
+ we still need to collect that fragment up into a "leaf" OP_CLASS. */
2187
+
2188
+ prev_ptr = ptr;
2189
+ ptr = PRIV(compile_class_not_nested)(
2190
+ context->options, context->xoptions, ptr, &code,
2191
+ (meta != META_CLASS_NOT) == negated, &context->needs_bitmap,
2192
+ context->errorcodeptr, context->cb, lengthptr);
2193
+ if (ptr == NULL) return FALSE;
2194
+
2195
+ /* We must have a 100% guarantee that ptr increases when
2196
+ compile_class_operand() returns, even on Release builds, so that we can
2197
+ statically prove our loops terminate. */
2198
+ /* LCOV_EXCL_START */
2199
+ if (ptr <= prev_ptr)
2200
+ {
2201
+ PCRE2_DEBUG_UNREACHABLE();
2202
+ return FALSE;
2203
+ }
2204
+ /* LCOV_EXCL_STOP */
2205
+
2206
+ /* If we fell through above, consume the closing ']'. */
2207
+ if (meta == META_CLASS || meta == META_CLASS_NOT)
2208
+ {
2209
+ PCRE2_ASSERT(*ptr == META_CLASS_END);
2210
+ ptr++;
2211
+ }
2212
+
2213
+ /* Regardless of whether (lengthptr == NULL), some data will still be written
2214
+ out to *pcode, which we need: we have to peek at it, to transform the opcode
2215
+ into the ECLASS version (since we need to hoist up the bitmaps). */
2216
+ PCRE2_ASSERT(code > code_start);
2217
+ extra_length = (lengthptr != NULL)? *lengthptr - prev_length : 0;
2218
+
2219
+ /* Easiest case: convert OP_ALLANY to ECL_ANY */
2220
+
2221
+ if (*code_start == OP_ALLANY)
2222
+ {
2223
+ PCRE2_ASSERT(code - code_start == 1 && extra_length == 0);
2224
+ pop_info->length = 1;
2225
+ *code_start = pop_info->op_single_type = ECL_ANY;
2226
+ memset(pop_info->bits.classbits, 0xff, 32);
2227
+ }
2228
+
2229
+ /* For OP_CLASS and OP_NCLASS, we hoist out the bitmap and convert to
2230
+ ECL_NONE / ECL_ANY respectively. */
2231
+
2232
+ else if (*code_start == OP_CLASS || *code_start == OP_NCLASS)
2233
+ {
2234
+ PCRE2_ASSERT(code - code_start == 1 + 32 / sizeof(PCRE2_UCHAR) &&
2235
+ extra_length == 0);
2236
+ pop_info->length = 1;
2237
+ *code_start = pop_info->op_single_type =
2238
+ (*code_start == OP_CLASS)? ECL_NONE : ECL_ANY;
2239
+ memcpy(pop_info->bits.classbits, code_start + 1, 32);
2240
+ /* Rewind the code pointer, but make sure we adjust *lengthptr, because we
2241
+ do need to reserve that space (even though we only use it temporarily). */
2242
+ if (lengthptr != NULL)
2243
+ *lengthptr += code - (code_start + 1);
2244
+ code = code_start + 1;
2245
+
2246
+ if (!context->needs_bitmap && *code_start == ECL_NONE)
2247
+ {
2248
+ uint32_t *classwords = pop_info->bits.classwords;
2249
+
2250
+ for (i = 0; i < 8; i++)
2251
+ if (classwords[i] != 0)
2252
+ {
2253
+ context->needs_bitmap = TRUE;
2254
+ break;
2255
+ }
2256
+ }
2257
+ else
2258
+ context->needs_bitmap = TRUE;
2259
+ }
2260
+
2261
+ /* Finally, for OP_XCLASS we hoist out the bitmap (if any), and convert to
2262
+ ECL_XCLASS. */
2263
+
2264
+ else
2265
+ {
2266
+ PCRE2_ASSERT(*code_start == OP_XCLASS);
2267
+ *code_start = pop_info->op_single_type = ECL_XCLASS;
2268
+
2269
+ PCRE2_ASSERT(code - code_start >= 1 + LINK_SIZE + 1);
2270
+
2271
+ memcpy(pop_info->bits.classbits, context->cb->classbits.classbits, 32);
2272
+ pop_info->length = (code - code_start) + extra_length;
2273
+ }
2274
+
2275
+ break;
2276
+ } /* End of switch(meta) */
2277
+
2278
+ pop_info->code_start = (lengthptr == NULL)? code_start : NULL;
2279
+
2280
+ if (lengthptr != NULL)
2281
+ {
2282
+ *lengthptr += code - code_start;
2283
+ code = code_start;
2284
+ }
2285
+
2286
+ DONE:
2287
+ PCRE2_ASSERT(lengthptr == NULL || (code == code_start));
2288
+
2289
+ *pptr = ptr;
2290
+ *pcode = code;
2291
+ return TRUE;
2292
+ }
2293
+
2294
+
2295
+
2296
+ /* This function consumes a group of implicitly-unioned class elements.
2297
+ These can be characters, ranges, properties, or nested classes, as long
2298
+ as they are all joined by being placed adjacently. */
2299
+
2300
+ static BOOL
2301
+ compile_class_juxtaposition(eclass_context *context, BOOL negated,
2302
+ uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info,
2303
+ PCRE2_SIZE *lengthptr)
2304
+ {
2305
+ uint32_t *ptr = *pptr;
2306
+ PCRE2_UCHAR *code = *pcode;
2307
+ #ifdef PCRE2_DEBUG
2308
+ PCRE2_UCHAR *start_code = *pcode;
2309
+ #endif
2310
+
2311
+ /* See compile_class_binary_loose() for comments on compile-time folding of
2312
+ the "negated" flag. */
2313
+
2314
+ /* Because it's a non-empty class, there must be an operand at the start. */
2315
+ if (!compile_class_operand(context, negated, &ptr, &code, pop_info, lengthptr))
2316
+ return FALSE;
2317
+
2318
+ while (*ptr != META_CLASS_END &&
2319
+ !(*ptr >= META_ECLASS_AND && *ptr <= META_ECLASS_NOT))
2320
+ {
2321
+ uint32_t op;
2322
+ BOOL rhs_negated;
2323
+ eclass_op_info rhs_op_info;
2324
+
2325
+ if (negated)
2326
+ {
2327
+ /* !(A juxtapose B) -> !A && !B */
2328
+ op = ECL_AND;
2329
+ rhs_negated = TRUE;
2330
+ }
2331
+ else
2332
+ {
2333
+ /* A juxtapose B -> A || B */
2334
+ op = ECL_OR;
2335
+ rhs_negated = FALSE;
2336
+ }
2337
+
2338
+ /* An operand must follow the operator. */
2339
+ if (!compile_class_operand(context, rhs_negated, &ptr, &code,
2340
+ &rhs_op_info, lengthptr))
2341
+ return FALSE;
2342
+
2343
+ /* Convert infix to postfix (RPN). */
2344
+ fold_binary(op, pop_info, &rhs_op_info, lengthptr);
2345
+ if (lengthptr == NULL)
2346
+ code = pop_info->code_start + pop_info->length;
2347
+ }
2348
+
2349
+ PCRE2_ASSERT(lengthptr == NULL || code == start_code);
2350
+
2351
+ *pptr = ptr;
2352
+ *pcode = code;
2353
+ return TRUE;
2354
+ }
2355
+
2356
+
2357
+
2358
+ /* This function consumes unary prefix operators. */
2359
+
2360
+ static BOOL
2361
+ compile_class_unary(eclass_context *context, BOOL negated,
2362
+ uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info,
2363
+ PCRE2_SIZE *lengthptr)
2364
+ {
2365
+ uint32_t *ptr = *pptr;
2366
+ #ifdef PCRE2_DEBUG
2367
+ PCRE2_UCHAR *start_code = *pcode;
2368
+ #endif
2369
+
2370
+ while (*ptr == META_ECLASS_NOT)
2371
+ {
2372
+ ++ptr;
2373
+ negated = !negated;
2374
+ }
2375
+
2376
+ *pptr = ptr;
2377
+ /* Because it's a non-empty class, there must be an operand. */
2378
+ if (!compile_class_juxtaposition(context, negated, pptr, pcode,
2379
+ pop_info, lengthptr))
2380
+ return FALSE;
2381
+
2382
+ PCRE2_ASSERT(lengthptr == NULL || *pcode == start_code);
2383
+ return TRUE;
2384
+ }
2385
+
2386
+
2387
+
2388
+ /* This function consumes tightly-binding binary operators. */
2389
+
2390
+ static BOOL
2391
+ compile_class_binary_tight(eclass_context *context, BOOL negated,
2392
+ uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info,
2393
+ PCRE2_SIZE *lengthptr)
2394
+ {
2395
+ uint32_t *ptr = *pptr;
2396
+ PCRE2_UCHAR *code = *pcode;
2397
+ #ifdef PCRE2_DEBUG
2398
+ PCRE2_UCHAR *start_code = *pcode;
2399
+ #endif
2400
+
2401
+ /* See compile_class_binary_loose() for comments on compile-time folding of
2402
+ the "negated" flag. */
2403
+
2404
+ /* Because it's a non-empty class, there must be an operand at the start. */
2405
+ if (!compile_class_unary(context, negated, &ptr, &code, pop_info, lengthptr))
2406
+ return FALSE;
2407
+
2408
+ while (*ptr == META_ECLASS_AND)
2409
+ {
2410
+ uint32_t op;
2411
+ BOOL rhs_negated;
2412
+ eclass_op_info rhs_op_info;
2413
+
2414
+ if (negated)
2415
+ {
2416
+ /* !(A && B) -> !A || !B */
2417
+ op = ECL_OR;
2418
+ rhs_negated = TRUE;
2419
+ }
2420
+ else
2421
+ {
2422
+ /* A && B -> A && B */
2423
+ op = ECL_AND;
2424
+ rhs_negated = FALSE;
2425
+ }
2426
+
2427
+ ++ptr;
2428
+
2429
+ /* An operand must follow the operator. */
2430
+ if (!compile_class_unary(context, rhs_negated, &ptr, &code,
2431
+ &rhs_op_info, lengthptr))
2432
+ return FALSE;
2433
+
2434
+ /* Convert infix to postfix (RPN). */
2435
+ fold_binary(op, pop_info, &rhs_op_info, lengthptr);
2436
+ if (lengthptr == NULL)
2437
+ code = pop_info->code_start + pop_info->length;
2438
+ }
2439
+
2440
+ PCRE2_ASSERT(lengthptr == NULL || code == start_code);
2441
+
2442
+ *pptr = ptr;
2443
+ *pcode = code;
2444
+ return TRUE;
2445
+ }
2446
+
2447
+
2448
+
2449
+ /* This function consumes loosely-binding binary operators. */
2450
+
2451
+ static BOOL
2452
+ compile_class_binary_loose(eclass_context *context, BOOL negated,
2453
+ uint32_t **pptr, PCRE2_UCHAR **pcode, eclass_op_info *pop_info,
2454
+ PCRE2_SIZE *lengthptr)
2455
+ {
2456
+ uint32_t *ptr = *pptr;
2457
+ PCRE2_UCHAR *code = *pcode;
2458
+ #ifdef PCRE2_DEBUG
2459
+ PCRE2_UCHAR *start_code = *pcode;
2460
+ #endif
2461
+
2462
+ /* We really want to fold the negation operator, if at all possible, so that
2463
+ simple cases can be reduced down. In particular, in 8-bit no-UTF mode, we want
2464
+ to produce a fully-folded expression, so that we can guarantee not to emit any
2465
+ OP_ECLASS codes (in the same way that we never emit OP_XCLASS in this mode).
2466
+
2467
+ This has the consequence that with a little ingenuity, we can in fact avoid
2468
+ emitting (nearly...) all cases of the "NOT" operator. Imagine that we have:
2469
+ !(A ...
2470
+ We have parsed the preceding "!", and we are about to parse the "A" operand. We
2471
+ don't know yet whether there will even be a following binary operand! Both of
2472
+ these are possibilities for what follows:
2473
+ !(A && B)
2474
+ !(A)
2475
+ However, we can still fold the "!" into the "A" operand, because no matter what
2476
+ the following binary operator will be, we can produce an expression which is
2477
+ equivalent. */
2478
+
2479
+ /* Because it's a non-empty class, there must be an operand at the start. */
2480
+ if (!compile_class_binary_tight(context, negated, &ptr, &code,
2481
+ pop_info, lengthptr))
2482
+ return FALSE;
2483
+
2484
+ while (*ptr >= META_ECLASS_OR && *ptr <= META_ECLASS_XOR)
2485
+ {
2486
+ uint32_t op;
2487
+ BOOL op_neg;
2488
+ BOOL rhs_negated;
2489
+ eclass_op_info rhs_op_info;
2490
+
2491
+ if (negated)
2492
+ {
2493
+ /* The whole expression is being negated; we respond by unconditionally
2494
+ negating the LHS A, before seeing what follows. And hooray! We can recover,
2495
+ no matter what follows. */
2496
+ /* !(A || B) -> !A && !B */
2497
+ /* !(A -- B) -> !(A && !B) -> !A || B */
2498
+ /* !(A XOR B) -> !(!A XOR !B) -> !A XNOR !B */
2499
+ op = (*ptr == META_ECLASS_OR )? ECL_AND :
2500
+ (*ptr == META_ECLASS_SUB)? ECL_OR :
2501
+ /*ptr == META_ECLASS_XOR*/ ECL_XOR;
2502
+ op_neg = (*ptr == META_ECLASS_XOR);
2503
+ rhs_negated = *ptr != META_ECLASS_SUB;
2504
+ }
2505
+ else
2506
+ {
2507
+ /* A || B -> A || B */
2508
+ /* A -- B -> A && !B */
2509
+ /* A XOR B -> A XOR B */
2510
+ op = (*ptr == META_ECLASS_OR )? ECL_OR :
2511
+ (*ptr == META_ECLASS_SUB)? ECL_AND :
2512
+ /*ptr == META_ECLASS_XOR*/ ECL_XOR;
2513
+ op_neg = FALSE;
2514
+ rhs_negated = *ptr == META_ECLASS_SUB;
2515
+ }
2516
+
2517
+ ++ptr;
2518
+
2519
+ /* An operand must follow the operator. */
2520
+ if (!compile_class_binary_tight(context, rhs_negated, &ptr, &code,
2521
+ &rhs_op_info, lengthptr))
2522
+ return FALSE;
2523
+
2524
+ /* Convert infix to postfix (RPN). */
2525
+ fold_binary(op, pop_info, &rhs_op_info, lengthptr);
2526
+ if (op_neg) fold_negation(pop_info, lengthptr, FALSE);
2527
+ if (lengthptr == NULL)
2528
+ code = pop_info->code_start + pop_info->length;
2529
+ }
2530
+
2531
+ PCRE2_ASSERT(lengthptr == NULL || code == start_code);
2532
+
2533
+ *pptr = ptr;
2534
+ *pcode = code;
2535
+ return TRUE;
2536
+ }
2537
+
2538
+
2539
+
2540
+ /* This function converts the META codes in pptr into opcodes written to
2541
+ pcode. The pptr must start at a META_CLASS or META_CLASS_NOT.
2542
+
2543
+ The class is compiled as a left-associative sequence of operator
2544
+ applications.
2545
+
2546
+ The pptr will be left pointing at the matching META_CLASS_END. */
2547
+
2548
+ static BOOL
2549
+ compile_eclass_nested(eclass_context *context, BOOL negated,
2550
+ uint32_t **pptr, PCRE2_UCHAR **pcode,
2551
+ eclass_op_info *pop_info, PCRE2_SIZE *lengthptr)
2552
+ {
2553
+ uint32_t *ptr = *pptr;
2554
+ #ifdef PCRE2_DEBUG
2555
+ PCRE2_UCHAR *start_code = *pcode;
2556
+ #endif
2557
+
2558
+ /* The CLASS_IS_ECLASS bit must be set since it is a nested class. */
2559
+ PCRE2_ASSERT(*ptr == (META_CLASS | CLASS_IS_ECLASS) ||
2560
+ *ptr == (META_CLASS_NOT | CLASS_IS_ECLASS));
2561
+
2562
+ if (*ptr++ == (META_CLASS_NOT | CLASS_IS_ECLASS))
2563
+ negated = !negated;
2564
+
2565
+ (*pptr)++;
2566
+
2567
+ /* Because it's a non-empty class, there must be an operand at the start. */
2568
+ if (!compile_class_binary_loose(context, negated, pptr, pcode,
2569
+ pop_info, lengthptr))
2570
+ return FALSE;
2571
+
2572
+ PCRE2_ASSERT(**pptr == META_CLASS_END);
2573
+ PCRE2_ASSERT(lengthptr == NULL || *pcode == start_code);
2574
+ return TRUE;
2575
+ }
2576
+
2577
+ BOOL
2578
+ PRIV(compile_class_nested)(uint32_t options, uint32_t xoptions,
2579
+ uint32_t **pptr, PCRE2_UCHAR **pcode, int *errorcodeptr,
2580
+ compile_block *cb, PCRE2_SIZE *lengthptr)
2581
+ {
2582
+ eclass_context context;
2583
+ eclass_op_info op_info;
2584
+ PCRE2_SIZE previous_length = (lengthptr != NULL)? *lengthptr : 0;
2585
+ PCRE2_UCHAR *code = *pcode;
2586
+ PCRE2_UCHAR *previous;
2587
+ BOOL allbitsone = TRUE;
2588
+ int i;
2589
+
2590
+ context.needs_bitmap = FALSE;
2591
+ context.options = options;
2592
+ context.xoptions = xoptions;
2593
+ context.errorcodeptr = errorcodeptr;
2594
+ context.cb = cb;
2595
+
2596
+ previous = code;
2597
+ *code++ = OP_ECLASS;
2598
+ code += LINK_SIZE;
2599
+ *code++ = 0; /* Flags, currently zero. */
2600
+ if (!compile_eclass_nested(&context, FALSE, pptr, &code, &op_info, lengthptr))
2601
+ return FALSE;
2602
+
2603
+ if (lengthptr != NULL)
2604
+ {
2605
+ *lengthptr += code - previous;
2606
+ code = previous;
2607
+ /* (*lengthptr - previous_length) now holds the amount of buffer that
2608
+ we require to make the call to compile_class_nested() with
2609
+ lengthptr = NULL, and including the (1+LINK_SIZE+1) that we write out
2610
+ before that call. */
2611
+ }
2612
+
2613
+ /* Do some useful counting of what's in the bitmap. */
2614
+ for (i = 0; i < 8; i++)
2615
+ if (op_info.bits.classwords[i] != 0xffffffff)
2616
+ {
2617
+ allbitsone = FALSE;
2618
+ break;
2619
+ }
2620
+
2621
+ /* After constant-folding the extended class syntax, it may turn out to be
2622
+ a simple class after all. In that case, we can unwrap it from the
2623
+ OP_ECLASS container - and in fact, we must do so, because in 8-bit
2624
+ no-Unicode mode the matcher is compiled without support for OP_ECLASS. */
2625
+
2626
+ #ifndef SUPPORT_WIDE_CHARS
2627
+ PCRE2_ASSERT(op_info.op_single_type != 0);
2628
+ #else
2629
+ if (op_info.op_single_type != 0)
2630
+ #endif
2631
+ {
2632
+ /* Rewind back over the OP_ECLASS. */
2633
+ code = previous;
2634
+
2635
+ /* If the bits are all ones, and the "high characters" are all matched
2636
+ too, we use a special-cased encoding of OP_ALLANY. */
2637
+
2638
+ if (op_info.op_single_type == ECL_ANY && allbitsone)
2639
+ {
2640
+ /* Advancing code means rewinding lengthptr, at this point. */
2641
+ if (lengthptr != NULL) *lengthptr -= 1;
2642
+ *code++ = OP_ALLANY;
2643
+ }
2644
+
2645
+ /* If the high bits are all matched / all not-matched, then we emit an
2646
+ OP_NCLASS/OP_CLASS respectively. */
2647
+
2648
+ else if (op_info.op_single_type == ECL_ANY ||
2649
+ op_info.op_single_type == ECL_NONE)
2650
+ {
2651
+ PCRE2_SIZE required_len = 1 + (32 / sizeof(PCRE2_UCHAR));
2652
+
2653
+ if (lengthptr != NULL)
2654
+ {
2655
+ if (required_len > (*lengthptr - previous_length))
2656
+ *lengthptr = previous_length + required_len;
2657
+ }
2658
+
2659
+ /* Advancing code means rewinding lengthptr, at this point. */
2660
+ if (lengthptr != NULL) *lengthptr -= required_len;
2661
+ *code++ = (op_info.op_single_type == ECL_ANY)? OP_NCLASS : OP_CLASS;
2662
+ memcpy(code, op_info.bits.classbits, 32);
2663
+ code += 32 / sizeof(PCRE2_UCHAR);
2664
+ }
2665
+
2666
+ /* Otherwise, we have an ECL_XCLASS, so we have the OP_XCLASS data
2667
+ there, but, we pulled out its bitmap into op_info, so now we have to
2668
+ put that back into the OP_XCLASS. */
2669
+
2670
+ else
2671
+ {
2672
+ #ifndef SUPPORT_WIDE_CHARS
2673
+ PCRE2_DEBUG_UNREACHABLE();
2674
+ #else
2675
+ BOOL need_map = context.needs_bitmap;
2676
+ PCRE2_SIZE required_len;
2677
+
2678
+ PCRE2_ASSERT(op_info.op_single_type == ECL_XCLASS);
2679
+ required_len = op_info.length + (need_map? 32/sizeof(PCRE2_UCHAR) : 0);
2680
+
2681
+ if (lengthptr != NULL)
2682
+ {
2683
+ /* Don't unconditionally request all the space we need - we may
2684
+ already have asked for more during processing of the ECLASS. */
2685
+ if (required_len > (*lengthptr - previous_length))
2686
+ *lengthptr = previous_length + required_len;
2687
+
2688
+ /* The code we write out here won't be ignored, even during the
2689
+ (lengthptr != NULL) phase, because if there's a following quantifier
2690
+ it will peek backwards. So we do have to write out a (truncated)
2691
+ OP_XCLASS, even on this branch. */
2692
+ *lengthptr -= 1 + LINK_SIZE + 1;
2693
+ *code++ = OP_XCLASS;
2694
+ PUT(code, 0, 1 + LINK_SIZE + 1);
2695
+ code += LINK_SIZE;
2696
+ *code++ = 0;
2697
+ }
2698
+ else
2699
+ {
2700
+ PCRE2_UCHAR *rest;
2701
+ PCRE2_SIZE rest_len;
2702
+ PCRE2_UCHAR flags;
2703
+
2704
+ /* 1 unit: OP_XCLASS | LINK_SIZE units | 1 unit: flags | ...rest */
2705
+ PCRE2_ASSERT(op_info.length >= 1 + LINK_SIZE + 1);
2706
+ rest = op_info.code_start + 1 + LINK_SIZE + 1;
2707
+ rest_len = (op_info.code_start + op_info.length) - rest;
2708
+
2709
+ /* First read any data we use, before memmove splats it. */
2710
+ flags = op_info.code_start[1 + LINK_SIZE];
2711
+ PCRE2_ASSERT((flags & XCL_MAP) == 0);
2712
+
2713
+ /* Next do the memmove before any writes. */
2714
+ memmove(code + 1 + LINK_SIZE + 1 + (need_map? 32/sizeof(PCRE2_UCHAR) : 0),
2715
+ rest, CU2BYTES(rest_len));
2716
+
2717
+ /* Finally write the header data. */
2718
+ *code++ = OP_XCLASS;
2719
+ PUT(code, 0, (int)required_len);
2720
+ code += LINK_SIZE;
2721
+ *code++ = flags | (need_map? XCL_MAP : 0);
2722
+ if (need_map)
2723
+ {
2724
+ memcpy(code, op_info.bits.classbits, 32);
2725
+ code += 32 / sizeof(PCRE2_UCHAR);
2726
+ }
2727
+ code += rest_len;
2728
+ }
2729
+ #endif /* SUPPORT_WIDE_CHARS */
2730
+ }
2731
+ }
2732
+
2733
+ /* Otherwise, we're going to keep the OP_ECLASS. However, again we need
2734
+ to do some adjustment to insert the bitmap if we have one. */
2735
+
2736
+ #ifdef SUPPORT_WIDE_CHARS
2737
+ else
2738
+ {
2739
+ BOOL need_map = context.needs_bitmap;
2740
+ PCRE2_SIZE required_len =
2741
+ 1 + LINK_SIZE + 1 + (need_map? 32/sizeof(PCRE2_UCHAR) : 0) + op_info.length;
2742
+
2743
+ if (lengthptr != NULL)
2744
+ {
2745
+ if (required_len > (*lengthptr - previous_length))
2746
+ *lengthptr = previous_length + required_len;
2747
+
2748
+ /* As for the XCLASS branch above, we do have to write out a dummy
2749
+ OP_ECLASS, because of the backwards peek by the quantifier code. Write
2750
+ out a (truncated) OP_ECLASS, even on this branch. */
2751
+ *lengthptr -= 1 + LINK_SIZE + 1;
2752
+ *code++ = OP_ECLASS;
2753
+ PUT(code, 0, 1 + LINK_SIZE + 1);
2754
+ code += LINK_SIZE;
2755
+ *code++ = 0;
2756
+ }
2757
+ else
2758
+ {
2759
+ if (need_map)
2760
+ {
2761
+ PCRE2_UCHAR *map_start = previous + 1 + LINK_SIZE + 1;
2762
+ previous[1 + LINK_SIZE] |= ECL_MAP;
2763
+ memmove(map_start + 32/sizeof(PCRE2_UCHAR), map_start,
2764
+ CU2BYTES(code - map_start));
2765
+ memcpy(map_start, op_info.bits.classbits, 32);
2766
+ code += 32 / sizeof(PCRE2_UCHAR);
2767
+ }
2768
+ PUT(previous, 1, (int)(code - previous));
2769
+ }
2770
+ }
2771
+ #endif /* SUPPORT_WIDE_CHARS */
2772
+
2773
+ *pcode = code;
2774
+ return TRUE;
2775
+ }
2776
+
2777
+ /* End of pcre2_compile_class.c */