re2 1.19.2 → 1.20.0

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 (151) hide show
  1. package/.github/actions/linux-alpine-node-16/Dockerfile +1 -1
  2. package/.github/actions/linux-alpine-node-18/Dockerfile +1 -1
  3. package/.github/actions/linux-alpine-node-20/Dockerfile +1 -1
  4. package/.gitmodules +5 -2
  5. package/README.md +1 -0
  6. package/binding.gyp +82 -25
  7. package/lib/replace.cc +4 -4
  8. package/package.json +1 -1
  9. package/tsconfig.json +2 -1
  10. package/vendor/re2/.bazelrc +16 -0
  11. package/vendor/re2/.github/bazel.sh +24 -0
  12. package/vendor/re2/.github/cmake.sh +12 -0
  13. package/vendor/re2/.github/workflows/ci-bazel.yml +17 -0
  14. package/vendor/re2/.github/workflows/ci-cmake.yml +108 -0
  15. package/vendor/re2/.github/workflows/ci.yml +89 -0
  16. package/vendor/re2/.github/workflows/pr.yml +26 -0
  17. package/vendor/re2/.github/workflows/python.yml +185 -0
  18. package/vendor/re2/AUTHORS +13 -0
  19. package/vendor/re2/BUILD.bazel +280 -0
  20. package/vendor/re2/CMakeLists.txt +268 -0
  21. package/vendor/re2/CONTRIBUTING.md +2 -0
  22. package/vendor/re2/CONTRIBUTORS +41 -0
  23. package/vendor/re2/Makefile +400 -0
  24. package/vendor/{README → re2/README} +5 -0
  25. package/vendor/re2/SECURITY.md +4 -0
  26. package/vendor/re2/WORKSPACE.bazel +62 -0
  27. package/vendor/re2/app/BUILD.bazel +19 -0
  28. package/vendor/re2/app/_re2.cc +94 -0
  29. package/vendor/re2/app/_re2.d.ts +23 -0
  30. package/vendor/re2/app/app.ts +111 -0
  31. package/vendor/re2/app/build.sh +50 -0
  32. package/vendor/re2/app/index.html +5 -0
  33. package/vendor/re2/app/package.json +14 -0
  34. package/vendor/re2/app/rollup.config.js +28 -0
  35. package/vendor/re2/app/tsconfig.json +17 -0
  36. package/vendor/re2/benchlog/benchplot.py +98 -0
  37. package/vendor/re2/benchlog/mktable +155 -0
  38. package/vendor/re2/doc/mksyntaxgo +42 -0
  39. package/vendor/re2/doc/mksyntaxhtml +42 -0
  40. package/vendor/re2/doc/mksyntaxwiki +36 -0
  41. package/vendor/re2/doc/syntax.html +477 -0
  42. package/vendor/re2/doc/syntax.txt +463 -0
  43. package/vendor/re2/lib/git/commit-msg.hook +104 -0
  44. package/vendor/re2/libre2.symbols +19 -0
  45. package/vendor/re2/libre2.symbols.darwin +15 -0
  46. package/vendor/re2/python/BUILD.bazel +36 -0
  47. package/vendor/re2/python/README +1 -0
  48. package/vendor/re2/python/_re2.cc +338 -0
  49. package/vendor/re2/python/re2.py +582 -0
  50. package/vendor/re2/python/re2_test.py +482 -0
  51. package/vendor/re2/python/setup.py +105 -0
  52. package/vendor/re2/{bitmap256.cc → re2/bitmap256.cc} +4 -4
  53. package/vendor/re2/{bitstate.cc → re2/bitstate.cc} +21 -25
  54. package/vendor/re2/{compile.cc → re2/compile.cc} +5 -4
  55. package/vendor/re2/{dfa.cc → re2/dfa.cc} +120 -101
  56. package/vendor/re2/{filtered_re2.cc → re2/filtered_re2.cc} +8 -11
  57. package/vendor/re2/{filtered_re2.h → re2/filtered_re2.h} +5 -4
  58. package/vendor/re2/{fuzzing → re2/fuzzing}/re2_fuzzer.cc +4 -6
  59. package/vendor/re2/{mimics_pcre.cc → re2/mimics_pcre.cc} +0 -1
  60. package/vendor/re2/{nfa.cc → re2/nfa.cc} +34 -37
  61. package/vendor/re2/{onepass.cc → re2/onepass.cc} +25 -27
  62. package/vendor/re2/{parse.cc → re2/parse.cc} +118 -121
  63. package/vendor/re2/{prefilter.cc → re2/prefilter.cc} +2 -3
  64. package/vendor/re2/{prefilter.h → re2/prefilter.h} +0 -1
  65. package/vendor/re2/{prefilter_tree.cc → re2/prefilter_tree.cc} +4 -5
  66. package/vendor/re2/{prefilter_tree.h → re2/prefilter_tree.h} +1 -2
  67. package/vendor/re2/{prog.cc → re2/prog.cc} +20 -21
  68. package/vendor/re2/{prog.h → re2/prog.h} +21 -22
  69. package/vendor/re2/{re2.cc → re2/re2.cc} +51 -62
  70. package/vendor/re2/{re2.h → re2/re2.h} +78 -40
  71. package/vendor/re2/{regexp.cc → re2/regexp.cc} +11 -12
  72. package/vendor/re2/{regexp.h → re2/regexp.h} +9 -10
  73. package/vendor/re2/{set.cc → re2/set.cc} +3 -5
  74. package/vendor/re2/{set.h → re2/set.h} +4 -3
  75. package/vendor/re2/{simplify.cc → re2/simplify.cc} +1 -2
  76. package/vendor/re2/re2/stringpiece.h +24 -0
  77. package/vendor/re2/{testing → re2/testing}/backtrack.cc +22 -25
  78. package/vendor/re2/{testing → re2/testing}/charclass_test.cc +23 -21
  79. package/vendor/re2/{testing → re2/testing}/compile_test.cc +5 -4
  80. package/vendor/re2/{testing → re2/testing}/dfa_test.cc +36 -30
  81. package/vendor/re2/{testing → re2/testing}/dump.cc +8 -8
  82. package/vendor/re2/{testing → re2/testing}/exhaustive1_test.cc +1 -1
  83. package/vendor/re2/{testing → re2/testing}/exhaustive2_test.cc +1 -1
  84. package/vendor/re2/{testing → re2/testing}/exhaustive3_test.cc +1 -1
  85. package/vendor/re2/{testing → re2/testing}/exhaustive_test.cc +1 -1
  86. package/vendor/re2/{testing → re2/testing}/exhaustive_tester.cc +36 -32
  87. package/vendor/re2/{testing → re2/testing}/exhaustive_tester.h +0 -1
  88. package/vendor/re2/{testing → re2/testing}/filtered_re2_test.cc +9 -8
  89. package/vendor/re2/{testing → re2/testing}/mimics_pcre_test.cc +3 -2
  90. package/vendor/re2/{testing → re2/testing}/null_walker.cc +1 -1
  91. package/vendor/re2/{testing → re2/testing}/parse_test.cc +13 -12
  92. package/vendor/re2/{testing → re2/testing}/possible_match_test.cc +15 -14
  93. package/vendor/re2/{testing → re2/testing}/random_test.cc +13 -12
  94. package/vendor/re2/{testing → re2/testing}/re2_arg_test.cc +25 -2
  95. package/vendor/re2/{testing → re2/testing}/re2_test.cc +49 -47
  96. package/vendor/re2/{testing → re2/testing}/regexp_benchmark.cc +144 -145
  97. package/vendor/re2/{testing → re2/testing}/regexp_generator.cc +18 -14
  98. package/vendor/re2/{testing → re2/testing}/regexp_generator.h +3 -4
  99. package/vendor/re2/{testing → re2/testing}/regexp_test.cc +1 -1
  100. package/vendor/re2/{testing → re2/testing}/required_prefix_test.cc +5 -4
  101. package/vendor/re2/{testing → re2/testing}/search_test.cc +3 -2
  102. package/vendor/re2/{testing → re2/testing}/set_test.cc +1 -1
  103. package/vendor/re2/{testing → re2/testing}/simplify_test.cc +3 -2
  104. package/vendor/re2/{testing → re2/testing}/string_generator.cc +3 -3
  105. package/vendor/re2/{testing → re2/testing}/string_generator.h +5 -6
  106. package/vendor/re2/{testing → re2/testing}/string_generator_test.cc +2 -2
  107. package/vendor/re2/{testing → re2/testing}/tester.cc +77 -78
  108. package/vendor/re2/{testing → re2/testing}/tester.h +13 -15
  109. package/vendor/re2/{tostring.cc → re2/tostring.cc} +7 -8
  110. package/vendor/re2/{unicode_casefold.h → re2/unicode_casefold.h} +0 -1
  111. package/vendor/re2/{unicode_groups.h → re2/unicode_groups.h} +0 -1
  112. package/vendor/re2/{walker-inl.h → re2/walker-inl.h} +2 -1
  113. package/vendor/re2/re2.pc.in +9 -0
  114. package/vendor/re2/re2Config.cmake.in +28 -0
  115. package/vendor/re2/runtests +33 -0
  116. package/vendor/re2/testinstall.cc +27 -0
  117. package/vendor/re2/ucs2.diff +567 -0
  118. package/vendor/{util → re2/util}/logging.h +2 -2
  119. package/vendor/{util → re2/util}/pcre.cc +47 -116
  120. package/vendor/{util → re2/util}/pcre.h +53 -63
  121. package/vendor/re2/util/strutil.cc +26 -0
  122. package/vendor/{util → re2/util}/strutil.h +0 -5
  123. package/vendor/re2/stringpiece.cc +0 -65
  124. package/vendor/re2/stringpiece.h +0 -213
  125. package/vendor/util/benchmark.cc +0 -131
  126. package/vendor/util/benchmark.h +0 -156
  127. package/vendor/util/flags.h +0 -26
  128. package/vendor/util/mix.h +0 -41
  129. package/vendor/util/mutex.h +0 -164
  130. package/vendor/util/strutil.cc +0 -149
  131. package/vendor/util/test.cc +0 -34
  132. package/vendor/util/test.h +0 -50
  133. package/vendor/util/util.h +0 -42
  134. /package/vendor/{LICENSE → re2/LICENSE} +0 -0
  135. /package/vendor/re2/{bitmap256.h → re2/bitmap256.h} +0 -0
  136. /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/LICENSE +0 -0
  137. /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/include/fuzzer/FuzzedDataProvider.h +0 -0
  138. /package/vendor/re2/{make_perl_groups.pl → re2/make_perl_groups.pl} +0 -0
  139. /package/vendor/re2/{make_unicode_casefold.py → re2/make_unicode_casefold.py} +0 -0
  140. /package/vendor/re2/{make_unicode_groups.py → re2/make_unicode_groups.py} +0 -0
  141. /package/vendor/re2/{perl_groups.cc → re2/perl_groups.cc} +0 -0
  142. /package/vendor/re2/{pod_array.h → re2/pod_array.h} +0 -0
  143. /package/vendor/re2/{sparse_array.h → re2/sparse_array.h} +0 -0
  144. /package/vendor/re2/{sparse_set.h → re2/sparse_set.h} +0 -0
  145. /package/vendor/re2/{unicode.py → re2/unicode.py} +0 -0
  146. /package/vendor/re2/{unicode_casefold.cc → re2/unicode_casefold.cc} +0 -0
  147. /package/vendor/re2/{unicode_groups.cc → re2/unicode_groups.cc} +0 -0
  148. /package/vendor/{util → re2/util}/fuzz.cc +0 -0
  149. /package/vendor/{util → re2/util}/malloc_counter.h +0 -0
  150. /package/vendor/{util → re2/util}/rune.cc +0 -0
  151. /package/vendor/{util → re2/util}/utf.h +0 -0
