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.
- package/.github/actions/linux-alpine-node-16/Dockerfile +1 -1
- package/.github/actions/linux-alpine-node-18/Dockerfile +1 -1
- package/.github/actions/linux-alpine-node-20/Dockerfile +1 -1
- package/.gitmodules +5 -2
- package/README.md +1 -0
- package/binding.gyp +82 -25
- package/lib/replace.cc +4 -4
- package/package.json +1 -1
- package/tsconfig.json +2 -1
- package/vendor/re2/.bazelrc +16 -0
- package/vendor/re2/.github/bazel.sh +24 -0
- package/vendor/re2/.github/cmake.sh +12 -0
- package/vendor/re2/.github/workflows/ci-bazel.yml +17 -0
- package/vendor/re2/.github/workflows/ci-cmake.yml +108 -0
- package/vendor/re2/.github/workflows/ci.yml +89 -0
- package/vendor/re2/.github/workflows/pr.yml +26 -0
- package/vendor/re2/.github/workflows/python.yml +185 -0
- package/vendor/re2/AUTHORS +13 -0
- package/vendor/re2/BUILD.bazel +280 -0
- package/vendor/re2/CMakeLists.txt +268 -0
- package/vendor/re2/CONTRIBUTING.md +2 -0
- package/vendor/re2/CONTRIBUTORS +41 -0
- package/vendor/re2/Makefile +400 -0
- package/vendor/{README → re2/README} +5 -0
- package/vendor/re2/SECURITY.md +4 -0
- package/vendor/re2/WORKSPACE.bazel +62 -0
- package/vendor/re2/app/BUILD.bazel +19 -0
- package/vendor/re2/app/_re2.cc +94 -0
- package/vendor/re2/app/_re2.d.ts +23 -0
- package/vendor/re2/app/app.ts +111 -0
- package/vendor/re2/app/build.sh +50 -0
- package/vendor/re2/app/index.html +5 -0
- package/vendor/re2/app/package.json +14 -0
- package/vendor/re2/app/rollup.config.js +28 -0
- package/vendor/re2/app/tsconfig.json +17 -0
- package/vendor/re2/benchlog/benchplot.py +98 -0
- package/vendor/re2/benchlog/mktable +155 -0
- package/vendor/re2/doc/mksyntaxgo +42 -0
- package/vendor/re2/doc/mksyntaxhtml +42 -0
- package/vendor/re2/doc/mksyntaxwiki +36 -0
- package/vendor/re2/doc/syntax.html +477 -0
- package/vendor/re2/doc/syntax.txt +463 -0
- package/vendor/re2/lib/git/commit-msg.hook +104 -0
- package/vendor/re2/libre2.symbols +19 -0
- package/vendor/re2/libre2.symbols.darwin +15 -0
- package/vendor/re2/python/BUILD.bazel +36 -0
- package/vendor/re2/python/README +1 -0
- package/vendor/re2/python/_re2.cc +338 -0
- package/vendor/re2/python/re2.py +582 -0
- package/vendor/re2/python/re2_test.py +482 -0
- package/vendor/re2/python/setup.py +105 -0
- package/vendor/re2/{bitmap256.cc → re2/bitmap256.cc} +4 -4
- package/vendor/re2/{bitstate.cc → re2/bitstate.cc} +21 -25
- package/vendor/re2/{compile.cc → re2/compile.cc} +5 -4
- package/vendor/re2/{dfa.cc → re2/dfa.cc} +120 -101
- package/vendor/re2/{filtered_re2.cc → re2/filtered_re2.cc} +8 -11
- package/vendor/re2/{filtered_re2.h → re2/filtered_re2.h} +5 -4
- package/vendor/re2/{fuzzing → re2/fuzzing}/re2_fuzzer.cc +4 -6
- package/vendor/re2/{mimics_pcre.cc → re2/mimics_pcre.cc} +0 -1
- package/vendor/re2/{nfa.cc → re2/nfa.cc} +34 -37
- package/vendor/re2/{onepass.cc → re2/onepass.cc} +25 -27
- package/vendor/re2/{parse.cc → re2/parse.cc} +118 -121
- package/vendor/re2/{prefilter.cc → re2/prefilter.cc} +2 -3
- package/vendor/re2/{prefilter.h → re2/prefilter.h} +0 -1
- package/vendor/re2/{prefilter_tree.cc → re2/prefilter_tree.cc} +4 -5
- package/vendor/re2/{prefilter_tree.h → re2/prefilter_tree.h} +1 -2
- package/vendor/re2/{prog.cc → re2/prog.cc} +20 -21
- package/vendor/re2/{prog.h → re2/prog.h} +21 -22
- package/vendor/re2/{re2.cc → re2/re2.cc} +51 -62
- package/vendor/re2/{re2.h → re2/re2.h} +78 -40
- package/vendor/re2/{regexp.cc → re2/regexp.cc} +11 -12
- package/vendor/re2/{regexp.h → re2/regexp.h} +9 -10
- package/vendor/re2/{set.cc → re2/set.cc} +3 -5
- package/vendor/re2/{set.h → re2/set.h} +4 -3
- package/vendor/re2/{simplify.cc → re2/simplify.cc} +1 -2
- package/vendor/re2/re2/stringpiece.h +24 -0
- package/vendor/re2/{testing → re2/testing}/backtrack.cc +22 -25
- package/vendor/re2/{testing → re2/testing}/charclass_test.cc +23 -21
- package/vendor/re2/{testing → re2/testing}/compile_test.cc +5 -4
- package/vendor/re2/{testing → re2/testing}/dfa_test.cc +36 -30
- package/vendor/re2/{testing → re2/testing}/dump.cc +8 -8
- package/vendor/re2/{testing → re2/testing}/exhaustive1_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive2_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive3_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive_tester.cc +36 -32
- package/vendor/re2/{testing → re2/testing}/exhaustive_tester.h +0 -1
- package/vendor/re2/{testing → re2/testing}/filtered_re2_test.cc +9 -8
- package/vendor/re2/{testing → re2/testing}/mimics_pcre_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/null_walker.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/parse_test.cc +13 -12
- package/vendor/re2/{testing → re2/testing}/possible_match_test.cc +15 -14
- package/vendor/re2/{testing → re2/testing}/random_test.cc +13 -12
- package/vendor/re2/{testing → re2/testing}/re2_arg_test.cc +25 -2
- package/vendor/re2/{testing → re2/testing}/re2_test.cc +49 -47
- package/vendor/re2/{testing → re2/testing}/regexp_benchmark.cc +144 -145
- package/vendor/re2/{testing → re2/testing}/regexp_generator.cc +18 -14
- package/vendor/re2/{testing → re2/testing}/regexp_generator.h +3 -4
- package/vendor/re2/{testing → re2/testing}/regexp_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/required_prefix_test.cc +5 -4
- package/vendor/re2/{testing → re2/testing}/search_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/set_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/simplify_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/string_generator.cc +3 -3
- package/vendor/re2/{testing → re2/testing}/string_generator.h +5 -6
- package/vendor/re2/{testing → re2/testing}/string_generator_test.cc +2 -2
- package/vendor/re2/{testing → re2/testing}/tester.cc +77 -78
- package/vendor/re2/{testing → re2/testing}/tester.h +13 -15
- package/vendor/re2/{tostring.cc → re2/tostring.cc} +7 -8
- package/vendor/re2/{unicode_casefold.h → re2/unicode_casefold.h} +0 -1
- package/vendor/re2/{unicode_groups.h → re2/unicode_groups.h} +0 -1
- package/vendor/re2/{walker-inl.h → re2/walker-inl.h} +2 -1
- package/vendor/re2/re2.pc.in +9 -0
- package/vendor/re2/re2Config.cmake.in +28 -0
- package/vendor/re2/runtests +33 -0
- package/vendor/re2/testinstall.cc +27 -0
- package/vendor/re2/ucs2.diff +567 -0
- package/vendor/{util → re2/util}/logging.h +2 -2
- package/vendor/{util → re2/util}/pcre.cc +47 -116
- package/vendor/{util → re2/util}/pcre.h +53 -63
- package/vendor/re2/util/strutil.cc +26 -0
- package/vendor/{util → re2/util}/strutil.h +0 -5
- package/vendor/re2/stringpiece.cc +0 -65
- package/vendor/re2/stringpiece.h +0 -213
- package/vendor/util/benchmark.cc +0 -131
- package/vendor/util/benchmark.h +0 -156
- package/vendor/util/flags.h +0 -26
- package/vendor/util/mix.h +0 -41
- package/vendor/util/mutex.h +0 -164
- package/vendor/util/strutil.cc +0 -149
- package/vendor/util/test.cc +0 -34
- package/vendor/util/test.h +0 -50
- package/vendor/util/util.h +0 -42
- /package/vendor/{LICENSE → re2/LICENSE} +0 -0
- /package/vendor/re2/{bitmap256.h → re2/bitmap256.h} +0 -0
- /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/LICENSE +0 -0
- /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/include/fuzzer/FuzzedDataProvider.h +0 -0
- /package/vendor/re2/{make_perl_groups.pl → re2/make_perl_groups.pl} +0 -0
- /package/vendor/re2/{make_unicode_casefold.py → re2/make_unicode_casefold.py} +0 -0
- /package/vendor/re2/{make_unicode_groups.py → re2/make_unicode_groups.py} +0 -0
- /package/vendor/re2/{perl_groups.cc → re2/perl_groups.cc} +0 -0
- /package/vendor/re2/{pod_array.h → re2/pod_array.h} +0 -0
- /package/vendor/re2/{sparse_array.h → re2/sparse_array.h} +0 -0
- /package/vendor/re2/{sparse_set.h → re2/sparse_set.h} +0 -0
- /package/vendor/re2/{unicode.py → re2/unicode.py} +0 -0
- /package/vendor/re2/{unicode_casefold.cc → re2/unicode_casefold.cc} +0 -0
- /package/vendor/re2/{unicode_groups.cc → re2/unicode_groups.cc} +0 -0
- /package/vendor/{util → re2/util}/fuzz.cc +0 -0
- /package/vendor/{util → re2/util}/malloc_counter.h +0 -0
- /package/vendor/{util → re2/util}/rune.cc +0 -0
- /package/vendor/{util → re2/util}/utf.h +0 -0
|
@@ -25,13 +25,11 @@
|
|
|
25
25
|
#include <string>
|
|
26
26
|
#include <vector>
|
|
27
27
|
|
|
28
|
-
#include "
|
|
28
|
+
#include "absl/base/macros.h"
|
|
29
29
|
#include "util/logging.h"
|
|
30
|
-
#include "util/strutil.h"
|
|
31
30
|
#include "util/utf.h"
|
|
32
31
|
#include "re2/pod_array.h"
|
|
33
32
|
#include "re2/regexp.h"
|
|
34
|
-
#include "re2/stringpiece.h"
|
|
35
33
|
#include "re2/unicode_casefold.h"
|
|
36
34
|
#include "re2/unicode_groups.h"
|
|
37
35
|
#include "re2/walker-inl.h"
|
|
@@ -70,7 +68,7 @@ void Regexp::FUZZING_ONLY_set_maximum_repeat_count(int i) {
|
|
|
70
68
|
|
|
71
69
|
class Regexp::ParseState {
|
|
72
70
|
public:
|
|
73
|
-
ParseState(ParseFlags flags,
|
|
71
|
+
ParseState(ParseFlags flags, absl::string_view whole_regexp,
|
|
74
72
|
RegexpStatus* status);
|
|
75
73
|
~ParseState();
|
|
76
74
|
|
|
@@ -107,18 +105,18 @@ class Regexp::ParseState {
|
|
|
107
105
|
// Pushes a repeat operator regexp onto the stack.
|
|
108
106
|
// A valid argument for the operator must already be on the stack.
|
|
109
107
|
// s is the name of the operator, for use in error messages.
|
|
110
|
-
bool PushRepeatOp(RegexpOp op,
|
|
108
|
+
bool PushRepeatOp(RegexpOp op, absl::string_view s, bool nongreedy);
|
|
111
109
|
|
|
112
110
|
// Pushes a repetition regexp onto the stack.
|
|
113
111
|
// A valid argument for the operator must already be on the stack.
|
|
114
|
-
bool PushRepetition(int min, int max,
|
|
112
|
+
bool PushRepetition(int min, int max, absl::string_view s, bool nongreedy);
|
|
115
113
|
|
|
116
114
|
// Checks whether a particular regexp op is a marker.
|
|
117
115
|
bool IsMarker(RegexpOp op);
|
|
118
116
|
|
|
119
117
|
// Processes a left parenthesis in the input.
|
|
120
118
|
// Pushes a marker onto the stack.
|
|
121
|
-
bool DoLeftParen(
|
|
119
|
+
bool DoLeftParen(absl::string_view name);
|
|
122
120
|
bool DoLeftParenNoCapture();
|
|
123
121
|
|
|
124
122
|
// Processes a vertical bar in the input.
|
|
@@ -142,24 +140,23 @@ class Regexp::ParseState {
|
|
|
142
140
|
|
|
143
141
|
// Parse a character class into *out_re.
|
|
144
142
|
// Removes parsed text from s.
|
|
145
|
-
bool ParseCharClass(
|
|
143
|
+
bool ParseCharClass(absl::string_view* s, Regexp** out_re,
|
|
146
144
|
RegexpStatus* status);
|
|
147
145
|
|
|
148
146
|
// Parse a character class character into *rp.
|
|
149
147
|
// Removes parsed text from s.
|
|
150
|
-
bool ParseCCCharacter(
|
|
151
|
-
|
|
148
|
+
bool ParseCCCharacter(absl::string_view* s, Rune* rp,
|
|
149
|
+
absl::string_view whole_class,
|
|
152
150
|
RegexpStatus* status);
|
|
153
151
|
|
|
154
152
|
// Parse a character class range into rr.
|
|
155
153
|
// Removes parsed text from s.
|
|
156
|
-
bool ParseCCRange(
|
|
157
|
-
|
|
154
|
+
bool ParseCCRange(absl::string_view* s, RuneRange* rr,
|
|
155
|
+
absl::string_view whole_class,
|
|
158
156
|
RegexpStatus* status);
|
|
159
157
|
|
|
160
158
|
// Parse a Perl flag set or non-capturing group from s.
|
|
161
|
-
bool ParsePerlFlags(
|
|
162
|
-
|
|
159
|
+
bool ParsePerlFlags(absl::string_view* s);
|
|
163
160
|
|
|
164
161
|
// Finishes the current concatenation,
|
|
165
162
|
// collapsing it into a single regexp on the stack.
|
|
@@ -177,7 +174,7 @@ class Regexp::ParseState {
|
|
|
177
174
|
|
|
178
175
|
private:
|
|
179
176
|
ParseFlags flags_;
|
|
180
|
-
|
|
177
|
+
absl::string_view whole_regexp_;
|
|
181
178
|
RegexpStatus* status_;
|
|
182
179
|
Regexp* stacktop_;
|
|
183
180
|
int ncap_; // number of capturing parens seen
|
|
@@ -192,7 +189,7 @@ const RegexpOp kLeftParen = static_cast<RegexpOp>(kMaxRegexpOp+1);
|
|
|
192
189
|
const RegexpOp kVerticalBar = static_cast<RegexpOp>(kMaxRegexpOp+2);
|
|
193
190
|
|
|
194
191
|
Regexp::ParseState::ParseState(ParseFlags flags,
|
|
195
|
-
|
|
192
|
+
absl::string_view whole_regexp,
|
|
196
193
|
RegexpStatus* status)
|
|
197
194
|
: flags_(flags), whole_regexp_(whole_regexp),
|
|
198
195
|
status_(status), stacktop_(NULL), ncap_(0) {
|
|
@@ -269,7 +266,7 @@ bool Regexp::ParseState::PushRegexp(Regexp* re) {
|
|
|
269
266
|
// Searches the case folding tables and returns the CaseFold* that contains r.
|
|
270
267
|
// If there isn't one, returns the CaseFold* with smallest f->lo bigger than r.
|
|
271
268
|
// If there isn't one, returns NULL.
|
|
272
|
-
const CaseFold* LookupCaseFold(const CaseFold
|
|
269
|
+
const CaseFold* LookupCaseFold(const CaseFold* f, int n, Rune r) {
|
|
273
270
|
const CaseFold* ef = f + n;
|
|
274
271
|
|
|
275
272
|
// Binary search for entry containing r.
|
|
@@ -297,7 +294,7 @@ const CaseFold* LookupCaseFold(const CaseFold *f, int n, Rune r) {
|
|
|
297
294
|
}
|
|
298
295
|
|
|
299
296
|
// Returns the result of applying the fold f to the rune r.
|
|
300
|
-
Rune ApplyFold(const CaseFold
|
|
297
|
+
Rune ApplyFold(const CaseFold* f, Rune r) {
|
|
301
298
|
switch (f->delta) {
|
|
302
299
|
default:
|
|
303
300
|
return r + f->delta;
|
|
@@ -305,7 +302,7 @@ Rune ApplyFold(const CaseFold *f, Rune r) {
|
|
|
305
302
|
case EvenOddSkip: // even <-> odd but only applies to every other
|
|
306
303
|
if ((r - f->lo) % 2)
|
|
307
304
|
return r;
|
|
308
|
-
|
|
305
|
+
ABSL_FALLTHROUGH_INTENDED;
|
|
309
306
|
case EvenOdd: // even <-> odd
|
|
310
307
|
if (r%2 == 0)
|
|
311
308
|
return r + 1;
|
|
@@ -314,7 +311,7 @@ Rune ApplyFold(const CaseFold *f, Rune r) {
|
|
|
314
311
|
case OddEvenSkip: // odd <-> even but only applies to every other
|
|
315
312
|
if ((r - f->lo) % 2)
|
|
316
313
|
return r;
|
|
317
|
-
|
|
314
|
+
ABSL_FALLTHROUGH_INTENDED;
|
|
318
315
|
case OddEven: // odd <-> even
|
|
319
316
|
if (r%2 == 1)
|
|
320
317
|
return r + 1;
|
|
@@ -472,7 +469,7 @@ bool Regexp::ParseState::PushSimpleOp(RegexpOp op) {
|
|
|
472
469
|
// Pushes a repeat operator regexp onto the stack.
|
|
473
470
|
// A valid argument for the operator must already be on the stack.
|
|
474
471
|
// The char c is the name of the operator, for use in error messages.
|
|
475
|
-
bool Regexp::ParseState::PushRepeatOp(RegexpOp op,
|
|
472
|
+
bool Regexp::ParseState::PushRepeatOp(RegexpOp op, absl::string_view s,
|
|
476
473
|
bool nongreedy) {
|
|
477
474
|
if (stacktop_ == NULL || IsMarker(stacktop_->op())) {
|
|
478
475
|
status_->set_code(kRegexpRepeatArgument);
|
|
@@ -565,8 +562,7 @@ int RepetitionWalker::ShortVisit(Regexp* re, int parent_arg) {
|
|
|
565
562
|
|
|
566
563
|
// Pushes a repetition regexp onto the stack.
|
|
567
564
|
// A valid argument for the operator must already be on the stack.
|
|
568
|
-
bool Regexp::ParseState::PushRepetition(int min, int max,
|
|
569
|
-
const StringPiece& s,
|
|
565
|
+
bool Regexp::ParseState::PushRepetition(int min, int max, absl::string_view s,
|
|
570
566
|
bool nongreedy) {
|
|
571
567
|
if ((max != -1 && max < min) ||
|
|
572
568
|
min > maximum_repeat_count ||
|
|
@@ -609,7 +605,7 @@ bool Regexp::ParseState::IsMarker(RegexpOp op) {
|
|
|
609
605
|
|
|
610
606
|
// Processes a left parenthesis in the input.
|
|
611
607
|
// Pushes a marker onto the stack.
|
|
612
|
-
bool Regexp::ParseState::DoLeftParen(
|
|
608
|
+
bool Regexp::ParseState::DoLeftParen(absl::string_view name) {
|
|
613
609
|
Regexp* re = new Regexp(kLeftParen, flags_);
|
|
614
610
|
re->cap_ = ++ncap_;
|
|
615
611
|
if (name.data() != NULL)
|
|
@@ -774,8 +770,8 @@ Regexp* Regexp::RemoveLeadingRegexp(Regexp* re) {
|
|
|
774
770
|
// Returns the leading string that re starts with.
|
|
775
771
|
// The returned Rune* points into a piece of re,
|
|
776
772
|
// so it must not be used after the caller calls re->Decref().
|
|
777
|
-
Rune* Regexp::LeadingString(Regexp* re, int
|
|
778
|
-
Regexp::ParseFlags
|
|
773
|
+
Rune* Regexp::LeadingString(Regexp* re, int* nrune,
|
|
774
|
+
Regexp::ParseFlags* flags) {
|
|
779
775
|
while (re->op() == kRegexpConcat && re->nsub() > 0)
|
|
780
776
|
re = re->sub()[0];
|
|
781
777
|
|
|
@@ -806,7 +802,7 @@ void Regexp::RemoveLeadingString(Regexp* re, int n) {
|
|
|
806
802
|
Regexp* stk[4];
|
|
807
803
|
size_t d = 0;
|
|
808
804
|
while (re->op() == kRegexpConcat) {
|
|
809
|
-
if (d <
|
|
805
|
+
if (d < ABSL_ARRAYSIZE(stk))
|
|
810
806
|
stk[d++] = re;
|
|
811
807
|
re = re->sub()[0];
|
|
812
808
|
}
|
|
@@ -1325,7 +1321,7 @@ bool Regexp::ParseState::MaybeConcatString(int r, ParseFlags flags) {
|
|
|
1325
1321
|
|
|
1326
1322
|
// Parses a decimal integer, storing it in *np.
|
|
1327
1323
|
// Sets *s to span the remainder of the string.
|
|
1328
|
-
static bool ParseInteger(
|
|
1324
|
+
static bool ParseInteger(absl::string_view* s, int* np) {
|
|
1329
1325
|
if (s->empty() || !isdigit((*s)[0] & 0xFF))
|
|
1330
1326
|
return false;
|
|
1331
1327
|
// Disallow leading zeros.
|
|
@@ -1351,10 +1347,10 @@ static bool ParseInteger(StringPiece* s, int* np) {
|
|
|
1351
1347
|
// sets *hi to -1 to signify this.
|
|
1352
1348
|
// {,2} is NOT a valid suffix.
|
|
1353
1349
|
// The Maybe in the name signifies that the regexp parse
|
|
1354
|
-
// doesn't fail even if ParseRepetition does, so the
|
|
1350
|
+
// doesn't fail even if ParseRepetition does, so the string_view
|
|
1355
1351
|
// s must NOT be edited unless MaybeParseRepetition returns true.
|
|
1356
|
-
static bool MaybeParseRepetition(
|
|
1357
|
-
|
|
1352
|
+
static bool MaybeParseRepetition(absl::string_view* sp, int* lo, int* hi) {
|
|
1353
|
+
absl::string_view s = *sp;
|
|
1358
1354
|
if (s.empty() || s[0] != '{')
|
|
1359
1355
|
return false;
|
|
1360
1356
|
s.remove_prefix(1); // '{'
|
|
@@ -1385,12 +1381,13 @@ static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
|
|
|
1385
1381
|
return true;
|
|
1386
1382
|
}
|
|
1387
1383
|
|
|
1388
|
-
// Removes the next Rune from the
|
|
1384
|
+
// Removes the next Rune from the string_view and stores it in *r.
|
|
1389
1385
|
// Returns number of bytes removed from sp.
|
|
1390
1386
|
// Behaves as though there is a terminating NUL at the end of sp.
|
|
1391
1387
|
// Argument order is backwards from usual Google style
|
|
1392
1388
|
// but consistent with chartorune.
|
|
1393
|
-
static int
|
|
1389
|
+
static int StringViewToRune(Rune* r, absl::string_view* sp,
|
|
1390
|
+
RegexpStatus* status) {
|
|
1394
1391
|
// fullrune() takes int, not size_t. However, it just looks
|
|
1395
1392
|
// at the leading byte and treats any length >= 4 the same.
|
|
1396
1393
|
if (fullrune(sp->data(), static_cast<int>(std::min(size_t{4}, sp->size())))) {
|
|
@@ -1411,18 +1408,18 @@ static int StringPieceToRune(Rune *r, StringPiece *sp, RegexpStatus* status) {
|
|
|
1411
1408
|
|
|
1412
1409
|
if (status != NULL) {
|
|
1413
1410
|
status->set_code(kRegexpBadUTF8);
|
|
1414
|
-
status->set_error_arg(
|
|
1411
|
+
status->set_error_arg(absl::string_view());
|
|
1415
1412
|
}
|
|
1416
1413
|
return -1;
|
|
1417
1414
|
}
|
|
1418
1415
|
|
|
1419
1416
|
// Returns whether name is valid UTF-8.
|
|
1420
1417
|
// If not, sets status to kRegexpBadUTF8.
|
|
1421
|
-
static bool IsValidUTF8(
|
|
1422
|
-
|
|
1418
|
+
static bool IsValidUTF8(absl::string_view s, RegexpStatus* status) {
|
|
1419
|
+
absl::string_view t = s;
|
|
1423
1420
|
Rune r;
|
|
1424
1421
|
while (!t.empty()) {
|
|
1425
|
-
if (
|
|
1422
|
+
if (StringViewToRune(&r, &t, status) < 0)
|
|
1426
1423
|
return false;
|
|
1427
1424
|
}
|
|
1428
1425
|
return true;
|
|
@@ -1450,23 +1447,23 @@ static int UnHex(int c) {
|
|
|
1450
1447
|
// Parse an escape sequence (e.g., \n, \{).
|
|
1451
1448
|
// Sets *s to span the remainder of the string.
|
|
1452
1449
|
// Sets *rp to the named character.
|
|
1453
|
-
static bool ParseEscape(
|
|
1450
|
+
static bool ParseEscape(absl::string_view* s, Rune* rp,
|
|
1454
1451
|
RegexpStatus* status, int rune_max) {
|
|
1455
1452
|
const char* begin = s->data();
|
|
1456
1453
|
if (s->empty() || (*s)[0] != '\\') {
|
|
1457
1454
|
// Should not happen - caller always checks.
|
|
1458
1455
|
status->set_code(kRegexpInternalError);
|
|
1459
|
-
status->set_error_arg(
|
|
1456
|
+
status->set_error_arg(absl::string_view());
|
|
1460
1457
|
return false;
|
|
1461
1458
|
}
|
|
1462
1459
|
if (s->size() == 1) {
|
|
1463
1460
|
status->set_code(kRegexpTrailingBackslash);
|
|
1464
|
-
status->set_error_arg(
|
|
1461
|
+
status->set_error_arg(absl::string_view());
|
|
1465
1462
|
return false;
|
|
1466
1463
|
}
|
|
1467
1464
|
Rune c, c1;
|
|
1468
1465
|
s->remove_prefix(1); // backslash
|
|
1469
|
-
if (
|
|
1466
|
+
if (StringViewToRune(&c, s, status) < 0)
|
|
1470
1467
|
return false;
|
|
1471
1468
|
int code;
|
|
1472
1469
|
switch (c) {
|
|
@@ -1492,7 +1489,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1492
1489
|
// Single non-zero octal digit is a backreference; not supported.
|
|
1493
1490
|
if (s->empty() || (*s)[0] < '0' || (*s)[0] > '7')
|
|
1494
1491
|
goto BadEscape;
|
|
1495
|
-
|
|
1492
|
+
ABSL_FALLTHROUGH_INTENDED;
|
|
1496
1493
|
case '0':
|
|
1497
1494
|
// consume up to three octal digits; already have one.
|
|
1498
1495
|
code = c - '0';
|
|
@@ -1516,7 +1513,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1516
1513
|
case 'x':
|
|
1517
1514
|
if (s->empty())
|
|
1518
1515
|
goto BadEscape;
|
|
1519
|
-
if (
|
|
1516
|
+
if (StringViewToRune(&c, s, status) < 0)
|
|
1520
1517
|
return false;
|
|
1521
1518
|
if (c == '{') {
|
|
1522
1519
|
// Any number of digits in braces.
|
|
@@ -1525,7 +1522,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1525
1522
|
// Perl accepts any text at all; it ignores all text
|
|
1526
1523
|
// after the first non-hex digit. We require only hex digits,
|
|
1527
1524
|
// and at least one.
|
|
1528
|
-
if (
|
|
1525
|
+
if (StringViewToRune(&c, s, status) < 0)
|
|
1529
1526
|
return false;
|
|
1530
1527
|
int nhex = 0;
|
|
1531
1528
|
code = 0;
|
|
@@ -1536,7 +1533,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1536
1533
|
goto BadEscape;
|
|
1537
1534
|
if (s->empty())
|
|
1538
1535
|
goto BadEscape;
|
|
1539
|
-
if (
|
|
1536
|
+
if (StringViewToRune(&c, s, status) < 0)
|
|
1540
1537
|
return false;
|
|
1541
1538
|
}
|
|
1542
1539
|
if (c != '}' || nhex == 0)
|
|
@@ -1547,7 +1544,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1547
1544
|
// Easy case: two hex digits.
|
|
1548
1545
|
if (s->empty())
|
|
1549
1546
|
goto BadEscape;
|
|
1550
|
-
if (
|
|
1547
|
+
if (StringViewToRune(&c1, s, status) < 0)
|
|
1551
1548
|
return false;
|
|
1552
1549
|
if (!IsHex(c) || !IsHex(c1))
|
|
1553
1550
|
goto BadEscape;
|
|
@@ -1593,7 +1590,7 @@ BadEscape:
|
|
|
1593
1590
|
// Unrecognized escape sequence.
|
|
1594
1591
|
status->set_code(kRegexpBadEscape);
|
|
1595
1592
|
status->set_error_arg(
|
|
1596
|
-
|
|
1593
|
+
absl::string_view(begin, static_cast<size_t>(s->data() - begin)));
|
|
1597
1594
|
return false;
|
|
1598
1595
|
}
|
|
1599
1596
|
|
|
@@ -1621,21 +1618,21 @@ void CharClassBuilder::AddRangeFlags(
|
|
|
1621
1618
|
}
|
|
1622
1619
|
|
|
1623
1620
|
// Look for a group with the given name.
|
|
1624
|
-
static const UGroup* LookupGroup(
|
|
1625
|
-
const UGroup
|
|
1621
|
+
static const UGroup* LookupGroup(absl::string_view name,
|
|
1622
|
+
const UGroup* groups, int ngroups) {
|
|
1626
1623
|
// Simple name lookup.
|
|
1627
1624
|
for (int i = 0; i < ngroups; i++)
|
|
1628
|
-
if (
|
|
1625
|
+
if (absl::string_view(groups[i].name) == name)
|
|
1629
1626
|
return &groups[i];
|
|
1630
1627
|
return NULL;
|
|
1631
1628
|
}
|
|
1632
1629
|
|
|
1633
1630
|
// Look for a POSIX group with the given name (e.g., "[:^alpha:]")
|
|
1634
|
-
static const UGroup* LookupPosixGroup(
|
|
1631
|
+
static const UGroup* LookupPosixGroup(absl::string_view name) {
|
|
1635
1632
|
return LookupGroup(name, posix_groups, num_posix_groups);
|
|
1636
1633
|
}
|
|
1637
1634
|
|
|
1638
|
-
static const UGroup* LookupPerlGroup(
|
|
1635
|
+
static const UGroup* LookupPerlGroup(absl::string_view name) {
|
|
1639
1636
|
return LookupGroup(name, perl_groups, num_perl_groups);
|
|
1640
1637
|
}
|
|
1641
1638
|
|
|
@@ -1646,16 +1643,16 @@ static URange32 any32[] = { { 65536, Runemax } };
|
|
|
1646
1643
|
static UGroup anygroup = { "Any", +1, any16, 1, any32, 1 };
|
|
1647
1644
|
|
|
1648
1645
|
// Look for a Unicode group with the given name (e.g., "Han")
|
|
1649
|
-
static const UGroup* LookupUnicodeGroup(
|
|
1646
|
+
static const UGroup* LookupUnicodeGroup(absl::string_view name) {
|
|
1650
1647
|
// Special case: "Any" means any.
|
|
1651
|
-
if (name ==
|
|
1648
|
+
if (name == absl::string_view("Any"))
|
|
1652
1649
|
return &anygroup;
|
|
1653
1650
|
return LookupGroup(name, unicode_groups, num_unicode_groups);
|
|
1654
1651
|
}
|
|
1655
1652
|
#endif
|
|
1656
1653
|
|
|
1657
1654
|
// Add a UGroup or its negation to the character class.
|
|
1658
|
-
static void AddUGroup(CharClassBuilder
|
|
1655
|
+
static void AddUGroup(CharClassBuilder* cc, const UGroup* g, int sign,
|
|
1659
1656
|
Regexp::ParseFlags parse_flags) {
|
|
1660
1657
|
if (sign == +1) {
|
|
1661
1658
|
for (int i = 0; i < g->nr16; i++) {
|
|
@@ -1705,16 +1702,17 @@ static void AddUGroup(CharClassBuilder *cc, const UGroup *g, int sign,
|
|
|
1705
1702
|
// not the Perl empty-string classes (\b \B \A \Z \z).
|
|
1706
1703
|
// On success, sets *s to span the remainder of the string
|
|
1707
1704
|
// and returns the corresponding UGroup.
|
|
1708
|
-
// The
|
|
1709
|
-
const UGroup* MaybeParsePerlCCEscape(
|
|
1705
|
+
// The string_view must *NOT* be edited unless the call succeeds.
|
|
1706
|
+
const UGroup* MaybeParsePerlCCEscape(absl::string_view* s,
|
|
1707
|
+
Regexp::ParseFlags parse_flags) {
|
|
1710
1708
|
if (!(parse_flags & Regexp::PerlClasses))
|
|
1711
1709
|
return NULL;
|
|
1712
1710
|
if (s->size() < 2 || (*s)[0] != '\\')
|
|
1713
1711
|
return NULL;
|
|
1714
|
-
// Could use
|
|
1712
|
+
// Could use StringViewToRune, but there aren't
|
|
1715
1713
|
// any non-ASCII Perl group names.
|
|
1716
|
-
|
|
1717
|
-
const UGroup
|
|
1714
|
+
absl::string_view name(s->data(), 2);
|
|
1715
|
+
const UGroup* g = LookupPerlGroup(name);
|
|
1718
1716
|
if (g == NULL)
|
|
1719
1717
|
return NULL;
|
|
1720
1718
|
s->remove_prefix(name.size());
|
|
@@ -1729,9 +1727,9 @@ enum ParseStatus {
|
|
|
1729
1727
|
|
|
1730
1728
|
// Maybe parses a Unicode character group like \p{Han} or \P{Han}
|
|
1731
1729
|
// (the latter is a negated group).
|
|
1732
|
-
ParseStatus ParseUnicodeGroup(
|
|
1733
|
-
|
|
1734
|
-
RegexpStatus* status) {
|
|
1730
|
+
ParseStatus ParseUnicodeGroup(absl::string_view* s,
|
|
1731
|
+
Regexp::ParseFlags parse_flags,
|
|
1732
|
+
CharClassBuilder* cc, RegexpStatus* status) {
|
|
1735
1733
|
// Decide whether to parse.
|
|
1736
1734
|
if (!(parse_flags & Regexp::UnicodeGroups))
|
|
1737
1735
|
return kParseNothing;
|
|
@@ -1745,34 +1743,34 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1745
1743
|
int sign = +1; // -1 = negated char class
|
|
1746
1744
|
if (c == 'P')
|
|
1747
1745
|
sign = -sign;
|
|
1748
|
-
|
|
1749
|
-
|
|
1746
|
+
absl::string_view seq = *s; // \p{Han} or \pL
|
|
1747
|
+
absl::string_view name; // Han or L
|
|
1750
1748
|
s->remove_prefix(2); // '\\', 'p'
|
|
1751
1749
|
|
|
1752
|
-
if (!
|
|
1750
|
+
if (!StringViewToRune(&c, s, status))
|
|
1753
1751
|
return kParseError;
|
|
1754
1752
|
if (c != '{') {
|
|
1755
1753
|
// Name is the bit of string we just skipped over for c.
|
|
1756
1754
|
const char* p = seq.data() + 2;
|
|
1757
|
-
name =
|
|
1755
|
+
name = absl::string_view(p, static_cast<size_t>(s->data() - p));
|
|
1758
1756
|
} else {
|
|
1759
1757
|
// Name is in braces. Look for closing }
|
|
1760
1758
|
size_t end = s->find('}', 0);
|
|
1761
|
-
if (end ==
|
|
1759
|
+
if (end == absl::string_view::npos) {
|
|
1762
1760
|
if (!IsValidUTF8(seq, status))
|
|
1763
1761
|
return kParseError;
|
|
1764
1762
|
status->set_code(kRegexpBadCharRange);
|
|
1765
1763
|
status->set_error_arg(seq);
|
|
1766
1764
|
return kParseError;
|
|
1767
1765
|
}
|
|
1768
|
-
name =
|
|
1766
|
+
name = absl::string_view(s->data(), end); // without '}'
|
|
1769
1767
|
s->remove_prefix(end + 1); // with '}'
|
|
1770
1768
|
if (!IsValidUTF8(name, status))
|
|
1771
1769
|
return kParseError;
|
|
1772
1770
|
}
|
|
1773
1771
|
|
|
1774
1772
|
// Chop seq where s now begins.
|
|
1775
|
-
seq =
|
|
1773
|
+
seq = absl::string_view(seq.data(), static_cast<size_t>(s->data() - seq.data()));
|
|
1776
1774
|
|
|
1777
1775
|
if (!name.empty() && name[0] == '^') {
|
|
1778
1776
|
sign = -sign;
|
|
@@ -1781,7 +1779,7 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1781
1779
|
|
|
1782
1780
|
#if !defined(RE2_USE_ICU)
|
|
1783
1781
|
// Look up the group in the RE2 Unicode data.
|
|
1784
|
-
const UGroup
|
|
1782
|
+
const UGroup* g = LookupUnicodeGroup(name);
|
|
1785
1783
|
if (g == NULL) {
|
|
1786
1784
|
status->set_code(kRegexpBadCharRange);
|
|
1787
1785
|
status->set_error_arg(seq);
|
|
@@ -1819,9 +1817,9 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1819
1817
|
// Parses a character class name like [:alnum:].
|
|
1820
1818
|
// Sets *s to span the remainder of the string.
|
|
1821
1819
|
// Adds the ranges corresponding to the class to ranges.
|
|
1822
|
-
static ParseStatus ParseCCName(
|
|
1823
|
-
|
|
1824
|
-
RegexpStatus* status) {
|
|
1820
|
+
static ParseStatus ParseCCName(absl::string_view* s,
|
|
1821
|
+
Regexp::ParseFlags parse_flags,
|
|
1822
|
+
CharClassBuilder* cc, RegexpStatus* status) {
|
|
1825
1823
|
// Check begins with [:
|
|
1826
1824
|
const char* p = s->data();
|
|
1827
1825
|
const char* ep = s->data() + s->size();
|
|
@@ -1839,9 +1837,9 @@ static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1839
1837
|
|
|
1840
1838
|
// Got it. Check that it's valid.
|
|
1841
1839
|
q += 2;
|
|
1842
|
-
|
|
1840
|
+
absl::string_view name(p, static_cast<size_t>(q - p));
|
|
1843
1841
|
|
|
1844
|
-
const UGroup
|
|
1842
|
+
const UGroup* g = LookupPosixGroup(name);
|
|
1845
1843
|
if (g == NULL) {
|
|
1846
1844
|
status->set_code(kRegexpBadCharRange);
|
|
1847
1845
|
status->set_error_arg(name);
|
|
@@ -1857,8 +1855,8 @@ static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1857
1855
|
// There are fewer special characters here than in the rest of the regexp.
|
|
1858
1856
|
// Sets *s to span the remainder of the string.
|
|
1859
1857
|
// Sets *rp to the character.
|
|
1860
|
-
bool Regexp::ParseState::ParseCCCharacter(
|
|
1861
|
-
|
|
1858
|
+
bool Regexp::ParseState::ParseCCCharacter(absl::string_view* s, Rune* rp,
|
|
1859
|
+
absl::string_view whole_class,
|
|
1862
1860
|
RegexpStatus* status) {
|
|
1863
1861
|
if (s->empty()) {
|
|
1864
1862
|
status->set_code(kRegexpMissingBracket);
|
|
@@ -1872,7 +1870,7 @@ bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
|
|
|
1872
1870
|
return ParseEscape(s, rp, status, rune_max_);
|
|
1873
1871
|
|
|
1874
1872
|
// Otherwise take the next rune.
|
|
1875
|
-
return
|
|
1873
|
+
return StringViewToRune(rp, s, status) >= 0;
|
|
1876
1874
|
}
|
|
1877
1875
|
|
|
1878
1876
|
// Parses a character class character, or, if the character
|
|
@@ -1880,10 +1878,10 @@ bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
|
|
|
1880
1878
|
// For single characters, rr->lo == rr->hi.
|
|
1881
1879
|
// Sets *s to span the remainder of the string.
|
|
1882
1880
|
// Sets *rp to the character.
|
|
1883
|
-
bool Regexp::ParseState::ParseCCRange(
|
|
1884
|
-
|
|
1881
|
+
bool Regexp::ParseState::ParseCCRange(absl::string_view* s, RuneRange* rr,
|
|
1882
|
+
absl::string_view whole_class,
|
|
1885
1883
|
RegexpStatus* status) {
|
|
1886
|
-
|
|
1884
|
+
absl::string_view os = *s;
|
|
1887
1885
|
if (!ParseCCCharacter(s, &rr->lo, whole_class, status))
|
|
1888
1886
|
return false;
|
|
1889
1887
|
// [a-] means (a|-), so check for final ].
|
|
@@ -1893,8 +1891,8 @@ bool Regexp::ParseState::ParseCCRange(StringPiece* s, RuneRange* rr,
|
|
|
1893
1891
|
return false;
|
|
1894
1892
|
if (rr->hi < rr->lo) {
|
|
1895
1893
|
status->set_code(kRegexpBadCharRange);
|
|
1896
|
-
status->set_error_arg(
|
|
1897
|
-
|
|
1894
|
+
status->set_error_arg(absl::string_view(
|
|
1895
|
+
os.data(), static_cast<size_t>(s->data() - os.data())));
|
|
1898
1896
|
return false;
|
|
1899
1897
|
}
|
|
1900
1898
|
} else {
|
|
@@ -1906,14 +1904,13 @@ bool Regexp::ParseState::ParseCCRange(StringPiece* s, RuneRange* rr,
|
|
|
1906
1904
|
// Parses a possibly-negated character class expression like [^abx-z[:digit:]].
|
|
1907
1905
|
// Sets *s to span the remainder of the string.
|
|
1908
1906
|
// Sets *out_re to the regexp for the class.
|
|
1909
|
-
bool Regexp::ParseState::ParseCharClass(
|
|
1910
|
-
Regexp** out_re,
|
|
1907
|
+
bool Regexp::ParseState::ParseCharClass(absl::string_view* s, Regexp** out_re,
|
|
1911
1908
|
RegexpStatus* status) {
|
|
1912
|
-
|
|
1909
|
+
absl::string_view whole_class = *s;
|
|
1913
1910
|
if (s->empty() || (*s)[0] != '[') {
|
|
1914
1911
|
// Caller checked this.
|
|
1915
1912
|
status->set_code(kRegexpInternalError);
|
|
1916
|
-
status->set_error_arg(
|
|
1913
|
+
status->set_error_arg(absl::string_view());
|
|
1917
1914
|
return false;
|
|
1918
1915
|
}
|
|
1919
1916
|
bool negated = false;
|
|
@@ -1935,16 +1932,16 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
1935
1932
|
// Except that Perl allows - anywhere.
|
|
1936
1933
|
if ((*s)[0] == '-' && !first && !(flags_&PerlX) &&
|
|
1937
1934
|
(s->size() == 1 || (*s)[1] != ']')) {
|
|
1938
|
-
|
|
1935
|
+
absl::string_view t = *s;
|
|
1939
1936
|
t.remove_prefix(1); // '-'
|
|
1940
1937
|
Rune r;
|
|
1941
|
-
int n =
|
|
1938
|
+
int n = StringViewToRune(&r, &t, status);
|
|
1942
1939
|
if (n < 0) {
|
|
1943
1940
|
re->Decref();
|
|
1944
1941
|
return false;
|
|
1945
1942
|
}
|
|
1946
1943
|
status->set_code(kRegexpBadCharRange);
|
|
1947
|
-
status->set_error_arg(
|
|
1944
|
+
status->set_error_arg(absl::string_view(s->data(), 1+n));
|
|
1948
1945
|
re->Decref();
|
|
1949
1946
|
return false;
|
|
1950
1947
|
}
|
|
@@ -1979,7 +1976,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
1979
1976
|
}
|
|
1980
1977
|
|
|
1981
1978
|
// Look for Perl character class symbols (extension).
|
|
1982
|
-
const UGroup
|
|
1979
|
+
const UGroup* g = MaybeParsePerlCCEscape(s, flags_);
|
|
1983
1980
|
if (g != NULL) {
|
|
1984
1981
|
AddUGroup(re->ccb_, g, g->sign, flags_);
|
|
1985
1982
|
continue;
|
|
@@ -2014,7 +2011,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
2014
2011
|
}
|
|
2015
2012
|
|
|
2016
2013
|
// Returns whether name is a valid capture name.
|
|
2017
|
-
static bool IsValidCaptureName(
|
|
2014
|
+
static bool IsValidCaptureName(absl::string_view name) {
|
|
2018
2015
|
if (name.empty())
|
|
2019
2016
|
return false;
|
|
2020
2017
|
|
|
@@ -2028,17 +2025,17 @@ static bool IsValidCaptureName(const StringPiece& name) {
|
|
|
2028
2025
|
// if they start doing that for capture names, we won't follow suit.
|
|
2029
2026
|
static const CharClass* const cc = []() {
|
|
2030
2027
|
CharClassBuilder ccb;
|
|
2031
|
-
for (
|
|
2028
|
+
for (absl::string_view group :
|
|
2032
2029
|
{"Lu", "Ll", "Lt", "Lm", "Lo", "Nl", "Mn", "Mc", "Nd", "Pc"})
|
|
2033
2030
|
AddUGroup(&ccb, LookupGroup(group, unicode_groups, num_unicode_groups),
|
|
2034
2031
|
+1, Regexp::NoParseFlags);
|
|
2035
2032
|
return ccb.GetCharClass();
|
|
2036
2033
|
}();
|
|
2037
2034
|
|
|
2038
|
-
|
|
2035
|
+
absl::string_view t = name;
|
|
2039
2036
|
Rune r;
|
|
2040
2037
|
while (!t.empty()) {
|
|
2041
|
-
if (
|
|
2038
|
+
if (StringViewToRune(&r, &t, NULL) < 0)
|
|
2042
2039
|
return false;
|
|
2043
2040
|
if (cc->Contains(r))
|
|
2044
2041
|
continue;
|
|
@@ -2052,8 +2049,8 @@ static bool IsValidCaptureName(const StringPiece& name) {
|
|
|
2052
2049
|
// The caller must check that s begins with "(?".
|
|
2053
2050
|
// Returns true on success. If the Perl flag is not
|
|
2054
2051
|
// well-formed or not supported, sets status_ and returns false.
|
|
2055
|
-
bool Regexp::ParseState::ParsePerlFlags(
|
|
2056
|
-
|
|
2052
|
+
bool Regexp::ParseState::ParsePerlFlags(absl::string_view* s) {
|
|
2053
|
+
absl::string_view t = *s;
|
|
2057
2054
|
|
|
2058
2055
|
// Caller is supposed to check this.
|
|
2059
2056
|
if (!(flags_ & PerlX) || t.size() < 2 || t[0] != '(' || t[1] != '?') {
|
|
@@ -2082,7 +2079,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
|
|
|
2082
2079
|
if (t.size() > 2 && t[0] == 'P' && t[1] == '<') {
|
|
2083
2080
|
// Pull out name.
|
|
2084
2081
|
size_t end = t.find('>', 2);
|
|
2085
|
-
if (end ==
|
|
2082
|
+
if (end == absl::string_view::npos) {
|
|
2086
2083
|
if (!IsValidUTF8(*s, status_))
|
|
2087
2084
|
return false;
|
|
2088
2085
|
status_->set_code(kRegexpBadNamedCapture);
|
|
@@ -2091,8 +2088,8 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
|
|
|
2091
2088
|
}
|
|
2092
2089
|
|
|
2093
2090
|
// t is "P<name>...", t[end] == '>'
|
|
2094
|
-
|
|
2095
|
-
|
|
2091
|
+
absl::string_view capture(t.data()-2, end+3); // "(?P<name>"
|
|
2092
|
+
absl::string_view name(t.data()+2, end-2); // "name"
|
|
2096
2093
|
if (!IsValidUTF8(name, status_))
|
|
2097
2094
|
return false;
|
|
2098
2095
|
if (!IsValidCaptureName(name)) {
|
|
@@ -2118,7 +2115,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
|
|
|
2118
2115
|
for (bool done = false; !done; ) {
|
|
2119
2116
|
if (t.empty())
|
|
2120
2117
|
goto BadPerlOp;
|
|
2121
|
-
if (
|
|
2118
|
+
if (StringViewToRune(&c, &t, status_) < 0)
|
|
2122
2119
|
return false;
|
|
2123
2120
|
switch (c) {
|
|
2124
2121
|
default:
|
|
@@ -2191,7 +2188,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
|
|
|
2191
2188
|
BadPerlOp:
|
|
2192
2189
|
status_->set_code(kRegexpBadPerlOp);
|
|
2193
2190
|
status_->set_error_arg(
|
|
2194
|
-
|
|
2191
|
+
absl::string_view(s->data(), static_cast<size_t>(t.data() - s->data())));
|
|
2195
2192
|
return false;
|
|
2196
2193
|
}
|
|
2197
2194
|
|
|
@@ -2199,7 +2196,7 @@ BadPerlOp:
|
|
|
2199
2196
|
// into UTF8 encoding in string.
|
|
2200
2197
|
// Can't use EncodingUtils::EncodeLatin1AsUTF8 because it is
|
|
2201
2198
|
// deprecated and because it rejects code points 0x80-0x9F.
|
|
2202
|
-
void ConvertLatin1ToUTF8(
|
|
2199
|
+
void ConvertLatin1ToUTF8(absl::string_view latin1, std::string* utf) {
|
|
2203
2200
|
char buf[UTFmax];
|
|
2204
2201
|
|
|
2205
2202
|
utf->clear();
|
|
@@ -2214,7 +2211,7 @@ void ConvertLatin1ToUTF8(const StringPiece& latin1, std::string* utf) {
|
|
|
2214
2211
|
// returning the corresponding Regexp tree.
|
|
2215
2212
|
// The caller must Decref the return value when done with it.
|
|
2216
2213
|
// Returns NULL on error.
|
|
2217
|
-
Regexp* Regexp::Parse(
|
|
2214
|
+
Regexp* Regexp::Parse(absl::string_view s, ParseFlags global_flags,
|
|
2218
2215
|
RegexpStatus* status) {
|
|
2219
2216
|
// Make status non-NULL (easier on everyone else).
|
|
2220
2217
|
RegexpStatus xstatus;
|
|
@@ -2222,7 +2219,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2222
2219
|
status = &xstatus;
|
|
2223
2220
|
|
|
2224
2221
|
ParseState ps(global_flags, s, status);
|
|
2225
|
-
|
|
2222
|
+
absl::string_view t = s;
|
|
2226
2223
|
|
|
2227
2224
|
// Convert regexp to UTF-8 (easier on the rest of the parser).
|
|
2228
2225
|
if (global_flags & Latin1) {
|
|
@@ -2236,7 +2233,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2236
2233
|
// Special parse loop for literal string.
|
|
2237
2234
|
while (!t.empty()) {
|
|
2238
2235
|
Rune r;
|
|
2239
|
-
if (
|
|
2236
|
+
if (StringViewToRune(&r, &t, status) < 0)
|
|
2240
2237
|
return NULL;
|
|
2241
2238
|
if (!ps.PushLiteral(r))
|
|
2242
2239
|
return NULL;
|
|
@@ -2244,13 +2241,13 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2244
2241
|
return ps.DoFinish();
|
|
2245
2242
|
}
|
|
2246
2243
|
|
|
2247
|
-
|
|
2244
|
+
absl::string_view lastunary = absl::string_view();
|
|
2248
2245
|
while (!t.empty()) {
|
|
2249
|
-
|
|
2246
|
+
absl::string_view isunary = absl::string_view();
|
|
2250
2247
|
switch (t[0]) {
|
|
2251
2248
|
default: {
|
|
2252
2249
|
Rune r;
|
|
2253
|
-
if (
|
|
2250
|
+
if (StringViewToRune(&r, &t, status) < 0)
|
|
2254
2251
|
return NULL;
|
|
2255
2252
|
if (!ps.PushLiteral(r))
|
|
2256
2253
|
return NULL;
|
|
@@ -2269,7 +2266,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2269
2266
|
if (!ps.DoLeftParenNoCapture())
|
|
2270
2267
|
return NULL;
|
|
2271
2268
|
} else {
|
|
2272
|
-
if (!ps.DoLeftParen(
|
|
2269
|
+
if (!ps.DoLeftParen(absl::string_view()))
|
|
2273
2270
|
return NULL;
|
|
2274
2271
|
}
|
|
2275
2272
|
t.remove_prefix(1); // '('
|
|
@@ -2325,7 +2322,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2325
2322
|
op = kRegexpQuest;
|
|
2326
2323
|
goto Rep;
|
|
2327
2324
|
Rep:
|
|
2328
|
-
|
|
2325
|
+
absl::string_view opstr = t;
|
|
2329
2326
|
bool nongreedy = false;
|
|
2330
2327
|
t.remove_prefix(1); // '*' or '+' or '?'
|
|
2331
2328
|
if (ps.flags() & PerlX) {
|
|
@@ -2338,14 +2335,14 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2338
2335
|
// a** is a syntax error, not a double-star.
|
|
2339
2336
|
// (and a++ means something else entirely, which we don't support!)
|
|
2340
2337
|
status->set_code(kRegexpRepeatOp);
|
|
2341
|
-
status->set_error_arg(
|
|
2338
|
+
status->set_error_arg(absl::string_view(
|
|
2342
2339
|
lastunary.data(),
|
|
2343
2340
|
static_cast<size_t>(t.data() - lastunary.data())));
|
|
2344
2341
|
return NULL;
|
|
2345
2342
|
}
|
|
2346
2343
|
}
|
|
2347
|
-
opstr =
|
|
2348
|
-
|
|
2344
|
+
opstr = absl::string_view(opstr.data(),
|
|
2345
|
+
static_cast<size_t>(t.data() - opstr.data()));
|
|
2349
2346
|
if (!ps.PushRepeatOp(op, opstr, nongreedy))
|
|
2350
2347
|
return NULL;
|
|
2351
2348
|
isunary = opstr;
|
|
@@ -2354,7 +2351,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2354
2351
|
|
|
2355
2352
|
case '{': { // Counted repetition.
|
|
2356
2353
|
int lo, hi;
|
|
2357
|
-
|
|
2354
|
+
absl::string_view opstr = t;
|
|
2358
2355
|
if (!MaybeParseRepetition(&t, &lo, &hi)) {
|
|
2359
2356
|
// Treat like a literal.
|
|
2360
2357
|
if (!ps.PushLiteral('{'))
|
|
@@ -2371,14 +2368,14 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2371
2368
|
if (!lastunary.empty()) {
|
|
2372
2369
|
// Not allowed to stack repetition operators.
|
|
2373
2370
|
status->set_code(kRegexpRepeatOp);
|
|
2374
|
-
status->set_error_arg(
|
|
2371
|
+
status->set_error_arg(absl::string_view(
|
|
2375
2372
|
lastunary.data(),
|
|
2376
2373
|
static_cast<size_t>(t.data() - lastunary.data())));
|
|
2377
2374
|
return NULL;
|
|
2378
2375
|
}
|
|
2379
2376
|
}
|
|
2380
|
-
opstr =
|
|
2381
|
-
|
|
2377
|
+
opstr = absl::string_view(opstr.data(),
|
|
2378
|
+
static_cast<size_t>(t.data() - opstr.data()));
|
|
2382
2379
|
if (!ps.PushRepetition(lo, hi, opstr, nongreedy))
|
|
2383
2380
|
return NULL;
|
|
2384
2381
|
isunary = opstr;
|
|
@@ -2428,7 +2425,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2428
2425
|
break;
|
|
2429
2426
|
}
|
|
2430
2427
|
Rune r;
|
|
2431
|
-
if (
|
|
2428
|
+
if (StringViewToRune(&r, &t, status) < 0)
|
|
2432
2429
|
return NULL;
|
|
2433
2430
|
if (!ps.PushLiteral(r))
|
|
2434
2431
|
return NULL;
|
|
@@ -2454,7 +2451,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2454
2451
|
}
|
|
2455
2452
|
}
|
|
2456
2453
|
|
|
2457
|
-
const UGroup
|
|
2454
|
+
const UGroup* g = MaybeParsePerlCCEscape(&t, ps.flags());
|
|
2458
2455
|
if (g != NULL) {
|
|
2459
2456
|
Regexp* re = new Regexp(kRegexpCharClass, ps.flags() & ~FoldCase);
|
|
2460
2457
|
re->ccb_ = new CharClassBuilder;
|