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
@@ -6,7 +6,8 @@
6
6
 
7
7
  #include <string>
8
8
 
9
- #include "util/test.h"
9
+ #include "absl/base/macros.h"
10
+ #include "gtest/gtest.h"
10
11
  #include "util/logging.h"
11
12
  #include "re2/regexp.h"
12
13
 
@@ -262,7 +263,7 @@ void TestParse(const Test* tests, int ntests, Regexp::ParseFlags flags,
262
263
 
263
264
  // Test that regexps parse to expected structures.
264
265
  TEST(TestParse, SimpleRegexps) {
265
- TestParse(tests, arraysize(tests), kTestFlags, "simple");
266
+ TestParse(tests, ABSL_ARRAYSIZE(tests), kTestFlags, "simple");
266
267
  }
267
268
 
268
269
  Test foldcase_tests[] = {
@@ -279,7 +280,7 @@ Test foldcase_tests[] = {
279
280
 
280
281
  // Test that parsing with FoldCase works.
281
282
  TEST(TestParse, FoldCase) {
282
- TestParse(foldcase_tests, arraysize(foldcase_tests), Regexp::FoldCase, "foldcase");
283
+ TestParse(foldcase_tests, ABSL_ARRAYSIZE(foldcase_tests), Regexp::FoldCase, "foldcase");
283
284
  }
284
285
 
285
286
  Test literal_tests[] = {
@@ -288,7 +289,7 @@ Test literal_tests[] = {
288
289
 
289
290
  // Test that parsing with Literal works.
290
291
  TEST(TestParse, Literal) {
291
- TestParse(literal_tests, arraysize(literal_tests), Regexp::Literal, "literal");
292
+ TestParse(literal_tests, ABSL_ARRAYSIZE(literal_tests), Regexp::Literal, "literal");
292
293
  }
293
294
 
294
295
  Test matchnl_tests[] = {
@@ -301,7 +302,7 @@ Test matchnl_tests[] = {
301
302
  // Test that parsing with MatchNL works.
302
303
  // (Also tested above during simple cases.)
303
304
  TEST(TestParse, MatchNL) {
304
- TestParse(matchnl_tests, arraysize(matchnl_tests), Regexp::MatchNL, "with MatchNL");
305
+ TestParse(matchnl_tests, ABSL_ARRAYSIZE(matchnl_tests), Regexp::MatchNL, "with MatchNL");
305
306
  }
306
307
 
307
308
  Test nomatchnl_tests[] = {
@@ -313,7 +314,7 @@ Test nomatchnl_tests[] = {
313
314
 
314
315
  // Test that parsing without MatchNL works.
315
316
  TEST(TestParse, NoMatchNL) {
316
- TestParse(nomatchnl_tests, arraysize(nomatchnl_tests), Regexp::NoParseFlags, "without MatchNL");
317
+ TestParse(nomatchnl_tests, ABSL_ARRAYSIZE(nomatchnl_tests), Regexp::NoParseFlags, "without MatchNL");
317
318
  }
318
319
 
319
320
  Test prefix_tests[] = {
@@ -357,7 +358,7 @@ Test prefix_tests[] = {
357
358
 
358
359
  // Test that prefix factoring works.
359
360
  TEST(TestParse, Prefix) {
360
- TestParse(prefix_tests, arraysize(prefix_tests), Regexp::PerlX, "prefix");
361
+ TestParse(prefix_tests, ABSL_ARRAYSIZE(prefix_tests), Regexp::PerlX, "prefix");
361
362
  }
362
363
 
363
364
  Test nested_tests[] = {
@@ -373,7 +374,7 @@ Test nested_tests[] = {
373
374
 
374
375
  // Test that nested repetition works.
375
376
  TEST(TestParse, Nested) {
376
- TestParse(nested_tests, arraysize(nested_tests), Regexp::PerlX, "nested");
377
+ TestParse(nested_tests, ABSL_ARRAYSIZE(nested_tests), Regexp::PerlX, "nested");
377
378
  }
378
379
 
379
380
  // Invalid regular expressions
@@ -428,20 +429,20 @@ const char* only_posix[] = {
428
429
 
429
430
  // Test that parser rejects bad regexps.
430
431
  TEST(TestParse, InvalidRegexps) {
431
- for (size_t i = 0; i < arraysize(badtests); i++) {
432
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(badtests); i++) {
432
433
  ASSERT_TRUE(Regexp::Parse(badtests[i], Regexp::PerlX, NULL) == NULL)
433
434
  << " " << badtests[i];
434
435
  ASSERT_TRUE(Regexp::Parse(badtests[i], Regexp::NoParseFlags, NULL) == NULL)
435
436
  << " " << badtests[i];
436
437
  }
437
- for (size_t i = 0; i < arraysize(only_posix); i++) {
438
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(only_posix); i++) {
438
439
  ASSERT_TRUE(Regexp::Parse(only_posix[i], Regexp::PerlX, NULL) == NULL)
439
440
  << " " << only_posix[i];
440
441
  Regexp* re = Regexp::Parse(only_posix[i], Regexp::NoParseFlags, NULL);
441
442
  ASSERT_TRUE(re != NULL) << " " << only_posix[i];
442
443
  re->Decref();
443
444
  }
444
- for (size_t i = 0; i < arraysize(only_perl); i++) {
445
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(only_perl); i++) {
445
446
  ASSERT_TRUE(Regexp::Parse(only_perl[i], Regexp::NoParseFlags, NULL) == NULL)
446
447
  << " " << only_perl[i];
447
448
  Regexp* re = Regexp::Parse(only_perl[i], Regexp::PerlX, NULL);
@@ -452,7 +453,7 @@ TEST(TestParse, InvalidRegexps) {
452
453
 
453
454
  // Test that ToString produces original regexp or equivalent one.
454
455
  TEST(TestToString, EquivalentParse) {
455
- for (size_t i = 0; i < arraysize(tests); i++) {
456
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(tests); i++) {
456
457
  RegexpStatus status;
457
458
  Regexp::ParseFlags f = kTestFlags;
458
459
  if (tests[i].flags != 0) {
@@ -6,9 +6,10 @@
6
6
  #include <string>
7
7
  #include <vector>
8
8
 
9
- #include "util/test.h"
9
+ #include "absl/base/macros.h"
10
+ #include "absl/strings/escaping.h"
11
+ #include "gtest/gtest.h"
10
12
  #include "util/logging.h"
11
- #include "util/strutil.h"
12
13
  #include "re2/prog.h"
13
14
  #include "re2/re2.h"
14
15
  #include "re2/regexp.h"
@@ -107,12 +108,12 @@ static PrefixTest tests[] = {
107
108
  };
108
109
 
109
110
  TEST(PossibleMatchRange, HandWritten) {
110
- for (size_t i = 0; i < arraysize(tests); i++) {
111
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(tests); i++) {
111
112
  for (size_t j = 0; j < 2; j++) {
112
113
  const PrefixTest& t = tests[i];
113
114
  std::string min, max;
114
115
  if (j == 0) {
115
- LOG(INFO) << "Checking regexp=" << CEscape(t.regexp);
116
+ LOG(INFO) << "Checking regexp=" << absl::CEscape(t.regexp);
116
117
  Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL);
117
118
  ASSERT_TRUE(re != NULL);
118
119
  Prog* prog = re->CompileToProg(0);
@@ -142,26 +143,26 @@ TEST(PossibleMatchRange, Failures) {
142
143
  // are no valid UTF-8 strings beginning with byte 0xFF.
143
144
  EXPECT_FALSE(RE2("[\\s\\S]+", RE2::Latin1).
144
145
  PossibleMatchRange(&min, &max, 10))
145
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
146
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
146
147
  EXPECT_FALSE(RE2("[\\0-\xFF]+", RE2::Latin1).
147
148
  PossibleMatchRange(&min, &max, 10))
148
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
149
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
149
150
  EXPECT_FALSE(RE2(".+hello", RE2::Latin1).
150
151
  PossibleMatchRange(&min, &max, 10))
151
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
152
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
152
153
  EXPECT_FALSE(RE2(".*hello", RE2::Latin1).
153
154
  PossibleMatchRange(&min, &max, 10))
154
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
155
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
155
156
  EXPECT_FALSE(RE2(".*", RE2::Latin1).
156
157
  PossibleMatchRange(&min, &max, 10))
157
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
158
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
158
159
  EXPECT_FALSE(RE2("\\C*").
159
160
  PossibleMatchRange(&min, &max, 10))
160
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
161
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
161
162
 
162
163
  // Fails because it's a malformed regexp.
163
164
  EXPECT_FALSE(RE2("*hello").PossibleMatchRange(&min, &max, 10))
164
- << "min=" << CEscape(min) << ", max=" << CEscape(max);
165
+ << "min=" << absl::CEscape(min) << ", max=" << absl::CEscape(max);
165
166
  }
166
167
 
167
168
  // Exhaustive test: generate all regexps within parameters,
@@ -201,7 +202,7 @@ class PossibleMatchTester : public RegexpGenerator {
201
202
  void PossibleMatchTester::HandleRegexp(const std::string& regexp) {
202
203
  regexps_++;
203
204
 
204
- VLOG(3) << CEscape(regexp);
205
+ VLOG(3) << absl::CEscape(regexp);
205
206
 
206
207
  RE2 re(regexp, RE2::Latin1);
207
208
  ASSERT_EQ(re.error(), "");
@@ -213,12 +214,12 @@ void PossibleMatchTester::HandleRegexp(const std::string& regexp) {
213
214
  // complicated expressions.
214
215
  if(strstr(regexp.c_str(), "\\C*"))
215
216
  return;
216
- LOG(QFATAL) << "PossibleMatchRange failed on: " << CEscape(regexp);
217
+ LOG(QFATAL) << "PossibleMatchRange failed on: " << absl::CEscape(regexp);
217
218
  }
218
219
 
219
220
  strgen_.Reset();
220
221
  while (strgen_.HasNext()) {
221
- const StringPiece& s = strgen_.Next();
222
+ absl::string_view s = strgen_.Next();
222
223
  tests_++;
223
224
  if (!RE2::FullMatch(s, re))
224
225
  continue;
@@ -8,14 +8,15 @@
8
8
  #include <string>
9
9
  #include <vector>
10
10
 
11
- #include "util/test.h"
12
- #include "util/flags.h"
11
+ #include "absl/flags/flag.h"
12
+ #include "absl/strings/str_format.h"
13
+ #include "gtest/gtest.h"
13
14
  #include "re2/testing/exhaustive_tester.h"
14
15
 
15
- DEFINE_FLAG(int, regexpseed, 404, "Random regexp seed.");
16
- DEFINE_FLAG(int, regexpcount, 100, "How many random regexps to generate.");
17
- DEFINE_FLAG(int, stringseed, 200, "Random string seed.");
18
- DEFINE_FLAG(int, stringcount, 100, "How many random strings to generate.");
16
+ ABSL_FLAG(int, regexpseed, 404, "Random regexp seed.");
17
+ ABSL_FLAG(int, regexpcount, 100, "How many random regexps to generate.");
18
+ ABSL_FLAG(int, stringseed, 200, "Random string seed.");
19
+ ABSL_FLAG(int, stringcount, 100, "How many random strings to generate.");
19
20
 
20
21
  namespace re2 {
21
22
 
@@ -38,12 +39,12 @@ static void RandomTest(int maxatoms, int maxops,
38
39
 
39
40
  ExhaustiveTester t(maxatoms, maxops, alphabet, ops,
40
41
  maxstrlen, stralphabet, wrapper, "");
41
- t.RandomStrings(GetFlag(FLAGS_stringseed),
42
- GetFlag(FLAGS_stringcount));
43
- t.GenerateRandom(GetFlag(FLAGS_regexpseed),
44
- GetFlag(FLAGS_regexpcount));
45
- printf("%d regexps, %d tests, %d failures [%d/%d str]\n",
46
- t.regexps(), t.tests(), t.failures(), maxstrlen, (int)stralphabet.size());
42
+ t.RandomStrings(absl::GetFlag(FLAGS_stringseed),
43
+ absl::GetFlag(FLAGS_stringcount));
44
+ t.GenerateRandom(absl::GetFlag(FLAGS_regexpseed),
45
+ absl::GetFlag(FLAGS_regexpcount));
46
+ absl::PrintF("%d regexps, %d tests, %d failures [%d/%d str]\n",
47
+ t.regexps(), t.tests(), t.failures(), maxstrlen, stralphabet.size());
47
48
  EXPECT_EQ(0, t.failures());
48
49
  }
49
50
 
@@ -10,7 +10,8 @@
10
10
  #include <stdint.h>
11
11
  #include <string.h>
12
12
 
13
- #include "util/test.h"
13
+ #include "absl/base/macros.h"
14
+ #include "gtest/gtest.h"
14
15
  #include "util/logging.h"
15
16
  #include "re2/re2.h"
16
17
 
@@ -87,7 +88,7 @@ const SuccessTable kSuccessTable[] = {
87
88
  { "18446744073709551616", 0, { false, false, false, false, false, false }},
88
89
  };
89
90
 
90
- const int kNumStrings = arraysize(kSuccessTable);
91
+ const int kNumStrings = ABSL_ARRAYSIZE(kSuccessTable);
91
92
 
92
93
  // It's ugly to use a macro, but we apparently can't use the EXPECT_EQ
93
94
  // macro outside of a TEST block and this seems to be the only way to
@@ -157,4 +158,26 @@ TEST(RE2ArgTest, ParseFromTest) {
157
158
  #endif
158
159
  }
159
160
 
161
+ TEST(RE2ArgTest, OptionalDoubleTest) {
162
+ absl::optional<double> opt;
163
+ RE2::Arg arg(&opt);
164
+ EXPECT_TRUE(arg.Parse(NULL, 0));
165
+ EXPECT_FALSE(opt.has_value());
166
+ EXPECT_FALSE(arg.Parse("", 0));
167
+ EXPECT_TRUE(arg.Parse("28.30", 5));
168
+ EXPECT_TRUE(opt.has_value());
169
+ EXPECT_EQ(*opt, 28.30);
170
+ }
171
+
172
+ TEST(RE2ArgTest, OptionalIntWithCRadixTest) {
173
+ absl::optional<int> opt;
174
+ RE2::Arg arg = RE2::CRadix(&opt);
175
+ EXPECT_TRUE(arg.Parse(NULL, 0));
176
+ EXPECT_FALSE(opt.has_value());
177
+ EXPECT_FALSE(arg.Parse("", 0));
178
+ EXPECT_TRUE(arg.Parse("0xb0e", 5));
179
+ EXPECT_TRUE(opt.has_value());
180
+ EXPECT_EQ(*opt, 2830);
181
+ }
182
+
160
183
  } // namespace re2
@@ -18,9 +18,10 @@
18
18
  #include <unistd.h> /* for sysconf */
19
19
  #endif
20
20
 
21
- #include "util/test.h"
21
+ #include "absl/base/macros.h"
22
+ #include "absl/strings/str_format.h"
23
+ #include "gtest/gtest.h"
22
24
  #include "util/logging.h"
23
- #include "util/strutil.h"
24
25
  #include "re2/re2.h"
25
26
  #include "re2/regexp.h"
26
27
 
@@ -238,7 +239,7 @@ TEST(RE2, Consume) {
238
239
  std::string word;
239
240
 
240
241
  std::string s(" aaa b!@#$@#$cccc");
241
- StringPiece input(s);
242
+ absl::string_view input(s);
242
243
 
243
244
  ASSERT_TRUE(RE2::Consume(&input, r, &word));
244
245
  ASSERT_EQ(word, "aaa") << " input: " << input;
@@ -249,7 +250,7 @@ TEST(RE2, Consume) {
249
250
 
250
251
  TEST(RE2, ConsumeN) {
251
252
  const std::string s(" one two three 4");
252
- StringPiece input(s);
253
+ absl::string_view input(s);
253
254
 
254
255
  RE2::Arg argv[2];
255
256
  const RE2::Arg* const args[2] = { &argv[0], &argv[1] };
@@ -276,7 +277,7 @@ TEST(RE2, FindAndConsume) {
276
277
  std::string word;
277
278
 
278
279
  std::string s(" aaa b!@#$@#$cccc");
279
- StringPiece input(s);
280
+ absl::string_view input(s);
280
281
 
281
282
  ASSERT_TRUE(RE2::FindAndConsume(&input, r, &word));
282
283
  ASSERT_EQ(word, "aaa");
@@ -296,7 +297,7 @@ TEST(RE2, FindAndConsume) {
296
297
 
297
298
  TEST(RE2, FindAndConsumeN) {
298
299
  const std::string s(" one two three 4");
299
- StringPiece input(s);
300
+ absl::string_view input(s);
300
301
 
301
302
  RE2::Arg argv[2];
302
303
  const RE2::Arg* const args[2] = { &argv[0], &argv[1] };
@@ -345,17 +346,17 @@ TEST(RE2, MatchNumberPeculiarity) {
345
346
 
346
347
  TEST(RE2, Match) {
347
348
  RE2 re("((\\w+):([0-9]+))"); // extracts host and port
348
- StringPiece group[4];
349
+ absl::string_view group[4];
349
350
 
350
351
  // No match.
351
- StringPiece s = "zyzzyva";
352
+ absl::string_view s = "zyzzyva";
352
353
  ASSERT_FALSE(
353
- re.Match(s, 0, s.size(), RE2::UNANCHORED, group, arraysize(group)));
354
+ re.Match(s, 0, s.size(), RE2::UNANCHORED, group, ABSL_ARRAYSIZE(group)));
354
355
 
355
356
  // Matches and extracts.
356
357
  s = "a chrisr:9000 here";
357
358
  ASSERT_TRUE(
358
- re.Match(s, 0, s.size(), RE2::UNANCHORED, group, arraysize(group)));
359
+ re.Match(s, 0, s.size(), RE2::UNANCHORED, group, ABSL_ARRAYSIZE(group)));
359
360
  ASSERT_EQ(group[0], "chrisr:9000");
360
361
  ASSERT_EQ(group[1], "chrisr:9000");
361
362
  ASSERT_EQ(group[2], "chrisr");
@@ -528,7 +529,7 @@ TEST(EmptyCharset, Fuzz) {
528
529
  "[^\\D\\d]",
529
530
  "[^\\D[:digit:]]"
530
531
  };
531
- for (size_t i = 0; i < arraysize(empties); i++)
532
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(empties); i++)
532
533
  ASSERT_FALSE(RE2(empties[i]).Match("abc", 0, 3, RE2::UNANCHORED, NULL, 0));
533
534
  }
534
535
 
@@ -542,8 +543,8 @@ TEST(EmptyCharset, BitstateAssumptions) {
542
543
  "((((()))))" "([^\\S\\s]|[^\\S\\s])?",
543
544
  "((((()))))" "(([^\\S\\s]|[^\\S\\s])|)"
544
545
  };
545
- StringPiece group[6];
546
- for (size_t i = 0; i < arraysize(nop_empties); i++)
546
+ absl::string_view group[6];
547
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(nop_empties); i++)
547
548
  ASSERT_TRUE(RE2(nop_empties[i]).Match("", 0, 0, RE2::UNANCHORED, group, 6));
548
549
  }
549
550
 
@@ -672,15 +673,15 @@ TEST(RE2, FullMatchIntegerArg) {
672
673
 
673
674
  TEST(RE2, FullMatchStringArg) {
674
675
  std::string s;
675
- // String-arg
676
+ // string-arg
676
677
  ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", &s));
677
678
  ASSERT_EQ(s, std::string("ell"));
678
679
  }
679
680
 
680
- TEST(RE2, FullMatchStringPieceArg) {
681
+ TEST(RE2, FullMatchStringViewArg) {
681
682
  int i;
682
- // StringPiece-arg
683
- StringPiece sp;
683
+ absl::string_view sp;
684
+ // string_view-arg
684
685
  ASSERT_TRUE(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &sp, &i));
685
686
  ASSERT_EQ(sp.size(), 4);
686
687
  ASSERT_TRUE(memcmp(sp.data(), "ruby", 4) == 0);
@@ -742,7 +743,7 @@ TEST(RE2, FullMatchTypedNullArg) {
742
743
  // Ignore non-void* NULL arg
743
744
  ASSERT_TRUE(RE2::FullMatch("hello", "he(.*)lo", (char*)NULL));
744
745
  ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", (std::string*)NULL));
745
- ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", (StringPiece*)NULL));
746
+ ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", (absl::string_view*)NULL));
746
747
  ASSERT_TRUE(RE2::FullMatch("1234", "(.*)", (int*)NULL));
747
748
  ASSERT_TRUE(RE2::FullMatch("1234567890123456", "(.*)", (long long*)NULL));
748
749
  ASSERT_TRUE(RE2::FullMatch("123.4567890123456", "(.*)", (double*)NULL));
@@ -777,7 +778,8 @@ TEST(RE2, NULTerminated) {
777
778
  v[pagesize - 1] = '1';
778
779
 
779
780
  x = 0;
780
- ASSERT_TRUE(RE2::FullMatch(StringPiece(v + pagesize - 1, 1), "(.*)", &x));
781
+ ASSERT_TRUE(
782
+ RE2::FullMatch(absl::string_view(v + pagesize - 1, 1), "(.*)", &x));
781
783
  ASSERT_EQ(x, 1);
782
784
  #endif
783
785
  }
@@ -914,10 +916,10 @@ TEST(RE2, FloatingPointFullMatchTypes) {
914
916
  // implementation of strtof(3). And apparently MSVC too. Sigh.
915
917
  #if !defined(_MSC_VER) && !defined(__CYGWIN__) && !defined(__MINGW32__)
916
918
  ASSERT_TRUE(RE2::FullMatch("0.1", "(.*)", &v));
917
- ASSERT_EQ(v, 0.1f) << StringPrintf("%.8g != %.8g", v, 0.1f);
919
+ ASSERT_EQ(v, 0.1f) << absl::StrFormat("%.8g != %.8g", v, 0.1f);
918
920
  ASSERT_TRUE(RE2::FullMatch("6700000000081920.1", "(.*)", &v));
919
921
  ASSERT_EQ(v, 6700000000081920.1f)
920
- << StringPrintf("%.8g != %.8g", v, 6700000000081920.1f);
922
+ << absl::StrFormat("%.8g != %.8g", v, 6700000000081920.1f);
921
923
  #endif
922
924
  }
923
925
  {
@@ -929,10 +931,10 @@ TEST(RE2, FloatingPointFullMatchTypes) {
929
931
  ASSERT_EQ(v, double(1e23));
930
932
 
931
933
  ASSERT_TRUE(RE2::FullMatch("0.1", "(.*)", &v));
932
- ASSERT_EQ(v, 0.1) << StringPrintf("%.17g != %.17g", v, 0.1);
934
+ ASSERT_EQ(v, 0.1) << absl::StrFormat("%.17g != %.17g", v, 0.1);
933
935
  ASSERT_TRUE(RE2::FullMatch("1.00000005960464485", "(.*)", &v));
934
936
  ASSERT_EQ(v, 1.0000000596046448)
935
- << StringPrintf("%.17g != %.17g", v, 1.0000000596046448);
937
+ << absl::StrFormat("%.17g != %.17g", v, 1.0000000596046448);
936
938
  }
937
939
  }
938
940
 
@@ -1242,21 +1244,21 @@ TEST(RE2, DeepRecursion) {
1242
1244
  // not implementing case-folding.
1243
1245
  TEST(CaseInsensitive, MatchAndConsume) {
1244
1246
  std::string text = "A fish named *Wanda*";
1245
- StringPiece sp(text);
1246
- StringPiece result;
1247
+ absl::string_view sp(text);
1248
+ absl::string_view result;
1247
1249
  EXPECT_TRUE(RE2::PartialMatch(text, "(?i)([wand]{5})", &result));
1248
1250
  EXPECT_TRUE(RE2::FindAndConsume(&sp, "(?i)([wand]{5})", &result));
1249
1251
  }
1250
1252
 
1251
- // RE2 should permit implicit conversions from string, StringPiece, const char*,
1253
+ // RE2 should permit implicit conversions from string, string_view, const char*,
1252
1254
  // and C string literals.
1253
1255
  TEST(RE2, ImplicitConversions) {
1254
1256
  std::string re_string(".");
1255
- StringPiece re_stringpiece(".");
1256
- const char* re_cstring = ".";
1257
+ absl::string_view re_string_view(".");
1258
+ const char* re_c_string = ".";
1257
1259
  EXPECT_TRUE(RE2::PartialMatch("e", re_string));
1258
- EXPECT_TRUE(RE2::PartialMatch("e", re_stringpiece));
1259
- EXPECT_TRUE(RE2::PartialMatch("e", re_cstring));
1260
+ EXPECT_TRUE(RE2::PartialMatch("e", re_string_view));
1261
+ EXPECT_TRUE(RE2::PartialMatch("e", re_c_string));
1260
1262
  EXPECT_TRUE(RE2::PartialMatch("e", "."));
1261
1263
  }
1262
1264
 
@@ -1309,7 +1311,7 @@ static struct ErrorTest {
1309
1311
  { "zz(?P<name\377>abc)", RE2::ErrorBadUTF8, "" },
1310
1312
  };
1311
1313
  TEST(RE2, ErrorCodeAndArg) {
1312
- for (size_t i = 0; i < arraysize(error_tests); i++) {
1314
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(error_tests); i++) {
1313
1315
  RE2 re(error_tests[i].regexp, RE2::Quiet);
1314
1316
  EXPECT_FALSE(re.ok());
1315
1317
  EXPECT_EQ(re.error_code(), error_tests[i].error_code) << re.error();
@@ -1332,13 +1334,13 @@ static struct NeverTest {
1332
1334
  TEST(RE2, NeverNewline) {
1333
1335
  RE2::Options opt;
1334
1336
  opt.set_never_nl(true);
1335
- for (size_t i = 0; i < arraysize(never_tests); i++) {
1337
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(never_tests); i++) {
1336
1338
  const NeverTest& t = never_tests[i];
1337
1339
  RE2 re(t.regexp, opt);
1338
1340
  if (t.match == NULL) {
1339
1341
  EXPECT_FALSE(re.PartialMatch(t.text, re));
1340
1342
  } else {
1341
- StringPiece m;
1343
+ absl::string_view m;
1342
1344
  EXPECT_TRUE(re.PartialMatch(t.text, re, &m));
1343
1345
  EXPECT_EQ(m, t.match);
1344
1346
  }
@@ -1371,7 +1373,7 @@ TEST(RE2, BitstateCaptureBug) {
1371
1373
  RE2::Options opt;
1372
1374
  opt.set_max_mem(20000);
1373
1375
  RE2 re("(_________$)", opt);
1374
- StringPiece s = "xxxxxxxxxxxxxxxxxxxxxxxxxx_________x";
1376
+ absl::string_view s = "xxxxxxxxxxxxxxxxxxxxxxxxxx_________x";
1375
1377
  EXPECT_FALSE(re.Match(s, 0, s.size(), RE2::UNANCHORED, NULL, 0));
1376
1378
  }
1377
1379
 
@@ -1450,10 +1452,10 @@ TEST(RE2, NullVsEmptyString) {
1450
1452
  RE2 re(".*");
1451
1453
  EXPECT_TRUE(re.ok());
1452
1454
 
1453
- StringPiece null;
1455
+ absl::string_view null;
1454
1456
  EXPECT_TRUE(RE2::FullMatch(null, re));
1455
1457
 
1456
- StringPiece empty("");
1458
+ absl::string_view empty("");
1457
1459
  EXPECT_TRUE(RE2::FullMatch(empty, re));
1458
1460
  }
1459
1461
 
@@ -1465,25 +1467,25 @@ TEST(RE2, NullVsEmptyStringSubmatches) {
1465
1467
  EXPECT_TRUE(re.ok());
1466
1468
 
1467
1469
  // matches[0] is overall match, [1] is (), [2] is (foo), [3] is nonexistent.
1468
- StringPiece matches[4];
1470
+ absl::string_view matches[4];
1469
1471
 
1470
- for (size_t i = 0; i < arraysize(matches); i++)
1472
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(matches); i++)
1471
1473
  matches[i] = "bar";
1472
1474
 
1473
- StringPiece null;
1475
+ absl::string_view null;
1474
1476
  EXPECT_TRUE(re.Match(null, 0, null.size(), RE2::UNANCHORED,
1475
- matches, arraysize(matches)));
1476
- for (size_t i = 0; i < arraysize(matches); i++) {
1477
+ matches, ABSL_ARRAYSIZE(matches)));
1478
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(matches); i++) {
1477
1479
  EXPECT_TRUE(matches[i].data() == NULL); // always null
1478
1480
  EXPECT_TRUE(matches[i].empty());
1479
1481
  }
1480
1482
 
1481
- for (size_t i = 0; i < arraysize(matches); i++)
1483
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(matches); i++)
1482
1484
  matches[i] = "bar";
1483
1485
 
1484
- StringPiece empty("");
1486
+ absl::string_view empty("");
1485
1487
  EXPECT_TRUE(re.Match(empty, 0, empty.size(), RE2::UNANCHORED,
1486
- matches, arraysize(matches)));
1488
+ matches, ABSL_ARRAYSIZE(matches)));
1487
1489
  EXPECT_TRUE(matches[0].data() != NULL); // empty, not null
1488
1490
  EXPECT_TRUE(matches[0].empty());
1489
1491
  EXPECT_TRUE(matches[1].data() != NULL); // empty, not null
@@ -1497,7 +1499,7 @@ TEST(RE2, NullVsEmptyStringSubmatches) {
1497
1499
  // Issue 1816809
1498
1500
  TEST(RE2, Bug1816809) {
1499
1501
  RE2 re("(((((llx((-3)|(4)))(;(llx((-3)|(4))))*))))");
1500
- StringPiece piece("llx-3;llx4");
1502
+ absl::string_view piece("llx-3;llx4");
1501
1503
  std::string x;
1502
1504
  EXPECT_TRUE(RE2::Consume(&piece, re, &x));
1503
1505
  }
@@ -1615,7 +1617,7 @@ TEST(RE2, Bug26356109) {
1615
1617
  ASSERT_TRUE(re.ok());
1616
1618
 
1617
1619
  std::string s = "abc";
1618
- StringPiece m;
1620
+ absl::string_view m;
1619
1621
 
1620
1622
  ASSERT_TRUE(re.Match(s, 0, s.size(), RE2::UNANCHORED, &m, 1));
1621
1623
  ASSERT_EQ(m, s) << " (UNANCHORED) got m='" << m << "', want '" << s << "'";
@@ -1645,7 +1647,7 @@ TEST(RE2, Issue310) {
1645
1647
  // (?:|a)* matched more text than (?:|a)+ did.
1646
1648
 
1647
1649
  std::string s = "aaa";
1648
- StringPiece m;
1650
+ absl::string_view m;
1649
1651
 
1650
1652
  RE2 star("(?:|a)*");
1651
1653
  ASSERT_TRUE(star.Match(s, 0, s.size(), RE2::UNANCHORED, &m, 1));