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
@@ -9,24 +9,25 @@
9
9
  #include <string.h>
10
10
  #include <string>
11
11
 
12
- #include "util/util.h"
13
- #include "util/flags.h"
12
+ #include "absl/base/macros.h"
13
+ #include "absl/flags/flag.h"
14
+ #include "absl/strings/escaping.h"
15
+ #include "absl/strings/str_format.h"
14
16
  #include "util/logging.h"
15
- #include "util/strutil.h"
16
17
  #include "re2/testing/tester.h"
17
18
  #include "re2/prog.h"
18
19
  #include "re2/re2.h"
19
20
  #include "re2/regexp.h"
20
21
 
21
- DEFINE_FLAG(bool, dump_prog, false, "dump regexp program");
22
- DEFINE_FLAG(bool, log_okay, false, "log successful runs");
23
- DEFINE_FLAG(bool, dump_rprog, false, "dump reversed regexp program");
22
+ ABSL_FLAG(bool, dump_prog, false, "dump regexp program");
23
+ ABSL_FLAG(bool, log_okay, false, "log successful runs");
24
+ ABSL_FLAG(bool, dump_rprog, false, "dump reversed regexp program");
24
25
 
25
- DEFINE_FLAG(int, max_regexp_failures, 100,
26
- "maximum number of regexp test failures (-1 = unlimited)");
26
+ ABSL_FLAG(int, max_regexp_failures, 100,
27
+ "maximum number of regexp test failures (-1 = unlimited)");
27
28
 
28
- DEFINE_FLAG(std::string, regexp_engines, "",
29
- "pattern to select regexp engines to test");
29
+ ABSL_FLAG(std::string, regexp_engines, "",
30
+ "pattern to select regexp engines to test");
30
31
 
