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
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
#include <utility>
|
|
11
11
|
#include <vector>
|
|
12
12
|
|
|
13
|
-
#include "
|
|
13
|
+
#include "absl/strings/str_format.h"
|
|
14
14
|
#include "util/logging.h"
|
|
15
|
-
#include "util/strutil.h"
|
|
16
15
|
#include "util/utf.h"
|
|
17
16
|
#include "re2/re2.h"
|
|
18
17
|
#include "re2/unicode_casefold.h"
|
|
@@ -664,7 +663,7 @@ std::string Prefilter::DebugString() const {
|
|
|
664
663
|
switch (op_) {
|
|
665
664
|
default:
|
|
666
665
|
LOG(DFATAL) << "Bad op in Prefilter::DebugString: " << op_;
|
|
667
|
-
return
|
|
666
|
+
return absl::StrFormat("op%d", op_);
|
|
668
667
|
case NONE:
|
|
669
668
|
return "*no-matches*";
|
|
670
669
|
case ATOM:
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
#include <utility>
|
|
14
14
|
#include <vector>
|
|
15
15
|
|
|
16
|
-
#include "
|
|
16
|
+
#include "absl/strings/str_format.h"
|
|
17
17
|
#include "util/logging.h"
|
|
18
|
-
#include "util/strutil.h"
|
|
19
18
|
#include "re2/prefilter.h"
|
|
20
19
|
#include "re2/re2.h"
|
|
21
20
|
|
|
@@ -80,14 +79,14 @@ Prefilter* PrefilterTree::CanonicalNode(NodeMap* nodes, Prefilter* node) {
|
|
|
80
79
|
|
|
81
80
|
std::string PrefilterTree::NodeString(Prefilter* node) const {
|
|
82
81
|
// Adding the operation disambiguates AND/OR/atom nodes.
|
|
83
|
-
std::string s =
|
|
82
|
+
std::string s = absl::StrFormat("%d", node->op()) + ":";
|
|
84
83
|
if (node->op() == Prefilter::ATOM) {
|
|
85
84
|
s += node->atom();
|
|
86
85
|
} else {
|
|
87
86
|
for (size_t i = 0; i < node->subs()->size(); i++) {
|
|
88
87
|
if (i > 0)
|
|
89
88
|
s += ',';
|
|
90
|
-
s +=
|
|
89
|
+
s += absl::StrFormat("%d", (*node->subs())[i]->unique_id());
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
return s;
|
|
@@ -380,7 +379,7 @@ std::string PrefilterTree::DebugNodeString(Prefilter* node) const {
|
|
|
380
379
|
for (size_t i = 0; i < node->subs()->size(); i++) {
|
|
381
380
|
if (i > 0)
|
|
382
381
|
node_string += ',';
|
|
383
|
-
node_string +=
|
|
382
|
+
node_string += absl::StrFormat("%d", (*node->subs())[i]->unique_id());
|
|
384
383
|
node_string += ":";
|
|
385
384
|
node_string += DebugNodeString((*node->subs())[i]);
|
|
386
385
|
}
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
#include <string>
|
|
21
21
|
#include <vector>
|
|
22
22
|
|
|
23
|
-
#include "util/util.h"
|
|
24
23
|
#include "re2/prefilter.h"
|
|
25
24
|
#include "re2/sparse_array.h"
|
|
26
25
|
|
|
@@ -59,7 +58,7 @@ class PrefilterTree {
|
|
|
59
58
|
|
|
60
59
|
private:
|
|
61
60
|
typedef SparseArray<int> IntMap;
|
|
62
|
-
// TODO(junyer): Use
|
|
61
|
+
// TODO(junyer): Use absl::flat_hash_set<Prefilter*> instead?
|
|
63
62
|
// It should be trivial to get rid of the stringification...
|
|
64
63
|
typedef std::map<std::string, Prefilter*> NodeMap;
|
|
65
64
|
|
|
@@ -19,11 +19,10 @@
|
|
|
19
19
|
#include <memory>
|
|
20
20
|
#include <utility>
|
|
21
21
|
|
|
22
|
-
#include "
|
|
22
|
+
#include "absl/base/macros.h"
|
|
23
|
+
#include "absl/strings/str_format.h"
|
|
23
24
|
#include "util/logging.h"
|
|
24
|
-
#include "util/strutil.h"
|
|
25
25
|
#include "re2/bitmap256.h"
|
|
26
|
-
#include "re2/stringpiece.h"
|
|
27
26
|
|
|
28
27
|
namespace re2 {
|
|
29
28
|
|
|
@@ -74,34 +73,34 @@ void Prog::Inst::InitFail() {
|
|
|
74
73
|
std::string Prog::Inst::Dump() {
|
|
75
74
|
switch (opcode()) {
|
|
76
75
|
default:
|
|
77
|
-
return
|
|
76
|
+
return absl::StrFormat("opcode %d", static_cast<int>(opcode()));
|
|
78
77
|
|
|
79
78
|
case kInstAlt:
|
|
80
|
-
return
|
|
79
|
+
return absl::StrFormat("alt -> %d | %d", out(), out1_);
|
|
81
80
|
|
|
82
81
|
case kInstAltMatch:
|
|
83
|
-
return
|
|
82
|
+
return absl::StrFormat("altmatch -> %d | %d", out(), out1_);
|
|
84
83
|
|
|
85
84
|
case kInstByteRange:
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
return absl::StrFormat("byte%s [%02x-%02x] %d -> %d",
|
|
86
|
+
foldcase() ? "/i" : "",
|
|
87
|
+
lo_, hi_, hint(), out());
|
|
89
88
|
|
|
90
89
|
case kInstCapture:
|
|
91
|
-
return
|
|
90
|
+
return absl::StrFormat("capture %d -> %d", cap_, out());
|
|
92
91
|
|
|
93
92
|
case kInstEmptyWidth:
|
|
94
|
-
return
|
|
95
|
-
|
|
93
|
+
return absl::StrFormat("emptywidth %#x -> %d",
|
|
94
|
+
static_cast<int>(empty_), out());
|
|
96
95
|
|
|
97
96
|
case kInstMatch:
|
|
98
|
-
return
|
|
97
|
+
return absl::StrFormat("match! %d", match_id());
|
|
99
98
|
|
|
100
99
|
case kInstNop:
|
|
101
|
-
return
|
|
100
|
+
return absl::StrFormat("nop -> %d", out());
|
|
102
101
|
|
|
103
102
|
case kInstFail:
|
|
104
|
-
return
|
|
103
|
+
return absl::StrFormat("fail");
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
|
|
@@ -143,7 +142,7 @@ static std::string ProgToString(Prog* prog, Workq* q) {
|
|
|
143
142
|
for (Workq::iterator i = q->begin(); i != q->end(); ++i) {
|
|
144
143
|
int id = *i;
|
|
145
144
|
Prog::Inst* ip = prog->inst(id);
|
|
146
|
-
s +=
|
|
145
|
+
s += absl::StrFormat("%d. %s\n", id, ip->Dump());
|
|
147
146
|
AddToQueue(q, ip->out());
|
|
148
147
|
if (ip->opcode() == kInstAlt || ip->opcode() == kInstAltMatch)
|
|
149
148
|
AddToQueue(q, ip->out1());
|
|
@@ -156,9 +155,9 @@ static std::string FlattenedProgToString(Prog* prog, int start) {
|
|
|
156
155
|
for (int id = start; id < prog->size(); id++) {
|
|
157
156
|
Prog::Inst* ip = prog->inst(id);
|
|
158
157
|
if (ip->last())
|
|
159
|
-
s +=
|
|
158
|
+
s += absl::StrFormat("%d. %s\n", id, ip->Dump());
|
|
160
159
|
else
|
|
161
|
-
s +=
|
|
160
|
+
s += absl::StrFormat("%d+ %s\n", id, ip->Dump());
|
|
162
161
|
}
|
|
163
162
|
return s;
|
|
164
163
|
}
|
|
@@ -189,7 +188,7 @@ std::string Prog::DumpByteMap() {
|
|
|
189
188
|
while (c < 256-1 && bytemap_[c+1] == b)
|
|
190
189
|
c++;
|
|
191
190
|
int hi = c;
|
|
192
|
-
map +=
|
|
191
|
+
map += absl::StrFormat("[%02x-%02x] -> %d\n", lo, hi, b);
|
|
193
192
|
}
|
|
194
193
|
return map;
|
|
195
194
|
}
|
|
@@ -284,7 +283,7 @@ void Prog::Optimize() {
|
|
|
284
283
|
}
|
|
285
284
|
}
|
|
286
285
|
|
|
287
|
-
uint32_t Prog::EmptyFlags(
|
|
286
|
+
uint32_t Prog::EmptyFlags(absl::string_view text, const char* p) {
|
|
288
287
|
int flags = 0;
|
|
289
288
|
|
|
290
289
|
// ^ and \A
|
|
@@ -813,7 +812,7 @@ void Prog::EmitList(int root, SparseArray<int>* rootmap,
|
|
|
813
812
|
flat->back().set_opcode(kInstAltMatch);
|
|
814
813
|
flat->back().set_out(static_cast<int>(flat->size()));
|
|
815
814
|
flat->back().out1_ = static_cast<uint32_t>(flat->size())+1;
|
|
816
|
-
|
|
815
|
+
ABSL_FALLTHROUGH_INTENDED;
|
|
817
816
|
|
|
818
817
|
case kInstAlt:
|
|
819
818
|
stk->push_back(ip->out1());
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
#include <stdint.h>
|
|
13
13
|
#include <functional>
|
|
14
|
-
#include <mutex>
|
|
15
14
|
#include <string>
|
|
16
15
|
#include <vector>
|
|
17
16
|
#include <type_traits>
|
|
18
17
|
|
|
19
|
-
#include "
|
|
18
|
+
#include "absl/base/call_once.h"
|
|
19
|
+
#include "absl/strings/string_view.h"
|
|
20
20
|
#include "util/logging.h"
|
|
21
21
|
#include "re2/pod_array.h"
|
|
22
22
|
#include "re2/re2.h"
|
|
@@ -249,7 +249,7 @@ class Prog {
|
|
|
249
249
|
|
|
250
250
|
// Returns the set of kEmpty flags that are in effect at
|
|
251
251
|
// position p within context.
|
|
252
|
-
static uint32_t EmptyFlags(
|
|
252
|
+
static uint32_t EmptyFlags(absl::string_view context, const char* p);
|
|
253
253
|
|
|
254
254
|
// Returns whether byte c is a word character: ASCII only.
|
|
255
255
|
// Used by the implementation of \b and \B.
|
|
@@ -274,15 +274,15 @@ class Prog {
|
|
|
274
274
|
// If a particular submatch is not matched during the regexp match,
|
|
275
275
|
// it is set to NULL.
|
|
276
276
|
//
|
|
277
|
-
// Matching text ==
|
|
277
|
+
// Matching text == absl::string_view() is treated as any other empty
|
|
278
278
|
// string, but note that on return, it will not be possible to distinguish
|
|
279
279
|
// submatches that matched that empty string from submatches that didn't
|
|
280
280
|
// match anything. Either way, match[i] == NULL.
|
|
281
281
|
|
|
282
282
|
// Search using NFA: can find submatches but kind of slow.
|
|
283
|
-
bool SearchNFA(
|
|
284
|
-
Anchor anchor, MatchKind kind,
|
|
285
|
-
|
|
283
|
+
bool SearchNFA(absl::string_view text, absl::string_view context,
|
|
284
|
+
Anchor anchor, MatchKind kind, absl::string_view* match,
|
|
285
|
+
int nmatch);
|
|
286
286
|
|
|
287
287
|
// Search using DFA: much faster than NFA but only finds
|
|
288
288
|
// end of match and can use a lot more memory.
|
|
@@ -290,8 +290,8 @@ class Prog {
|
|
|
290
290
|
// If the DFA runs out of memory, sets *failed to true and returns false.
|
|
291
291
|
// If matches != NULL and kind == kManyMatch and there is a match,
|
|
292
292
|
// SearchDFA fills matches with the match IDs of the final matching state.
|
|
293
|
-
bool SearchDFA(
|
|
294
|
-
Anchor anchor, MatchKind kind,
|
|
293
|
+
bool SearchDFA(absl::string_view text, absl::string_view context,
|
|
294
|
+
Anchor anchor, MatchKind kind, absl::string_view* match0,
|
|
295
295
|
bool* failed, SparseSet* matches);
|
|
296
296
|
|
|
297
297
|
// The callback issued after building each DFA state with BuildEntireDFA().
|
|
@@ -321,16 +321,16 @@ class Prog {
|
|
|
321
321
|
// but much faster than NFA (competitive with PCRE)
|
|
322
322
|
// for those expressions.
|
|
323
323
|
bool IsOnePass();
|
|
324
|
-
bool SearchOnePass(
|
|
325
|
-
Anchor anchor, MatchKind kind,
|
|
326
|
-
|
|
324
|
+
bool SearchOnePass(absl::string_view text, absl::string_view context,
|
|
325
|
+
Anchor anchor, MatchKind kind, absl::string_view* match,
|
|
326
|
+
int nmatch);
|
|
327
327
|
|
|
328
328
|
// Bit-state backtracking. Fast on small cases but uses memory
|
|
329
329
|
// proportional to the product of the list count and the text size.
|
|
330
330
|
bool CanBitState() { return list_heads_.data() != NULL; }
|
|
331
|
-
bool SearchBitState(
|
|
332
|
-
Anchor anchor, MatchKind kind,
|
|
333
|
-
|
|
331
|
+
bool SearchBitState(absl::string_view text, absl::string_view context,
|
|
332
|
+
Anchor anchor, MatchKind kind, absl::string_view* match,
|
|
333
|
+
int nmatch);
|
|
334
334
|
|
|
335
335
|
static const int kMaxOnePassCapture = 5; // $0 through $4
|
|
336
336
|
|
|
@@ -340,10 +340,9 @@ class Prog {
|
|
|
340
340
|
// It is also recursive, so can't use in production (will overflow stacks).
|
|
341
341
|
// The name "Unsafe" here is supposed to be a flag that
|
|
342
342
|
// you should not be using this function.
|
|
343
|
-
bool UnsafeSearchBacktrack(
|
|
344
|
-
const StringPiece& context,
|
|
343
|
+
bool UnsafeSearchBacktrack(absl::string_view text, absl::string_view context,
|
|
345
344
|
Anchor anchor, MatchKind kind,
|
|
346
|
-
|
|
345
|
+
absl::string_view* match, int nmatch);
|
|
347
346
|
|
|
348
347
|
// Computes range for any strings matching regexp. The min and max can in
|
|
349
348
|
// some cases be arbitrarily precise, so the caller gets to specify the
|
|
@@ -444,8 +443,8 @@ class Prog {
|
|
|
444
443
|
|
|
445
444
|
uint8_t bytemap_[256]; // map from input bytes to byte classes
|
|
446
445
|
|
|
447
|
-
|
|
448
|
-
|
|
446
|
+
absl::once_flag dfa_first_once_;
|
|
447
|
+
absl::once_flag dfa_longest_once_;
|
|
449
448
|
|
|
450
449
|
Prog(const Prog&) = delete;
|
|
451
450
|
Prog& operator=(const Prog&) = delete;
|
|
@@ -455,10 +454,10 @@ class Prog {
|
|
|
455
454
|
// that don't allow comparisons between different objects - not even if
|
|
456
455
|
// those objects are views into the same string! Thus, we provide these
|
|
457
456
|
// conversion functions for convenience.
|
|
458
|
-
static inline const char* BeginPtr(
|
|
457
|
+
static inline const char* BeginPtr(absl::string_view s) {
|
|
459
458
|
return s.data();
|
|
460
459
|
}
|
|
461
|
-
static inline const char* EndPtr(
|
|
460
|
+
static inline const char* EndPtr(absl::string_view s) {
|
|
462
461
|
return s.data() + s.size();
|
|
463
462
|
}
|
|
464
463
|
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
#include <algorithm>
|
|
22
22
|
#include <atomic>
|
|
23
23
|
#include <iterator>
|
|
24
|
-
#include <mutex>
|
|
25
24
|
#include <string>
|
|
26
25
|
#include <utility>
|
|
27
26
|
#include <vector>
|
|
28
27
|
|
|
29
|
-
#include "
|
|
28
|
+
#include "absl/base/macros.h"
|
|
29
|
+
#include "absl/container/fixed_array.h"
|
|
30
|
+
#include "absl/strings/str_format.h"
|
|
30
31
|
#include "util/logging.h"
|
|
31
32
|
#include "util/strutil.h"
|
|
32
33
|
#include "util/utf.h"
|
|
@@ -129,7 +130,7 @@ static RE2::ErrorCode RegexpErrorToRE2(re2::RegexpStatusCode code) {
|
|
|
129
130
|
return RE2::ErrorInternal;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
static std::string trunc(
|
|
133
|
+
static std::string trunc(absl::string_view pattern) {
|
|
133
134
|
if (pattern.size() < 100)
|
|
134
135
|
return std::string(pattern);
|
|
135
136
|
return std::string(pattern.substr(0, 100)) + "...";
|
|
@@ -144,11 +145,11 @@ RE2::RE2(const std::string& pattern) {
|
|
|
144
145
|
Init(pattern, DefaultOptions);
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
RE2::RE2(
|
|
148
|
+
RE2::RE2(absl::string_view pattern) {
|
|
148
149
|
Init(pattern, DefaultOptions);
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
RE2::RE2(
|
|
152
|
+
RE2::RE2(absl::string_view pattern, const Options& options) {
|
|
152
153
|
Init(pattern, options);
|
|
153
154
|
}
|
|
154
155
|
|
|
@@ -196,9 +197,9 @@ int RE2::Options::ParseFlags() const {
|
|
|
196
197
|
return flags;
|
|
197
198
|
}
|
|
198
199
|
|
|
199
|
-
void RE2::Init(
|
|
200
|
-
static
|
|
201
|
-
|
|
200
|
+
void RE2::Init(absl::string_view pattern, const Options& options) {
|
|
201
|
+
static absl::once_flag empty_once;
|
|
202
|
+
absl::call_once(empty_once, []() {
|
|
202
203
|
(void) new (empty_storage) EmptyStorage;
|
|
203
204
|
});
|
|
204
205
|
|
|
@@ -261,7 +262,7 @@ void RE2::Init(const StringPiece& pattern, const Options& options) {
|
|
|
261
262
|
|
|
262
263
|
// We used to compute this lazily, but it's used during the
|
|
263
264
|
// typical control flow for a match call, so we now compute
|
|
264
|
-
// it eagerly, which avoids the overhead of
|
|
265
|
+
// it eagerly, which avoids the overhead of absl::once_flag.
|
|
265
266
|
num_captures_ = suffix_regexp_->NumCaptures();
|
|
266
267
|
|
|
267
268
|
// Could delay this until the first match call that
|
|
@@ -274,7 +275,7 @@ void RE2::Init(const StringPiece& pattern, const Options& options) {
|
|
|
274
275
|
|
|
275
276
|
// Returns rprog_, computing it if needed.
|
|
276
277
|
re2::Prog* RE2::ReverseProg() const {
|
|
277
|
-
|
|
278
|
+
absl::call_once(rprog_once_, [](const RE2* re) {
|
|
278
279
|
re->rprog_ =
|
|
279
280
|
re->suffix_regexp_->CompileToReverseProg(re->options_.max_mem() / 3);
|
|
280
281
|
if (re->rprog_ == NULL) {
|
|
@@ -382,7 +383,7 @@ int RE2::ReverseProgramFanout(std::vector<int>* histogram) const {
|
|
|
382
383
|
|
|
383
384
|
// Returns named_groups_, computing it if needed.
|
|
384
385
|
const std::map<std::string, int>& RE2::NamedCapturingGroups() const {
|
|
385
|
-
|
|
386
|
+
absl::call_once(named_groups_once_, [](const RE2* re) {
|
|
386
387
|
if (re->suffix_regexp_ != NULL)
|
|
387
388
|
re->named_groups_ = re->suffix_regexp_->NamedCaptures();
|
|
388
389
|
if (re->named_groups_ == NULL)
|
|
@@ -393,7 +394,7 @@ const std::map<std::string, int>& RE2::NamedCapturingGroups() const {
|
|
|
393
394
|
|
|
394
395
|
// Returns group_names_, computing it if needed.
|
|
395
396
|
const std::map<int, std::string>& RE2::CapturingGroupNames() const {
|
|
396
|
-
|
|
397
|
+
absl::call_once(group_names_once_, [](const RE2* re) {
|
|
397
398
|
if (re->suffix_regexp_ != NULL)
|
|
398
399
|
re->group_names_ = re->suffix_regexp_->CaptureNames();
|
|
399
400
|
if (re->group_names_ == NULL)
|
|
@@ -404,17 +405,17 @@ const std::map<int, std::string>& RE2::CapturingGroupNames() const {
|
|
|
404
405
|
|
|
405
406
|
/***** Convenience interfaces *****/
|
|
406
407
|
|
|
407
|
-
bool RE2::FullMatchN(
|
|
408
|
+
bool RE2::FullMatchN(absl::string_view text, const RE2& re,
|
|
408
409
|
const Arg* const args[], int n) {
|
|
409
410
|
return re.DoMatch(text, ANCHOR_BOTH, NULL, args, n);
|
|
410
411
|
}
|
|
411
412
|
|
|
412
|
-
bool RE2::PartialMatchN(
|
|
413
|
+
bool RE2::PartialMatchN(absl::string_view text, const RE2& re,
|
|
413
414
|
const Arg* const args[], int n) {
|
|
414
415
|
return re.DoMatch(text, UNANCHORED, NULL, args, n);
|
|
415
416
|
}
|
|
416
417
|
|
|
417
|
-
bool RE2::ConsumeN(
|
|
418
|
+
bool RE2::ConsumeN(absl::string_view* input, const RE2& re,
|
|
418
419
|
const Arg* const args[], int n) {
|
|
419
420
|
size_t consumed;
|
|
420
421
|
if (re.DoMatch(*input, ANCHOR_START, &consumed, args, n)) {
|
|
@@ -425,7 +426,7 @@ bool RE2::ConsumeN(StringPiece* input, const RE2& re,
|
|
|
425
426
|
}
|
|
426
427
|
}
|
|
427
428
|
|
|
428
|
-
bool RE2::FindAndConsumeN(
|
|
429
|
+
bool RE2::FindAndConsumeN(absl::string_view* input, const RE2& re,
|
|
429
430
|
const Arg* const args[], int n) {
|
|
430
431
|
size_t consumed;
|
|
431
432
|
if (re.DoMatch(*input, UNANCHORED, &consumed, args, n)) {
|
|
@@ -438,12 +439,12 @@ bool RE2::FindAndConsumeN(StringPiece* input, const RE2& re,
|
|
|
438
439
|
|
|
439
440
|
bool RE2::Replace(std::string* str,
|
|
440
441
|
const RE2& re,
|
|
441
|
-
|
|
442
|
-
|
|
442
|
+
absl::string_view rewrite) {
|
|
443
|
+
absl::string_view vec[kVecSize];
|
|
443
444
|
int nvec = 1 + MaxSubmatch(rewrite);
|
|
444
445
|
if (nvec > 1 + re.NumberOfCapturingGroups())
|
|
445
446
|
return false;
|
|
446
|
-
if (nvec > static_cast<int>(
|
|
447
|
+
if (nvec > static_cast<int>(ABSL_ARRAYSIZE(vec)))
|
|
447
448
|
return false;
|
|
448
449
|
if (!re.Match(*str, 0, str->size(), UNANCHORED, vec, nvec))
|
|
449
450
|
return false;
|
|
@@ -460,12 +461,12 @@ bool RE2::Replace(std::string* str,
|
|
|
460
461
|
|
|
461
462
|
int RE2::GlobalReplace(std::string* str,
|
|
462
463
|
const RE2& re,
|
|
463
|
-
|
|
464
|
-
|
|
464
|
+
absl::string_view rewrite) {
|
|
465
|
+
absl::string_view vec[kVecSize];
|
|
465
466
|
int nvec = 1 + MaxSubmatch(rewrite);
|
|
466
467
|
if (nvec > 1 + re.NumberOfCapturingGroups())
|
|
467
468
|
return false;
|
|
468
|
-
if (nvec > static_cast<int>(
|
|
469
|
+
if (nvec > static_cast<int>(ABSL_ARRAYSIZE(vec)))
|
|
469
470
|
return false;
|
|
470
471
|
|
|
471
472
|
const char* p = str->data();
|
|
@@ -528,15 +529,15 @@ int RE2::GlobalReplace(std::string* str,
|
|
|
528
529
|
return count;
|
|
529
530
|
}
|
|
530
531
|
|
|
531
|
-
bool RE2::Extract(
|
|
532
|
+
bool RE2::Extract(absl::string_view text,
|
|
532
533
|
const RE2& re,
|
|
533
|
-
|
|
534
|
+
absl::string_view rewrite,
|
|
534
535
|
std::string* out) {
|
|
535
|
-
|
|
536
|
+
absl::string_view vec[kVecSize];
|
|
536
537
|
int nvec = 1 + MaxSubmatch(rewrite);
|
|
537
538
|
if (nvec > 1 + re.NumberOfCapturingGroups())
|
|
538
539
|
return false;
|
|
539
|
-
if (nvec > static_cast<int>(
|
|
540
|
+
if (nvec > static_cast<int>(ABSL_ARRAYSIZE(vec)))
|
|
540
541
|
return false;
|
|
541
542
|
if (!re.Match(text, 0, text.size(), UNANCHORED, vec, nvec))
|
|
542
543
|
return false;
|
|
@@ -545,7 +546,7 @@ bool RE2::Extract(const StringPiece& text,
|
|
|
545
546
|
return re.Rewrite(out, rewrite, vec, nvec);
|
|
546
547
|
}
|
|
547
548
|
|
|
548
|
-
std::string RE2::QuoteMeta(
|
|
549
|
+
std::string RE2::QuoteMeta(absl::string_view unquoted) {
|
|
549
550
|
std::string result;
|
|
550
551
|
result.reserve(unquoted.size() << 1);
|
|
551
552
|
|
|
@@ -644,11 +645,11 @@ static int ascii_strcasecmp(const char* a, const char* b, size_t len) {
|
|
|
644
645
|
|
|
645
646
|
/***** Actual matching and rewriting code *****/
|
|
646
647
|
|
|
647
|
-
bool RE2::Match(
|
|
648
|
+
bool RE2::Match(absl::string_view text,
|
|
648
649
|
size_t startpos,
|
|
649
650
|
size_t endpos,
|
|
650
651
|
Anchor re_anchor,
|
|
651
|
-
|
|
652
|
+
absl::string_view* submatch,
|
|
652
653
|
int nsubmatch) const {
|
|
653
654
|
if (!ok()) {
|
|
654
655
|
if (options_.log_errors())
|
|
@@ -665,7 +666,7 @@ bool RE2::Match(const StringPiece& text,
|
|
|
665
666
|
return false;
|
|
666
667
|
}
|
|
667
668
|
|
|
668
|
-
|
|
669
|
+
absl::string_view subtext = text;
|
|
669
670
|
subtext.remove_prefix(startpos);
|
|
670
671
|
subtext.remove_suffix(text.size() - endpos);
|
|
671
672
|
|
|
@@ -673,8 +674,8 @@ bool RE2::Match(const StringPiece& text,
|
|
|
673
674
|
|
|
674
675
|
// Don't ask for the location if we won't use it.
|
|
675
676
|
// SearchDFA can do extra optimizations in that case.
|
|
676
|
-
|
|
677
|
-
|
|
677
|
+
absl::string_view match;
|
|
678
|
+
absl::string_view* matchp = &match;
|
|
678
679
|
if (nsubmatch == 0)
|
|
679
680
|
matchp = NULL;
|
|
680
681
|
|
|
@@ -857,7 +858,7 @@ bool RE2::Match(const StringPiece& text,
|
|
|
857
858
|
if (ncap == 1)
|
|
858
859
|
submatch[0] = match;
|
|
859
860
|
} else {
|
|
860
|
-
|
|
861
|
+
absl::string_view subtext1;
|
|
861
862
|
if (skipped_test) {
|
|
862
863
|
// DFA ran out of memory or was skipped:
|
|
863
864
|
// need to search in entire original text.
|
|
@@ -895,17 +896,17 @@ bool RE2::Match(const StringPiece& text,
|
|
|
895
896
|
|
|
896
897
|
// Adjust overall match for required prefix that we stripped off.
|
|
897
898
|
if (prefixlen > 0 && nsubmatch > 0)
|
|
898
|
-
submatch[0] =
|
|
899
|
-
|
|
899
|
+
submatch[0] = absl::string_view(submatch[0].data() - prefixlen,
|
|
900
|
+
submatch[0].size() + prefixlen);
|
|
900
901
|
|
|
901
902
|
// Zero submatches that don't exist in the regexp.
|
|
902
903
|
for (int i = ncap; i < nsubmatch; i++)
|
|
903
|
-
submatch[i] =
|
|
904
|
+
submatch[i] = absl::string_view();
|
|
904
905
|
return true;
|
|
905
906
|
}
|
|
906
907
|
|
|
907
|
-
// Internal matcher - like Match() but takes Args not
|
|
908
|
-
bool RE2::DoMatch(
|
|
908
|
+
// Internal matcher - like Match() but takes Args not string_views.
|
|
909
|
+
bool RE2::DoMatch(absl::string_view text,
|
|
909
910
|
Anchor re_anchor,
|
|
910
911
|
size_t* consumed,
|
|
911
912
|
const Arg* const* args,
|
|
@@ -928,19 +929,10 @@ bool RE2::DoMatch(const StringPiece& text,
|
|
|
928
929
|
else
|
|
929
930
|
nvec = n+1;
|
|
930
931
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
StringPiece* heapvec = NULL;
|
|
934
|
-
|
|
935
|
-
if (nvec <= static_cast<int>(arraysize(stkvec))) {
|
|
936
|
-
vec = stkvec;
|
|
937
|
-
} else {
|
|
938
|
-
vec = new StringPiece[nvec];
|
|
939
|
-
heapvec = vec;
|
|
940
|
-
}
|
|
932
|
+
absl::FixedArray<absl::string_view, kVecSize> vec_storage(nvec);
|
|
933
|
+
absl::string_view* vec = vec_storage.data();
|
|
941
934
|
|
|
942
935
|
if (!Match(text, 0, text.size(), re_anchor, vec, nvec)) {
|
|
943
|
-
delete[] heapvec;
|
|
944
936
|
return false;
|
|
945
937
|
}
|
|
946
938
|
|
|
@@ -949,27 +941,24 @@ bool RE2::DoMatch(const StringPiece& text,
|
|
|
949
941
|
|
|
950
942
|
if (n == 0 || args == NULL) {
|
|
951
943
|
// We are not interested in results
|
|
952
|
-
delete[] heapvec;
|
|
953
944
|
return true;
|
|
954
945
|
}
|
|
955
946
|
|
|
956
947
|
// If we got here, we must have matched the whole pattern.
|
|
957
948
|
for (int i = 0; i < n; i++) {
|
|
958
|
-
|
|
949
|
+
absl::string_view s = vec[i+1];
|
|
959
950
|
if (!args[i]->Parse(s.data(), s.size())) {
|
|
960
951
|
// TODO: Should we indicate what the error was?
|
|
961
|
-
delete[] heapvec;
|
|
962
952
|
return false;
|
|
963
953
|
}
|
|
964
954
|
}
|
|
965
955
|
|
|
966
|
-
delete[] heapvec;
|
|
967
956
|
return true;
|
|
968
957
|
}
|
|
969
958
|
|
|
970
959
|
// Checks that the rewrite string is well-formed with respect to this
|
|
971
960
|
// regular expression.
|
|
972
|
-
bool RE2::CheckRewriteString(
|
|
961
|
+
bool RE2::CheckRewriteString(absl::string_view rewrite,
|
|
973
962
|
std::string* error) const {
|
|
974
963
|
int max_token = -1;
|
|
975
964
|
for (const char *s = rewrite.data(), *end = s + rewrite.size();
|
|
@@ -998,7 +987,7 @@ bool RE2::CheckRewriteString(const StringPiece& rewrite,
|
|
|
998
987
|
}
|
|
999
988
|
|
|
1000
989
|
if (max_token > NumberOfCapturingGroups()) {
|
|
1001
|
-
*error =
|
|
990
|
+
*error = absl::StrFormat(
|
|
1002
991
|
"Rewrite schema requests %d matches, but the regexp only has %d "
|
|
1003
992
|
"parenthesized subexpressions.",
|
|
1004
993
|
max_token, NumberOfCapturingGroups());
|
|
@@ -1009,7 +998,7 @@ bool RE2::CheckRewriteString(const StringPiece& rewrite,
|
|
|
1009
998
|
|
|
1010
999
|
// Returns the maximum submatch needed for the rewrite to be done by Replace().
|
|
1011
1000
|
// E.g. if rewrite == "foo \\2,\\1", returns 2.
|
|
1012
|
-
int RE2::MaxSubmatch(
|
|
1001
|
+
int RE2::MaxSubmatch(absl::string_view rewrite) {
|
|
1013
1002
|
int max = 0;
|
|
1014
1003
|
for (const char *s = rewrite.data(), *end = s + rewrite.size();
|
|
1015
1004
|
s < end; s++) {
|
|
@@ -1026,11 +1015,11 @@ int RE2::MaxSubmatch(const StringPiece& rewrite) {
|
|
|
1026
1015
|
return max;
|
|
1027
1016
|
}
|
|
1028
1017
|
|
|
1029
|
-
// Append the "rewrite" string, with backslash
|
|
1018
|
+
// Append the "rewrite" string, with backslash substitutions from "vec",
|
|
1030
1019
|
// to string "out".
|
|
1031
1020
|
bool RE2::Rewrite(std::string* out,
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1021
|
+
absl::string_view rewrite,
|
|
1022
|
+
const absl::string_view* vec,
|
|
1034
1023
|
int veclen) const {
|
|
1035
1024
|
for (const char *s = rewrite.data(), *end = s + rewrite.size();
|
|
1036
1025
|
s < end; s++) {
|
|
@@ -1049,7 +1038,7 @@ bool RE2::Rewrite(std::string* out,
|
|
|
1049
1038
|
}
|
|
1050
1039
|
return false;
|
|
1051
1040
|
}
|
|
1052
|
-
|
|
1041
|
+
absl::string_view snip = vec[n];
|
|
1053
1042
|
if (!snip.empty())
|
|
1054
1043
|
out->append(snip.data(), snip.size());
|
|
1055
1044
|
} else if (c == '\\') {
|
|
@@ -1081,9 +1070,9 @@ bool Parse(const char* str, size_t n, std::string* dest) {
|
|
|
1081
1070
|
}
|
|
1082
1071
|
|
|
1083
1072
|
template <>
|
|
1084
|
-
bool Parse(const char* str, size_t n,
|
|
1073
|
+
bool Parse(const char* str, size_t n, absl::string_view* dest) {
|
|
1085
1074
|
if (dest == NULL) return true;
|
|
1086
|
-
*dest =
|
|
1075
|
+
*dest = absl::string_view(str, n);
|
|
1087
1076
|
return true;
|
|
1088
1077
|
}
|
|
1089
1078
|
|