@@ -0,0 +1,567 @@
1
+ This is a dump from Google's source control system of the change
2
+ that removed UCS-2 support from RE2. As the explanation below
3
+ says, UCS-2 mode is fundamentally at odds with things like ^ and $,
4
+ so it never really worked very well. But if you are interested in using
5
+ it without those operators, it did work for that. It assumed that the
6
+ UCS-2 data was in the native host byte order.
7
+
8
+ If you are interested in adding UCS-2 mode back, this patch might
9
+ be a good starting point.
10
+
11
+
12
+ Change 12780686 by rsc@rsc-re2 on 2009/09/16 15:30:15
13
+
14
+ Retire UCS-2 mode.
15
+
16
+ I added it as an experiment for V8, but it
17
+ requires 2-byte lookahead to do completely,
18
+ and RE2 has 1-byte lookahead (enough for UTF-8)
19
+ as a fairly deep fundamental assumption,
20
+ so it did not support ^ or $.
21
+
22
+ ==== re2/bitstate.cc#2 - re2/bitstate.cc#3 ====
23
+ re2/bitstate.cc#2:314,321 - re2/bitstate.cc#3:314,319
24
+ cap_[0] = p;
25
+ if (TrySearch(prog_->start(), p)) // Match must be leftmost; done.
26
+ return true;
27
+ - if (prog_->flags() & Regexp::UCS2)
28
+ - p++;
29
+ }
30
+ return false;
31
+ }
32
+ ==== re2/compile.cc#17 - re2/compile.cc#18 ====
33
+ re2/compile.cc#17:95,101 - re2/compile.cc#18:95,100
34
+ // Input encodings.
35
+ enum Encoding {
36
+ kEncodingUTF8 = 1, // UTF-8 (0-10FFFF)
37
+ - kEncodingUCS2, // UCS-2 (0-FFFF), native byte order
38
+ kEncodingLatin1, // Latin1 (0-FF)
39
+ };
40
+
41
+ re2/compile.cc#17:168,176 - re2/compile.cc#18:167,172
42
+ void AddRuneRangeLatin1(Rune lo, Rune hi, bool foldcase);
43
+ void AddRuneRangeUTF8(Rune lo, Rune hi, bool foldcase);
44
+ void Add_80_10ffff();
45
+ - void AddRuneRangeUCS2(Rune lo, Rune hi, bool foldcase);
46
+ - void AddUCS2Pair(uint8 lo1, uint8 hi1, bool fold1,
47
+ - uint8 lo2, uint8 hi2, bool fold2);
48
+
49
+ // New suffix that matches the byte range lo-hi, then goes to next.
50
+ Inst* RuneByteSuffix(uint8 lo, uint8 hi, bool foldcase, Inst* next);
51
+ re2/compile.cc#17:475,481 - re2/compile.cc#18:471,477
52
+
53
+ // Converts rune range lo-hi into a fragment that recognizes
54
+ // the bytes that would make up those runes in the current
55
+ - // encoding (Latin 1, UTF-8, or UCS-2).
56
+ + // encoding (Latin 1 or UTF-8).
57
+ // This lets the machine work byte-by-byte even when
58
+ // using multibyte encodings.
59
+
60
+ re2/compile.cc#17:488,496 - re2/compile.cc#18:484,489
61
+ case kEncodingLatin1:
62
+ AddRuneRangeLatin1(lo, hi, foldcase);
63
+ break;
64
+ - case kEncodingUCS2:
65
+ - AddRuneRangeUCS2(lo, hi, foldcase);
66
+ - break;
67
+ }
68
+ }
69
+
70
+ re2/compile.cc#17:503,581 - re2/compile.cc#18:496,501
71
+ AddSuffix(RuneByteSuffix(lo, hi, foldcase, NULL));
72
+ }
73
+
74
+ - // Test whether 16-bit values are big or little endian.
75
+ - static bool BigEndian() {
76
+ - union {
77
+ - char byte[2];
78
+ - int16 endian;
79
+ - } u;
80
+ -
81
+ - u.byte[0] = 1;
82
+ - u.byte[1] = 2;
83
+ - return u.endian == 0x0102;
84
+ - }
85
+ -
86
+ - void Compiler::AddUCS2Pair(uint8 lo1, uint8 hi1, bool fold1,
87
+ - uint8 lo2, uint8 hi2, bool fold2) {
88
+ - Inst* ip;
89
+ - if (reversed_) {
90
+ - ip = RuneByteSuffix(lo1, hi1, fold1, NULL);
91
+ - ip = RuneByteSuffix(lo2, hi2, fold2, ip);
92
+ - } else {
93
+ - ip = RuneByteSuffix(lo2, hi2, fold2, NULL);
94
+ - ip = RuneByteSuffix(lo1, hi1, fold1, ip);
95
+ - }
96
+ - AddSuffix(ip);
97
+ - }
98
+ -
99
+ - void Compiler::AddRuneRangeUCS2(Rune lo, Rune hi, bool foldcase) {
100
+ - if (lo > hi || lo > 0xFFFF)
101
+ - return;
102
+ - if (hi > 0xFFFF)
103
+ - hi = 0xFFFF;
104
+ -
105
+ - // We'll assemble a pattern assuming big endian.
106
+ - // If the machine isn't, tell Cat to reverse its arguments.
107
+ - bool oldreversed = reversed_;
108
+ - if (!BigEndian()) {
109
+ - reversed_ = !oldreversed;
110
+ - }
111
+ -
112
+ - // Split into bytes.
113
+ - int lo1 = lo >> 8;
114
+ - int lo2 = lo & 0xFF;
115
+ - int hi1 = hi >> 8;
116
+ - int hi2 = hi & 0xFF;
117
+ -
118
+ - if (lo1 == hi1) {
119
+ - // Easy case: high bits are same in both.
120
+ - // Only do ASCII case folding on the second byte if the top byte is 00.
121
+ - AddUCS2Pair(lo1, lo1, false, lo2, hi2, lo1==0 && foldcase);
122
+ - } else {
123
+ - // Harder case: different second byte ranges depending on first byte.
124
+ -
125
+ - // Initial fragment.
126
+ - if (lo2 > 0) {
127
+ - AddUCS2Pair(lo1, lo1, false, lo2, 0xFF, lo1==0 && foldcase);
128
+ - lo1++;
129
+ - }
130
+ -
131
+ - // Trailing fragment.
132
+ - if (hi2 < 0xFF) {
133
+ - AddUCS2Pair(hi1, hi1, false, 0, hi2, false);
134
+ - hi1--;
135
+ - }
136
+ -
137
+ - // Inner ranges.
138
+ - if (lo1 <= hi1) {
139
+ - AddUCS2Pair(lo1, hi1, false, 0, 0xFF, false);
140
+ - }
141
+ - }
142
+ -
143
+ - // Restore reverse setting.
144
+ - reversed_ = oldreversed;
145
+ - }
146
+ -
147
+ // Table describing how to make a UTF-8 matching machine
148
+ // for the rune range 80-10FFFF (Runeself-Runemax).
149
+ // This range happens frequently enough (for example /./ and /[^a-z]/)
150
+ re2/compile.cc#17:707,716 - re2/compile.cc#18:627,634
151
+
152
+ Frag Compiler::Literal(Rune r, bool foldcase) {
153
+ switch (encoding_) {
154
+ - default: // UCS-2 or something new
155
+ - BeginRange();
156
+ - AddRuneRange(r, r, foldcase);
157
+ - return EndRange();
158
+ + default:
159
+ + return kNullFrag;
160
+
161
+ case kEncodingLatin1:
162
+ return ByteRange(r, r, foldcase);
163
+ re2/compile.cc#17:927,934 - re2/compile.cc#18:845,850
164
+
165
+ if (re->parse_flags() & Regexp::Latin1)
166
+ c.encoding_ = kEncodingLatin1;
167
+ - else if (re->parse_flags() & Regexp::UCS2)
168
+ - c.encoding_ = kEncodingUCS2;
169
+ c.reversed_ = reversed;
170
+ if (max_mem <= 0) {
171
+ c.max_inst_ = 100000; // more than enough
172
+ re2/compile.cc#17:983,993 - re2/compile.cc#18:899,905
173
+ c.prog_->set_start_unanchored(c.prog_->start());
174
+ } else {
175
+ Frag dot;
176
+ - if (c.encoding_ == kEncodingUCS2) {
177
+ - dot = c.Cat(c.ByteRange(0x00, 0xFF, false), c.ByteRange(0x00, 0xFF, false));
178
+ - } else {
179
+ - dot = c.ByteRange(0x00, 0xFF, false);
180
+ - }
181
+ + dot = c.ByteRange(0x00, 0xFF, false);
182
+ Frag dotloop = c.Star(dot, true);
183
+ Frag unanchored = c.Cat(dotloop, all);
184
+ c.prog_->set_start_unanchored(unanchored.begin);
185
+ ==== re2/nfa.cc#8 - re2/nfa.cc#9 ====
186
+ re2/nfa.cc#8:426,432 - re2/nfa.cc#9:426,431
187
+ const char* bp = context.begin();
188
+ int c = -1;
189
+ int wasword = 0;
190
+ - bool ucs2 = prog_->flags() & Regexp::UCS2;
191
+
192
+ if (text.begin() > context.begin()) {
193
+ c = text.begin()[-1] & 0xFF;
194
+ re2/nfa.cc#8:492,498 - re2/nfa.cc#9:491,497
195
+ // If there's a required first byte for an unanchored search
196
+ // and we're not in the middle of any possible matches,
197
+ // use memchr to search for the byte quickly.
198
+ - if (!ucs2 && !anchored && first_byte_ >= 0 && runq->size() == 0 &&
199
+ + if (!anchored && first_byte_ >= 0 && runq->size() == 0 &&
200
+ p < text.end() && (p[0] & 0xFF) != first_byte_) {
201
+ p = reinterpret_cast<const char*>(memchr(p, first_byte_,
202
+ text.end() - p));
203
+ re2/nfa.cc#8:505,526 - re2/nfa.cc#9:504,514
204
+ flag = Prog::EmptyFlags(context, p);
205
+ }
206
+
207
+ - // In UCS-2 mode, if we need to start a new thread,
208
+ - // make sure to do it on an even boundary.
209
+ - if(ucs2 && runq->size() == 0 &&
210
+ - (p - context.begin()) % 2 && p < text.end()) {
211
+ - p++;
212
+ - flag = Prog::EmptyFlags(context, p);
213
+ - }
214
+ -
215
+ // Steal match storage (cleared but unused as of yet)
216
+ // temporarily to hold match boundaries for new thread.
217
+ - // In UCS-2 mode, only start the thread on a 2-byte boundary.
218
+ - if(!ucs2 || (p - context.begin()) % 2 == 0) {
219
+ - match_[0] = p;
220
+ - AddToThreadq(runq, start_, flag, p, match_);
221
+ - match_[0] = NULL;
222
+ - }
223
+ + match_[0] = p;
224
+ + AddToThreadq(runq, start_, flag, p, match_);
225
+ + match_[0] = NULL;
226
+ }
227
+
228
+ // If all the threads have died, stop early.
229
+ ==== re2/parse.cc#22 - re2/parse.cc#23 ====
230
+ re2/parse.cc#22:160,167 - re2/parse.cc#23:160,165
231
+ status_(status), stacktop_(NULL), ncap_(0) {
232
+ if (flags_ & Latin1)
233
+ rune_max_ = 0xFF;
234
+ - else if (flags & UCS2)
235
+ - rune_max_ = 0xFFFF;
236
+ else
237
+ rune_max_ = Runemax;
238
+ }
239
+ re2/parse.cc#22:365,387 - re2/parse.cc#23:363,374
240
+ bool Regexp::ParseState::PushCarat() {
241
+ if (flags_ & OneLine) {
242
+ return PushSimpleOp(kRegexpBeginText);
243
+ - } else {
244
+ - if (flags_ & UCS2) {
245
+ - status_->set_code(kRegexpUnsupported);
246
+ - status_->set_error_arg("multiline ^ in UCS-2 mode");
247
+ - return false;
248
+ - }
249
+ - return PushSimpleOp(kRegexpBeginLine);
250
+ }
251
+ + return PushSimpleOp(kRegexpBeginLine);
252
+ }
253
+
254
+ // Pushes a \b or \B onto the stack.
255
+ bool Regexp::ParseState::PushWordBoundary(bool word) {
256
+ - if (flags_ & UCS2) {
257
+ - status_->set_code(kRegexpUnsupported);
258
+ - status_->set_error_arg("\\b or \\B in UCS-2 mode");
259
+ - return false;
260
+ - }
261
+ if (word)
262
+ return PushSimpleOp(kRegexpWordBoundary);
263
+ return PushSimpleOp(kRegexpNoWordBoundary);
264
+ re2/parse.cc#22:397,407 - re2/parse.cc#23:384,389
265
+ bool ret = PushSimpleOp(kRegexpEndText);
266
+ flags_ = oflags;
267
+ return ret;
268
+ - }
269
+ - if (flags_ & UCS2) {
270
+ - status_->set_code(kRegexpUnsupported);
271
+ - status_->set_error_arg("multiline $ in UCS-2 mode");
272
+ - return false;
273
+ }
274
+ return PushSimpleOp(kRegexpEndLine);
275
+ }
276
+ ==== re2/re2.cc#34 - re2/re2.cc#35 ====
277
+ re2/re2.cc#34:79,86 - re2/re2.cc#35:79,84
278
+ return RE2::ErrorBadUTF8;
279
+ case re2::kRegexpBadNamedCapture:
280
+ return RE2::ErrorBadNamedCapture;
281
+ - case re2::kRegexpUnsupported:
282
+ - return RE2::ErrorUnsupported;
283
+ }
284
+ return RE2::ErrorInternal;
285
+ }
286
+ re2/re2.cc#34:122,130 - re2/re2.cc#35:120,125
287
+ break;
288
+ case RE2::Options::EncodingLatin1:
289
+ flags |= Regexp::Latin1;
290
+ - break;
291
+ - case RE2::Options::EncodingUCS2:
292
+ - flags |= Regexp::UCS2;
293
+ break;
294
+ }
295
+
296
+ ==== re2/re2.h#36 - re2/re2.h#37 ====
297
+ re2/re2.h#36:246,252 - re2/re2.h#37:246,251
298
+ ErrorBadUTF8, // invalid UTF-8 in regexp
299
+ ErrorBadNamedCapture, // bad named capture group
300
+ ErrorPatternTooLarge, // pattern too large (compile failed)
301
+ - ErrorUnsupported, // unsupported feature (in UCS-2 mode)
302
+ };
303
+
304
+ // Predefined common options.
305
+ re2/re2.h#36:570,576 - re2/re2.h#37:569,574
306
+
307
+ enum Encoding {
308
+ EncodingUTF8 = 1,
309
+ - EncodingUCS2, // 16-bit Unicode 0-FFFF only
310
+ EncodingLatin1
311
+ };
312
+
313
+ ==== re2/regexp.cc#15 - re2/regexp.cc#16 ====
314
+ re2/regexp.cc#15:324,333 - re2/regexp.cc#16:324,329
315
+ // the regexp that remains after the prefix. The prefix might
316
+ // be ASCII case-insensitive.
317
+ bool Regexp::RequiredPrefix(string *prefix, bool *foldcase, Regexp** suffix) {
318
+ - // Don't even bother for UCS-2; it's time to throw that code away.
319
+ - if (parse_flags_ & UCS2)
320
+ - return false;
321
+ -
322
+ // No need for a walker: the regexp must be of the form
323
+ // 1. some number of ^ anchors
324
+ // 2. a literal char or string
325
+ ==== re2/regexp.h#20 - re2/regexp.h#21 ====
326
+ re2/regexp.h#20:187,193 - re2/regexp.h#21:187,192
327
+ kRegexpBadPerlOp, // bad perl operator
328
+ kRegexpBadUTF8, // invalid UTF-8 in regexp
329
+ kRegexpBadNamedCapture, // bad named capture
330
+ - kRegexpUnsupported, // unsupported operator
331
+ };
332
+
333
+ // Error status for certain operations.
334
+ re2/regexp.h#20:307,316 - re2/regexp.h#21:306,314
335
+ // \Q and \E to disable/enable metacharacters
336
+ // (?P<name>expr) for named captures
337
+ // \C to match any single byte
338
+ - UCS2 = 1<<10, // Text is in UCS-2, regexp is in UTF-8.
339
+ - UnicodeGroups = 1<<11, // Allow \p{Han} for Unicode Han group
340
+ + UnicodeGroups = 1<<10, // Allow \p{Han} for Unicode Han group
341
+ // and \P{Han} for its negation.
342
+ - NeverNL = 1<<12, // Never match NL, even if the regexp mentions
343
+ + NeverNL = 1<<11, // Never match NL, even if the regexp mentions
344
+ // it explicitly.
345
+
346
+ // As close to Perl as we can get.
347
+ ==== re2/testing/backtrack.cc#4 - re2/testing/backtrack.cc#5 ====
348
+ re2/testing/backtrack.cc#4:134,141 - re2/testing/backtrack.cc#5:134,139
349
+ cap_[0] = p;
350
+ if (Visit(prog_->start(), p)) // Match must be leftmost; done.
351
+ return true;
352
+ - if (prog_->flags() & Regexp::UCS2)
353
+ - p++;
354
+ }
355
+ return false;
356
+ }
357
+ ==== re2/testing/tester.cc#12 - re2/testing/tester.cc#13 ====
358
+ re2/testing/tester.cc#12:144,154 - re2/testing/tester.cc#13:144,152
359
+ static ParseMode parse_modes[] = {
360
+ { single_line, "single-line" },
361
+ { single_line|Regexp::Latin1, "single-line, latin1" },
362
+ - { single_line|Regexp::UCS2, "single-line, ucs2" },
363
+ { multi_line, "multiline" },
364
+ { multi_line|Regexp::NonGreedy, "multiline, nongreedy" },
365
+ { multi_line|Regexp::Latin1, "multiline, latin1" },
366
+ - { multi_line|Regexp::UCS2, "multiline, ucs2" },
367
+ };
368
+
369
+ static string FormatMode(Regexp::ParseFlags flags) {
370
+ re2/testing/tester.cc#12:179,189 - re2/testing/tester.cc#13:177,185
371
+ RegexpStatus status;
372
+ regexp_ = Regexp::Parse(regexp_str, flags, &status);
373
+ if (regexp_ == NULL) {
374
+ - if (status.code() != kRegexpUnsupported) {
375
+ - LOG(INFO) << "Cannot parse: " << CEscape(regexp_str_)
376
+ - << " mode: " << FormatMode(flags);
377
+ - error_ = true;
378
+ - }
379
+ + LOG(INFO) << "Cannot parse: " << CEscape(regexp_str_)
380
+ + << " mode: " << FormatMode(flags);
381
+ + error_ = true;
382
+ return;
383
+ }
384
+ prog_ = regexp_->CompileToProg(0);
385
+ re2/testing/tester.cc#12:230,237 - re2/testing/tester.cc#13:226,231
386
+ RE2::Options options;
387
+ if (flags & Regexp::Latin1)
388
+ options.set_encoding(RE2::Options::EncodingLatin1);
389
+ - else if (flags & Regexp::UCS2)
390
+ - options.set_encoding(RE2::Options::EncodingUCS2);
391
+ if (kind_ == Prog::kLongestMatch)
392
+ options.set_longest_match(true);
393
+ re2_ = new RE2(re, options);
394
+ re2/testing/tester.cc#12:281,379 - re2/testing/tester.cc#13:275,280
395
+ delete re2_;
396
+ }
397
+
398
+ - // Converts UTF-8 string in text into UCS-2 string in new_text.
399
+ - static bool ConvertUTF8ToUCS2(const StringPiece& text, StringPiece* new_text) {
400
+ - const char* p = text.begin();
401
+ - const char* ep = text.end();
402
+ - uint16* q = new uint16[ep - p];
403
+ - uint16* q0 = q;
404
+ -
405
+ - int n;
406
+ - Rune r;
407
+ - for (; p < ep; p += n) {
408
+ - if (!fullrune(p, ep - p)) {
409
+ - delete[] q0;
410
+ - return false;
411
+ - }
412
+ - n = chartorune(&r, p);
413
+ - if (r > 0xFFFF) {
414
+ - delete[] q0;
415
+ - return false;
416
+ - }
417
+ - *q++ = r;
418
+ - }
419
+ - *new_text = StringPiece(reinterpret_cast<char*>(q0), 2*(q - q0));
420
+ - return true;
421
+ - }
422
+ -
423
+ - // Rewrites *sp from being a pointer into text8 (UTF-8)
424
+ - // to being a pointer into text16 (equivalent text but in UCS-2).
425
+ - static void AdjustUTF8ToUCS2(const StringPiece& text8, const StringPiece& text16,
426
+ - StringPiece *sp) {
427
+ - if (sp->begin() == NULL && text8.begin() != NULL)
428
+ - return;
429
+ -
430
+ - int nrune = 0;
431
+ - int n;
432
+ - Rune r;
433
+ - const char* p = text8.begin();
434
+ - const char* ep = text8.end();
435
+ - const char* spbegin = NULL;
436
+ - const char* spend = NULL;
437
+ - for (;;) {
438
+ - if (p == sp->begin())
439
+ - spbegin = text16.begin() + sizeof(uint16)*nrune;
440
+ - if (p == sp->end())
441
+ - spend = text16.begin() + sizeof(uint16)*nrune;
442
+ - if (p >= ep)
443
+ - break;
444
+ - n = chartorune(&r, p);
445
+ - p += n;
446
+ - nrune++;
447
+ - }
448
+ - if (spbegin == NULL || spend == NULL) {
449
+ - LOG(FATAL) << "Error in AdjustUTF8ToUCS2 "
450
+ - << CEscape(text8) << " "
451
+ - << (int)(sp->begin() - text8.begin()) << " "
452
+ - << (int)(sp->end() - text8.begin());
453
+ - }
454
+ - *sp = StringPiece(spbegin, spend - spbegin);
455
+ - }
456
+ -
457
+ - // Rewrites *sp from begin a pointer into text16 (UCS-2)
458
+ - // to being a pointer into text8 (equivalent text but in UTF-8).
459
+ - static void AdjustUCS2ToUTF8(const StringPiece& text16, const StringPiece& text8,
460
+ - StringPiece* sp) {
461
+ - if (sp->begin() == NULL)
462
+ - return;
463
+ -
464
+ - int nrune = 0;
465
+ - int n;
466
+ - Rune r;
467
+ - const char* p = text8.begin();
468
+ - const char* ep = text8.end();
469
+ - const char* spbegin = NULL;
470
+ - const char* spend = NULL;
471
+ - for (;;) {
472
+ - if (nrune == (sp->begin() - text16.begin())/2)
473
+ - spbegin = p;
474
+ - if (nrune == (sp->end() - text16.begin())/2)
475
+ - spend = p;
476
+ - if (p >= ep)
477
+ - break;
478
+ - n = chartorune(&r, p);
479
+ - p += n;
480
+ - nrune++;
481
+ - }
482
+ - if (text8.begin() != NULL && (spbegin == NULL || spend == NULL)) {
483
+ - LOG(FATAL) << "Error in AdjustUCS2ToUTF8 "
484
+ - << CEscape(text16) << " "
485
+ - << (int)(sp->begin() - text16.begin()) << " "
486
+ - << (int)(sp->end() - text16.begin());
487
+ - }
488
+ - *sp = StringPiece(spbegin, spend - spbegin);
489
+ - }
490
+ -
491
+ // Runs a single search using the named engine type.
492
+ // This interface hides all the irregularities of the various
493
+ // engine interfaces from the rest of this file.
494
+ re2/testing/tester.cc#12:393,411 - re2/testing/tester.cc#13:294,300
495
+
496
+ StringPiece text = orig_text;
497
+ StringPiece context = orig_context;
498
+ - bool ucs2 = false;
499
+
500
+ - if ((flags() & Regexp::UCS2) && type != kEnginePCRE) {
501
+ - if (!ConvertUTF8ToUCS2(orig_context, &context)) {
502
+ - result->skipped = true;
503
+ - return;
504
+ - }
505
+ -
506
+ - // Rewrite context to refer to new text.
507
+ - AdjustUTF8ToUCS2(orig_context, context, &text);
508
+ - ucs2 = true;
509
+ - }
510
+ -
511
+ switch (type) {
512
+ default:
513
+ LOG(FATAL) << "Bad RunSearch type: " << (int)type;
514
+ re2/testing/tester.cc#12:557,577 - re2/testing/tester.cc#13:446,451
515
+ }
516
+ }
517
+
518
+ - // If we did UCS-2 matching, rewrite the matches to refer
519
+ - // to the original UTF-8 text.
520
+ - if (ucs2) {
521
+ - if (result->matched) {
522
+ - if (result->have_submatch0) {
523
+ - AdjustUCS2ToUTF8(context, orig_context, &result->submatch[0]);
524
+ - } else if (result->have_submatch) {
525
+ - for (int i = 0; i < nsubmatch; i++) {
526
+ - AdjustUCS2ToUTF8(context, orig_context, &result->submatch[i]);
527
+ - }
528
+ - }
529
+ - }
530
+ - delete[] context.begin();
531
+ - }
532
+ -
533
+ if (!result->matched)
534
+ memset(result->submatch, 0, sizeof result->submatch);
535
+ }
536
+ re2/testing/tester.cc#12:596,617 - re2/testing/tester.cc#13:470,475
537
+ return true;
538
+ }
539
+
540
+ - // Check whether text uses only Unicode points <= 0xFFFF
541
+ - // (in the BMP).
542
+ - static bool IsBMP(const StringPiece& text) {
543
+ - const char* p = text.begin();
544
+ - const char* ep = text.end();
545
+ - while (p < ep) {
546
+ - if (!fullrune(p, ep - p))
547
+ - return false;
548
+ - Rune r;
549
+ - p += chartorune(&r, p);
550
+ - if (r > 0xFFFF)
551
+ - return false;
552
+ - }
553
+ - return true;
554
+ - }
555
+ -
556
+ // Runs a single test.
557
+ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
558
+ Prog::Anchor anchor) {
559
+ re2/testing/tester.cc#12:619,625 - re2/testing/tester.cc#13:477,483
560
+ Result correct;
561
+ RunSearch(kEngineBacktrack, text, context, anchor, &correct);
562
+ if (correct.skipped) {
563
+ - if (regexp_ == NULL || !IsBMP(context)) // okay to skip in UCS-2 mode
564
+ + if (regexp_ == NULL)
565
+ return true;
566
+ LOG(ERROR) << "Skipped backtracking! " << CEscape(regexp_str_)
567
+ << " " << FormatMode(flags_);
@@ -13,7 +13,7 @@
13
13
  #include <ostream>
14
14
  #include <sstream>
15
15
 
16
- #include "util/util.h"
16
+ #include "absl/base/attributes.h"
17
17
 
18
18
  // Debug-only checking.
19
19
  #define DCHECK(condition) assert(condition)
@@ -93,7 +93,7 @@ class LogMessageFatal : public LogMessage {
93
93
  public:
94
94
  LogMessageFatal(const char* file, int line)
95
95
  : LogMessage(file, line) {}
96
- ATTRIBUTE_NORETURN ~LogMessageFatal() {
96
+ ABSL_ATTRIBUTE_NORETURN ~LogMessageFatal() {
97
97
  Flush();
98
98
  abort();
99
99
  }