31
32
  namespace re2 {
32
33
 
@@ -50,7 +51,7 @@ const char* engine_names[kEngineMax] = {
50
51
  // Returns the name of the engine.
51
52
  static const char* EngineName(Engine e) {
52
53
  CHECK_GE(e, 0);
53
- CHECK_LT(e, arraysize(engine_names));
54
+ CHECK_LT(e, ABSL_ARRAYSIZE(engine_names));
54
55
  CHECK(engine_names[e] != NULL);
55
56
  return engine_names[e];
56
57
  }
@@ -63,11 +64,11 @@ static uint32_t Engines() {
63
64
  if (did_parse)
64
65
  return cached_engines;
65
66
 
66
- if (GetFlag(FLAGS_regexp_engines).empty()) {
67
+ if (absl::GetFlag(FLAGS_regexp_engines).empty()) {
67
68
  cached_engines = ~0;
68
69
  } else {
69
70
  for (Engine i = static_cast<Engine>(0); i < kEngineMax; i++)
70
- if (GetFlag(FLAGS_regexp_engines).find(EngineName(i)) != std::string::npos)
71
+ if (absl::GetFlag(FLAGS_regexp_engines).find(EngineName(i)) != std::string::npos)
71
72
  cached_engines |= 1<<i;
72
73
  }
73
74
 
@@ -97,7 +98,7 @@ struct TestInstance::Result {
97
98
 
98
99
  void ClearSubmatch() {
99
100
  for (int i = 0; i < kMaxSubmatch; i++)
100
- submatch[i] = StringPiece();
101
+ submatch[i] = absl::string_view();
101
102
  }
102
103
 
103
104
  bool skipped; // test skipped: wasn't applicable
@@ -105,24 +106,24 @@ struct TestInstance::Result {
105
106
  bool untrusted; // don't really trust the answer
106
107
  bool have_submatch; // computed all submatch info
107
108
  bool have_submatch0; // computed just submatch[0]
108
- StringPiece submatch[kMaxSubmatch];
109
+ absl::string_view submatch[kMaxSubmatch];
109
110
  };
110
111
 
111
112
  typedef TestInstance::Result Result;
112
113
 
113
114
  // Formats a single capture range s in text in the form (a,b)
114
115
  // where a and b are the starting and ending offsets of s in text.
115
- static std::string FormatCapture(const StringPiece& text,
116
- const StringPiece& s) {
116
+ static std::string FormatCapture(absl::string_view text,
117
+ absl::string_view s) {
117
118
  if (s.data() == NULL)
118
119
  return "(?,?)";
119
- return StringPrintf("(%td,%td)",
120
- BeginPtr(s) - BeginPtr(text),
121
- EndPtr(s) - BeginPtr(text));
120
+ return absl::StrFormat("(%d,%d)",
121
+ BeginPtr(s) - BeginPtr(text),
122
+ EndPtr(s) - BeginPtr(text));
122
123
  }
123
124
 
124
125
  // Returns whether text contains non-ASCII (>= 0x80) bytes.
125
- static bool NonASCII(const StringPiece& text) {
126
+ static bool NonASCII(absl::string_view text) {
126
127
  for (size_t i = 0; i < text.size(); i++)
127
128
  if ((uint8_t)text[i] >= 0x80)
128
129
  return true;
@@ -174,15 +175,15 @@ static ParseMode parse_modes[] = {
174
175
  };
175
176
 
176
177
  static std::string FormatMode(Regexp::ParseFlags flags) {
177
- for (size_t i = 0; i < arraysize(parse_modes); i++)
178
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(parse_modes); i++)
178
179
  if (parse_modes[i].parse_flags == flags)
179
180
  return parse_modes[i].desc;
180
- return StringPrintf("%#x", static_cast<uint32_t>(flags));
181
+ return absl::StrFormat("%#x", static_cast<uint32_t>(flags));
181
182
  }
182
183
 
183
184
  // Constructs and saves all the matching engines that
184
185
  // will be required for the given tests.
185
- TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
186
+ TestInstance::TestInstance(absl::string_view regexp_str, Prog::MatchKind kind,
186
187
  Regexp::ParseFlags flags)
187
188
  : regexp_str_(regexp_str),
188
189
  kind_(kind),
@@ -195,14 +196,14 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
195
196
  re_(NULL),
196
197
  re2_(NULL) {
197
198
 
198
- VLOG(1) << CEscape(regexp_str);
199
+ VLOG(1) << absl::CEscape(regexp_str);
199
200
 
200
201
  // Compile regexp to prog.
201
202
  // Always required - needed for backtracking (reference implementation).
202
203
  RegexpStatus status;
203
204
  regexp_ = Regexp::Parse(regexp_str, flags, &status);
204
205
  if (regexp_ == NULL) {
205
- LOG(INFO) << "Cannot parse: " << CEscape(regexp_str_)
206
+ LOG(INFO) << "Cannot parse: " << absl::CEscape(regexp_str_)
206
207
  << " mode: " << FormatMode(flags);
207
208
  error_ = true;
208
209
  return;
@@ -210,14 +211,14 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
210
211
  num_captures_ = regexp_->NumCaptures();
211
212
  prog_ = regexp_->CompileToProg(0);
212
213
  if (prog_ == NULL) {
213
- LOG(INFO) << "Cannot compile: " << CEscape(regexp_str_);
214
+ LOG(INFO) << "Cannot compile: " << absl::CEscape(regexp_str_);
214
215
  error_ = true;
215
216
  return;
216
217
  }
217
- if (GetFlag(FLAGS_dump_prog)) {
218
+ if (absl::GetFlag(FLAGS_dump_prog)) {
218
219
  LOG(INFO) << "Prog for "
219
220
  << " regexp "
220
- << CEscape(regexp_str_)
221
+ << absl::CEscape(regexp_str_)
221
222
  << " (" << FormatKind(kind_)
222
223
  << ", " << FormatMode(flags_)
223
224
  << ")\n"
@@ -228,11 +229,11 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
228
229
  if (Engines() & ((1<<kEngineDFA)|(1<<kEngineDFA1))) {
229
230
  rprog_ = regexp_->CompileToReverseProg(0);
230
231
  if (rprog_ == NULL) {
231
- LOG(INFO) << "Cannot reverse compile: " << CEscape(regexp_str_);
232
+ LOG(INFO) << "Cannot reverse compile: " << absl::CEscape(regexp_str_);
232
233
  error_ = true;
233
234
  return;
234
235
  }
235
- if (GetFlag(FLAGS_dump_rprog))
236
+ if (absl::GetFlag(FLAGS_dump_rprog))
236
237
  LOG(INFO) << rprog_->Dump();
237
238
  }
238
239
 
@@ -256,7 +257,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
256
257
  options.set_longest_match(true);
257
258
  re2_ = new RE2(re, options);
258
259
  if (!re2_->error().empty()) {
259
- LOG(INFO) << "Cannot RE2: " << CEscape(re);
260
+ LOG(INFO) << "Cannot RE2: " << absl::CEscape(re);
260
261
  error_ = true;
261
262
  return;
262
263
  }
@@ -282,7 +283,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
282
283
  // add one more layer of parens.
283
284
  re_ = new PCRE("("+re+")", o);
284
285
  if (!re_->error().empty()) {
285
- LOG(INFO) << "Cannot PCRE: " << CEscape(re);
286
+ LOG(INFO) << "Cannot PCRE: " << absl::CEscape(re);
286
287
  error_ = true;
287
288
  return;
288
289
  }
@@ -301,11 +302,9 @@ TestInstance::~TestInstance() {
301
302
  // Runs a single search using the named engine type.
302
303
  // This interface hides all the irregularities of the various
303
304
  // engine interfaces from the rest of this file.
304
- void TestInstance::RunSearch(Engine type,
305
- const StringPiece& orig_text,
306
- const StringPiece& orig_context,
307
- Prog::Anchor anchor,
308
- Result* result) {
305
+ void TestInstance::RunSearch(Engine type, absl::string_view orig_text,
306
+ absl::string_view orig_context,
307
+ Prog::Anchor anchor, Result* result) {
309
308
  if (regexp_ == NULL) {
310
309
  result->skipped = true;
311
310
  return;
@@ -314,8 +313,8 @@ void TestInstance::RunSearch(Engine type,
314
313
  if (nsubmatch > kMaxSubmatch)
315
314
  nsubmatch = kMaxSubmatch;
316
315
 
317
- StringPiece text = orig_text;
318
- StringPiece context = orig_context;
316
+ absl::string_view text = orig_text;
317
+ absl::string_view context = orig_context;
319
318
 
320
319
  switch (type) {
321
320
  default:
@@ -368,8 +367,8 @@ void TestInstance::RunSearch(Engine type,
368
367
  result->submatch,
369
368
  &result->skipped, NULL)) {
370
369
  LOG(ERROR) << "Reverse DFA inconsistency: "
371
- << CEscape(regexp_str_)
372
- << " on " << CEscape(text);
370
+ << absl::CEscape(regexp_str_)
371
+ << " on " << absl::CEscape(text);
373
372
  result->matched = false;
374
373
  }
375
374
  }
@@ -438,19 +437,19 @@ void TestInstance::RunSearch(Engine type,
438
437
  // whitespace, not just vertical tab. Regexp::MimicsPCRE() is
439
438
  // unable to handle all cases of this, unfortunately, so just
440
439
  // catch them here. :(
441
- if (regexp_str_.find("\\v") != StringPiece::npos &&
442
- (text.find('\n') != StringPiece::npos ||
443
- text.find('\f') != StringPiece::npos ||
444
- text.find('\r') != StringPiece::npos)) {
440
+ if (regexp_str_.find("\\v") != absl::string_view::npos &&
441
+ (text.find('\n') != absl::string_view::npos ||
442
+ text.find('\f') != absl::string_view::npos ||
443
+ text.find('\r') != absl::string_view::npos)) {
445
444
  result->skipped = true;
446
445
  break;
447
446
  }
448
447
 
449
448
  // PCRE 8.34 or so started allowing vertical tab to match \s,
450
449
  // following a change made in Perl 5.18. RE2 does not.
451
- if ((regexp_str_.find("\\s") != StringPiece::npos ||
452
- regexp_str_.find("\\S") != StringPiece::npos) &&
453
- text.find('\v') != StringPiece::npos) {
450
+ if ((regexp_str_.find("\\s") != absl::string_view::npos ||
451
+ regexp_str_.find("\\S") != absl::string_view::npos) &&
452
+ text.find('\v') != absl::string_view::npos) {
454
453
  result->skipped = true;
455
454
  break;
456
455
  }
@@ -513,7 +512,7 @@ static bool ResultOkay(const Result& r, const Result& correct) {
513
512
  }
514
513
 
515
514
  // Runs a single test.
516
- bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
515
+ bool TestInstance::RunCase(absl::string_view text, absl::string_view context,
517
516
  Prog::Anchor anchor) {
518
517
  // Backtracking is the gold standard.
519
518
  Result correct;
@@ -521,12 +520,12 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
521
520
  if (correct.skipped) {
522
521
  if (regexp_ == NULL)
523
522
  return true;
524
- LOG(ERROR) << "Skipped backtracking! " << CEscape(regexp_str_)
523
+ LOG(ERROR) << "Skipped backtracking! " << absl::CEscape(regexp_str_)
525
524
  << " " << FormatMode(flags_);
526
525
  return false;
527
526
  }
528
- VLOG(1) << "Try: regexp " << CEscape(regexp_str_)
529
- << " text " << CEscape(text)
527
+ VLOG(1) << "Try: regexp " << absl::CEscape(regexp_str_)
528
+ << " text " << absl::CEscape(text)
530
529
  << " (" << FormatKind(kind_)
531
530
  << ", " << FormatAnchor(anchor)
532
531
  << ", " << FormatMode(flags_)
@@ -541,7 +540,7 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
541
540
  Result r;
542
541
  RunSearch(i, text, context, anchor, &r);
543
542
  if (ResultOkay(r, correct)) {
544
- if (GetFlag(FLAGS_log_okay))
543
+ if (absl::GetFlag(FLAGS_log_okay))
545
544
  LogMatch(r.skipped ? "Skipped: " : "Okay: ", i, text, context, anchor);
546
545
  continue;
547
546
  }
@@ -571,14 +570,14 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
571
570
  if (r.submatch[i].data() != correct.submatch[i].data() ||
572
571
  r.submatch[i].size() != correct.submatch[i].size()) {
573
572
  LOG(INFO) <<
574
- StringPrintf(" $%d: should be %s is %s",
575
- i,
576
- FormatCapture(text, correct.submatch[i]).c_str(),
577
- FormatCapture(text, r.submatch[i]).c_str());
573
+ absl::StrFormat(" $%d: should be %s is %s",
574
+ i,
575
+ FormatCapture(text, correct.submatch[i]),
576
+ FormatCapture(text, r.submatch[i]));
578
577
  } else {
579
578
  LOG(INFO) <<
580
- StringPrintf(" $%d: %s ok", i,
581
- FormatCapture(text, r.submatch[i]).c_str());
579
+ absl::StrFormat(" $%d: %s ok", i,
580
+ FormatCapture(text, r.submatch[i]));
582
581
  }
583
582
  }
584
583
  }
@@ -586,7 +585,7 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
586
585
  if (!all_okay) {
587
586
  // This will be initialised once (after flags have been initialised)
588
587
  // and that is desirable because we want to enforce a global limit.
589
- static int max_regexp_failures = GetFlag(FLAGS_max_regexp_failures);
588
+ static int max_regexp_failures = absl::GetFlag(FLAGS_max_regexp_failures);
590
589
  if (max_regexp_failures > 0 && --max_regexp_failures == 0)
591
590
  LOG(QFATAL) << "Too many regexp failures.";
592
591
  }
@@ -595,22 +594,22 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
595
594
  }
596
595
 
597
596
  void TestInstance::LogMatch(const char* prefix, Engine e,
598
- const StringPiece& text, const StringPiece& context,
597
+ absl::string_view text, absl::string_view context,
599
598
  Prog::Anchor anchor) {
600
599
  LOG(INFO) << prefix
601
600
  << EngineName(e)
602
601
  << " regexp "
603
- << CEscape(regexp_str_)
602
+ << absl::CEscape(regexp_str_)
604
603
  << " "
605
- << CEscape(regexp_->ToString())
604
+ << absl::CEscape(regexp_->ToString())
606
605
  << " text "
607
- << CEscape(text)
606
+ << absl::CEscape(text)
608
607
  << " ("
609
608
  << BeginPtr(text) - BeginPtr(context)
610
609
  << ","
611
610
  << EndPtr(text) - BeginPtr(context)
612
611
  << ") of context "
613
- << CEscape(context)
612
+ << absl::CEscape(context)
614
613
  << " (" << FormatKind(kind_)
615
614
  << ", " << FormatAnchor(anchor)
616
615
  << ", " << FormatMode(flags_)
@@ -624,10 +623,10 @@ static Prog::MatchKind kinds[] = {
624
623
  };
625
624
 
626
625
  // Test all possible match kinds and parse modes.
627
- Tester::Tester(const StringPiece& regexp) {
626
+ Tester::Tester(absl::string_view regexp) {
628
627
  error_ = false;
629
- for (size_t i = 0; i < arraysize(kinds); i++) {
630
- for (size_t j = 0; j < arraysize(parse_modes); j++) {
628
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(kinds); i++) {
629
+ for (size_t j = 0; j < ABSL_ARRAYSIZE(parse_modes); j++) {
631
630
  TestInstance* t = new TestInstance(regexp, kinds[i],
632
631
  parse_modes[j].parse_flags);
633
632
  error_ |= t->error();
@@ -641,8 +640,8 @@ Tester::~Tester() {
641
640
  delete v_[i];
642
641
  }
643
642
 
644
- bool Tester::TestCase(const StringPiece& text, const StringPiece& context,
645
- Prog::Anchor anchor) {
643
+ bool Tester::TestCase(absl::string_view text, absl::string_view context,
644
+ Prog::Anchor anchor) {
646
645
  bool okay = true;
647
646
  for (size_t i = 0; i < v_.size(); i++)
648
647
  okay &= (!v_[i]->error() && v_[i]->RunCase(text, context, anchor));
@@ -654,10 +653,10 @@ static Prog::Anchor anchors[] = {
654
653
  Prog::kUnanchored
655
654
  };
656
655
 
657
- bool Tester::TestInput(const StringPiece& text) {
656
+ bool Tester::TestInput(absl::string_view text) {
658
657
  bool okay = TestInputInContext(text, text);
659
658
  if (!text.empty()) {
660
- StringPiece sp;
659
+ absl::string_view sp;
661
660
  sp = text;
662
661
  sp.remove_prefix(1);
663
662
  okay &= TestInputInContext(sp, text);
@@ -668,16 +667,16 @@ bool Tester::TestInput(const StringPiece& text) {
668
667
  return okay;
669
668
  }
670
669
 
671
- bool Tester::TestInputInContext(const StringPiece& text,
672
- const StringPiece& context) {
670
+ bool Tester::TestInputInContext(absl::string_view text,
671
+ absl::string_view context) {
673
672
  bool okay = true;
674
- for (size_t i = 0; i < arraysize(anchors); i++)
673
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(anchors); i++)
675
674
  okay &= TestCase(text, context, anchors[i]);
676
675
  return okay;
677
676
  }
678
677
 
679
- bool TestRegexpOnText(const StringPiece& regexp,
680
- const StringPiece& text) {
678
+ bool TestRegexpOnText(absl::string_view regexp,
679
+ absl::string_view text) {
681
680
  Tester t(regexp);
682
681
  return t.TestInput(text);
683
682
  }
@@ -10,7 +10,7 @@
10
10
 
11
11
  #include <vector>
12
12
 
13
- #include "re2/stringpiece.h"
13
+ #include "absl/strings/string_view.h"
14
14
  #include "re2/prog.h"
15
15
  #include "re2/regexp.h"
16
16
  #include "re2/re2.h"
@@ -51,7 +51,7 @@ class TestInstance {
51
51
  public:
52
52
  struct Result;
53
53
 
54
- TestInstance(const StringPiece& regexp, Prog::MatchKind kind,
54
+ TestInstance(absl::string_view regexp, Prog::MatchKind kind,
55
55
  Regexp::ParseFlags flags);
56
56
  ~TestInstance();
57
57
  Regexp::ParseFlags flags() { return flags_; }
@@ -59,20 +59,18 @@ class TestInstance {
59
59
 
60
60
  // Runs a single test case: search in text, which is in context,
61
61
  // using the given anchoring.
62
- bool RunCase(const StringPiece& text, const StringPiece& context,
62
+ bool RunCase(absl::string_view text, absl::string_view context,
63
63
  Prog::Anchor anchor);
64
64
 
65
65
  private:
66
66
  // Runs a single search using the named engine type.
67
- void RunSearch(Engine type,
68
- const StringPiece& text, const StringPiece& context,
69
- Prog::Anchor anchor,
70
- Result *result);
67
+ void RunSearch(Engine type, absl::string_view text, absl::string_view context,
68
+ Prog::Anchor anchor, Result* result);
71
69
 
72
- void LogMatch(const char* prefix, Engine e, const StringPiece& text,
73
- const StringPiece& context, Prog::Anchor anchor);
70
+ void LogMatch(const char* prefix, Engine e, absl::string_view text,
71
+ absl::string_view context, Prog::Anchor anchor);
74
72
 
75
- const StringPiece regexp_str_; // regexp being tested
73
+ absl::string_view regexp_str_; // regexp being tested
76
74
  Prog::MatchKind kind_; // kind of match
77
75
  Regexp::ParseFlags flags_; // flags for parsing regexp_str_
78
76
  bool error_; // error during constructor?
@@ -91,21 +89,21 @@ class TestInstance {
91
89
  // A group of TestInstances for all possible configurations.
92
90
  class Tester {
93
91
  public:
94
- explicit Tester(const StringPiece& regexp);
92
+ explicit Tester(absl::string_view regexp);
95
93
  ~Tester();
96
94
 
97
95
  bool error() { return error_; }
98
96
 
99
97
  // Runs a single test case: search in text, which is in context,
100
98
  // using the given anchoring.
101
- bool TestCase(const StringPiece& text, const StringPiece& context,
99
+ bool TestCase(absl::string_view text, absl::string_view context,
102
100
  Prog::Anchor anchor);
103
101
 
104
102
  // Run TestCase(text, text, anchor) for all anchoring modes.
105
- bool TestInput(const StringPiece& text);
103
+ bool TestInput(absl::string_view text);
106
104
 
107
105
  // Run TestCase(text, context, anchor) for all anchoring modes.
108
- bool TestInputInContext(const StringPiece& text, const StringPiece& context);
106
+ bool TestInputInContext(absl::string_view text, absl::string_view context);
109
107
 
110
108
  private:
111
109
  bool error_;
@@ -116,7 +114,7 @@ class Tester {
116
114
  };
117
115
 
118
116
  // Run all possible tests using regexp and text.
119
- bool TestRegexpOnText(const StringPiece& regexp, const StringPiece& text);
117
+ bool TestRegexpOnText(absl::string_view regexp, absl::string_view text);
120
118
 
121
119
  } // namespace re2
122
120
 
@@ -8,9 +8,8 @@
8
8
  #include <string.h>
9
9
  #include <string>
10
10
 
11
- #include "util/util.h"
11
+ #include "absl/strings/str_format.h"
12
12
  #include "util/logging.h"
13
- #include "util/strutil.h"
14
13
  #include "util/utf.h"
15
14
  #include "re2/regexp.h"
16
15
  #include "re2/walker-inl.h"
@@ -216,11 +215,11 @@ int ToStringWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg,
216
215
 
217
216
  case kRegexpRepeat:
218
217
  if (re->max() == -1)
219
- t_->append(StringPrintf("{%d,}", re->min()));
218
+ t_->append(absl::StrFormat("{%d,}", re->min()));
220
219
  else if (re->min() == re->max())
221
- t_->append(StringPrintf("{%d}", re->min()));
220
+ t_->append(absl::StrFormat("{%d}", re->min()));
222
221
  else
223
- t_->append(StringPrintf("{%d,%d}", re->min(), re->max()));
222
+ t_->append(absl::StrFormat("{%d,%d}", re->min(), re->max()));
224
223
  if (re->parse_flags() & Regexp::NonGreedy)
225
224
  t_->append("?");
226
225
  if (prec < PrecUnary)
@@ -291,7 +290,7 @@ int ToStringWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg,
291
290
  // There's no syntax accepted by the parser to generate
292
291
  // this node (it is generated by RE2::Set) so make something
293
292
  // up that is readable but won't compile.
294
- t_->append(StringPrintf("(?HaveMatch:%d)", re->match_id()));
293
+ t_->append(absl::StrFormat("(?HaveMatch:%d)", re->match_id()));
295
294
  break;
296
295
  }
297
296
 
@@ -332,10 +331,10 @@ static void AppendCCChar(std::string* t, Rune r) {
332
331
  }
333
332
 
334
333
  if (r < 0x100) {
335
- *t += StringPrintf("\\x%02x", static_cast<int>(r));
334
+ *t += absl::StrFormat("\\x%02x", static_cast<int>(r));
336
335
  return;
337
336
  }
338
- *t += StringPrintf("\\x{%x}", static_cast<int>(r));
337
+ *t += absl::StrFormat("\\x{%x}", static_cast<int>(r));
339
338
  }
340
339
 
341
340
  static void AppendCCRange(std::string* t, Rune lo, Rune hi) {
@@ -41,7 +41,6 @@
41
41
 
42
42
  #include <stdint.h>
43
43
 
44
- #include "util/util.h"
45
44
  #include "util/utf.h"
46
45
 
47
46
  namespace re2 {
@@ -20,7 +20,6 @@
20
20
 
21
21
  #include <stdint.h>
22
22
 
23
- #include "util/util.h"
24
23
  #include "util/utf.h"
25
24
 
26
25
  namespace re2 {
@@ -15,6 +15,7 @@
15
15
 
16
16
  #include <stack>
17
17
 
18
+ #include "absl/base/macros.h"
18
19
  #include "util/logging.h"
19
20
  #include "re2/regexp.h"
20
21
 
@@ -190,7 +191,7 @@ template<typename T> T Regexp::Walker<T>::WalkInternal(Regexp* re, T top_arg,
190
191
  s->child_args = &s->child_arg;
191
192
  else if (re->nsub_ > 1)
192
193
  s->child_args = new T[re->nsub_];
193
- FALLTHROUGH_INTENDED;
194
+ ABSL_FALLTHROUGH_INTENDED;
194
195
  }
195
196
  default: {
196
197
  if (re->nsub_ > 0) {
@@ -0,0 +1,9 @@
1
+ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
2
+ libdir=@CMAKE_INSTALL_FULL_LIBDIR@
3
+
4
+ Name: re2
5
+ Description: RE2 is a fast, safe, thread-friendly regular expression engine.
6
+ Requires: @REQUIRES@
7
+ Version: @SONAME@.0.0
8
+ Cflags: -pthread -I${includedir}
9
+ Libs: -pthread -L${libdir} -lre2
@@ -0,0 +1,28 @@
1
+ # Copyright 2022 The RE2 Authors. All Rights Reserved.
2
+ # Use of this source code is governed by a BSD-style
3
+ # license that can be found in the LICENSE file.
4
+
5
+ @PACKAGE_INIT@
6
+
7
+ include(CMakeFindDependencyMacro)
8
+
9
+ set_and_check(re2_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@)
10
+
11
+ if(UNIX)
12
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
13
+ find_dependency(Threads REQUIRED)
14
+ endif()
15
+
16
+ find_dependency(absl REQUIRED)
17
+
18
+ if(@RE2_USE_ICU@)
19
+ find_dependency(ICU REQUIRED COMPONENTS uc)
20
+ endif()
21
+
22
+ check_required_components(re2)
23
+
24
+ if(TARGET re2::re2)
25
+ return()
26
+ endif()
27
+
28
+ include(${CMAKE_CURRENT_LIST_DIR}/re2Targets.cmake)
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # System Integrity Protection on Darwin complicated these matters somewhat.
4
+ # See https://github.com/google/re2/issues/175 for details.
5
+ if [ "x$1" = "x-shared-library-path" ]; then
6
+ if [ "x$(uname)" = "xDarwin" ]; then
7
+ DYLD_LIBRARY_PATH="$2:$DYLD_LIBRARY_PATH"
8
+ export DYLD_LIBRARY_PATH
9
+ else
10
+ LD_LIBRARY_PATH="$2:$LD_LIBRARY_PATH"
11
+ export LD_LIBRARY_PATH
12
+ fi
13
+ shift 2
14
+ fi
15
+
16
+ success=true
17
+ for i; do
18
+ printf "%-40s" $i
19
+ if $($i >$i.log 2>&1) 2>/dev/null; then
20
+ echo PASS
21
+ else
22
+ echo FAIL';' output in $i.log
23
+ success=false
24
+ fi
25
+ done
26
+
27
+ if $success; then
28
+ echo 'ALL TESTS PASSED.'
29
+ exit 0
30
+ else
31
+ echo 'TESTS FAILED.'
32
+ exit 1
33
+ fi
@@ -0,0 +1,27 @@
1
+ // Copyright 2008 The RE2 Authors. All Rights Reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ #include <stdio.h>
6
+ #include <re2/filtered_re2.h>
7
+ #include <re2/re2.h>
8
+
9
+ int main() {
10
+ re2::FilteredRE2 f;
11
+ int id;
12
+ f.Add("a.*b.*c", RE2::DefaultOptions, &id);
13
+ std::vector<std::string> v;
14
+ f.Compile(&v);
15
+ std::vector<int> ids;
16
+ f.FirstMatch("abbccc", ids);
17
+
18
+ int n;
19
+ if (RE2::FullMatch("axbyc", "a.*b.*c") &&
20
+ RE2::PartialMatch("foo123bar", "(\\d+)", &n) && n == 123) {
21
+ printf("PASS\n");
22
+ return 0;
23
+ }
24
+
25
+ printf("FAIL\n");
26
+ return 2;
27
+ }