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
@@ -75,7 +75,7 @@
75
75
  // have succeeded or one conversion has failed.
76
76
  // On conversion failure, the pointees will be in an indeterminate state
77
77
  // because the caller has no way of knowing which conversion failed.
78
- // However, conversion cannot fail for types like string and StringPiece
78
+ // However, conversion cannot fail for types like string and string_view
79
79
  // that do not inspect the submatch contents. Hence, in the common case
80
80
  // where all of the pointees are of such types, failure is always due to
81
81
  // match failure and thus none of the pointees will have been modified.
@@ -140,12 +140,12 @@
140
140
  //
141
141
  // The "Consume" operation may be useful if you want to repeatedly
142
142
  // match regular expressions at the front of a string and skip over
143
- // them as they match. This requires use of the "StringPiece" type,
143
+ // them as they match. This requires use of the string_view type,
144
144
  // which represents a sub-range of a real string.
145
145
  //
146
146
  // Example: read lines of the form "var = value" from a string.
147
- // std::string contents = ...; // Fill string somehow
148
- // StringPiece input(contents); // Wrap a StringPiece around it
147
+ // std::string contents = ...; // Fill string somehow
148
+ // absl::string_view input(contents); // Wrap a string_view around it
149
149
  //
150
150
  // std::string var;
151
151
  // int value;
@@ -206,7 +206,6 @@
206
206
  #include <stdint.h>
207
207
  #include <algorithm>
208
208
  #include <map>
209
- #include <mutex>
210
209
  #include <string>
211
210
  #include <type_traits>
212
211
  #include <vector>
@@ -215,6 +214,9 @@
215
214
  #include <TargetConditionals.h>
216
215
  #endif
217
216
 
217
+ #include "absl/base/call_once.h"
218
+ #include "absl/strings/string_view.h"
219
+ #include "absl/types/optional.h"
218
220
  #include "re2/stringpiece.h"
219
221
 
220
222
  namespace re2 {
@@ -273,11 +275,11 @@ class RE2 {
273
275
 
274
276
  // Need to have the const char* and const std::string& forms for implicit
275
277
  // conversions when passing string literals to FullMatch and PartialMatch.
276
- // Otherwise the StringPiece form would be sufficient.
278
+ // Otherwise the absl::string_view form would be sufficient.
277
279
  RE2(const char* pattern);
278
280
  RE2(const std::string& pattern);
279
- RE2(const StringPiece& pattern);
280
- RE2(const StringPiece& pattern, const Options& options);
281
+ RE2(absl::string_view pattern);
282
+ RE2(absl::string_view pattern, const Options& options);
281
283
  ~RE2();
282
284
 
283
285
  // Not copyable.
@@ -336,13 +338,13 @@ class RE2 {
336
338
  // the functions whose names are the prefix before the 'N'. It is sometimes
337
339
  // useful to invoke them directly, but the syntax is awkward, so the 'N'-less
338
340
  // versions should be preferred.
339
- static bool FullMatchN(const StringPiece& text, const RE2& re,
341
+ static bool FullMatchN(absl::string_view text, const RE2& re,
340
342
  const Arg* const args[], int n);
341
- static bool PartialMatchN(const StringPiece& text, const RE2& re,
343
+ static bool PartialMatchN(absl::string_view text, const RE2& re,
342
344
  const Arg* const args[], int n);
343
- static bool ConsumeN(StringPiece* input, const RE2& re,
345
+ static bool ConsumeN(absl::string_view* input, const RE2& re,
344
346
  const Arg* const args[], int n);
345
- static bool FindAndConsumeN(StringPiece* input, const RE2& re,
347
+ static bool FindAndConsumeN(absl::string_view* input, const RE2& re,
346
348
  const Arg* const args[], int n);
347
349
 
348
350
  private:
@@ -374,10 +376,10 @@ class RE2 {
374
376
  //
375
377
  // The provided pointer arguments can be pointers to any scalar numeric
376
378
  // type, or one of:
377
- // std::string (matched piece is copied to string)
378
- // StringPiece (StringPiece is mutated to point to matched piece)
379
- // T (where "bool T::ParseFrom(const char*, size_t)" exists)
380
- // (void*)NULL (the corresponding matched sub-pattern is not copied)
379
+ // std::string (matched piece is copied to string)
380
+ // absl::string_view (string_view is mutated to point to matched piece)
381
+ // T ("bool T::ParseFrom(const char*, size_t)" must exist)
382
+ // (void*)NULL (the corresponding matched sub-pattern is not copied)
381
383
  //
382
384
  // Returns true iff all of the following conditions are satisfied:
383
385
  // a. "text" matches "re" fully - from the beginning to the end of "text".
@@ -395,7 +397,7 @@ class RE2 {
395
397
  // int number;
396
398
  // RE2::FullMatch("abc", "[a-z]+(\\d+)?", &number);
397
399
  template <typename... A>
398
- static bool FullMatch(const StringPiece& text, const RE2& re, A&&... a) {
400
+ static bool FullMatch(absl::string_view text, const RE2& re, A&&... a) {
399
401
  return Apply(FullMatchN, text, re, Arg(std::forward<A>(a))...);
400
402
  }
401
403
 
@@ -411,7 +413,7 @@ class RE2 {
411
413
  // number of sub-patterns, the "i"th captured sub-pattern is
412
414
  // ignored.
413
415
  template <typename... A>
414
- static bool PartialMatch(const StringPiece& text, const RE2& re, A&&... a) {
416
+ static bool PartialMatch(absl::string_view text, const RE2& re, A&&... a) {
415
417
  return Apply(PartialMatchN, text, re, Arg(std::forward<A>(a))...);
416
418
  }
417
419
 
@@ -429,7 +431,7 @@ class RE2 {
429
431
  // number of sub-patterns, the "i"th captured sub-pattern is
430
432
  // ignored.
431
433
  template <typename... A>
432
- static bool Consume(StringPiece* input, const RE2& re, A&&... a) {
434
+ static bool Consume(absl::string_view* input, const RE2& re, A&&... a) {
433
435
  return Apply(ConsumeN, input, re, Arg(std::forward<A>(a))...);
434
436
  }
435
437
 
@@ -447,7 +449,7 @@ class RE2 {
447
449
  // number of sub-patterns, the "i"th captured sub-pattern is
448
450
  // ignored.
449
451
  template <typename... A>
450
- static bool FindAndConsume(StringPiece* input, const RE2& re, A&&... a) {
452
+ static bool FindAndConsume(absl::string_view* input, const RE2& re, A&&... a) {
451
453
  return Apply(FindAndConsumeN, input, re, Arg(std::forward<A>(a))...);
452
454
  }
453
455
 
@@ -466,7 +468,7 @@ class RE2 {
466
468
  // false otherwise.
467
469
  static bool Replace(std::string* str,
468
470
  const RE2& re,
469
- const StringPiece& rewrite);
471
+ absl::string_view rewrite);
470
472
 
471
473
  // Like Replace(), except replaces successive non-overlapping occurrences
472
474
  // of the pattern in the string with the rewrite. E.g.
@@ -483,7 +485,7 @@ class RE2 {
483
485
  // Returns the number of replacements made.
484
486
  static int GlobalReplace(std::string* str,
485
487
  const RE2& re,
486
- const StringPiece& rewrite);
488
+ absl::string_view rewrite);
487
489
 
488
490
  // Like Replace, except that if the pattern matches, "rewrite"
489
491
  // is copied into "out" with substitutions. The non-matching
@@ -493,9 +495,9 @@ class RE2 {
493
495
  // successfully; if no match occurs, the string is left unaffected.
494
496
  //
495
497
  // REQUIRES: "text" must not alias any part of "*out".
496
- static bool Extract(const StringPiece& text,
498
+ static bool Extract(absl::string_view text,
497
499
  const RE2& re,
498
- const StringPiece& rewrite,
500
+ absl::string_view rewrite,
499
501
  std::string* out);
500
502
 
501
503
  // Escapes all potentially meaningful regexp characters in
@@ -504,7 +506,7 @@ class RE2 {
504
506
  // 1.5-2.0?
505
507
  // may become:
506
508
  // 1\.5\-2\.0\?
507
- static std::string QuoteMeta(const StringPiece& unquoted);
509
+ static std::string QuoteMeta(absl::string_view unquoted);
508
510
 
509
511
  // Computes range for any strings matching regexp. The min and max can in
510
512
  // some cases be arbitrarily precise, so the caller gets to specify the
@@ -565,15 +567,15 @@ class RE2 {
565
567
  // Doesn't make sense to use nsubmatch > 1 + NumberOfCapturingGroups(),
566
568
  // but will be handled correctly.
567
569
  //
568
- // Passing text == StringPiece(NULL, 0) will be handled like any other
570
+ // Passing text == absl::string_view() will be handled like any other
569
571
  // empty string, but note that on return, it will not be possible to tell
570
572
  // whether submatch i matched the empty string or did not match:
571
573
  // either way, submatch[i].data() == NULL.
572
- bool Match(const StringPiece& text,
574
+ bool Match(absl::string_view text,
573
575
  size_t startpos,
574
576
  size_t endpos,
575
577
  Anchor re_anchor,
576
- StringPiece* submatch,
578
+ absl::string_view* submatch,
577
579
  int nsubmatch) const;
578
580
 
579
581
  // Check that the given rewrite string is suitable for use with this
@@ -584,12 +586,12 @@ class RE2 {
584
586
  // '\' followed by anything other than a digit or '\'.
585
587
  // A true return value guarantees that Replace() and Extract() won't
586
588
  // fail because of a bad rewrite string.
587
- bool CheckRewriteString(const StringPiece& rewrite,
589
+ bool CheckRewriteString(absl::string_view rewrite,
588
590
  std::string* error) const;
589
591
 
590
592
  // Returns the maximum submatch needed for the rewrite to be done by
591
593
  // Replace(). E.g. if rewrite == "foo \\2,\\1", returns 2.
592
- static int MaxSubmatch(const StringPiece& rewrite);
594
+ static int MaxSubmatch(absl::string_view rewrite);
593
595
 
594
596
  // Append the "rewrite" string, with backslash substitutions from "vec",
595
597
  // to string "out".
@@ -597,8 +599,8 @@ class RE2 {
597
599
  // rewrite string. CheckRewriteString guarantees that the rewrite will
598
600
  // be sucessful.
599
601
  bool Rewrite(std::string* out,
600
- const StringPiece& rewrite,
601
- const StringPiece* vec,
602
+ absl::string_view rewrite,
603
+ const absl::string_view* vec,
602
604
  int veclen) const;
603
605
 
604
606
  // Constructor options
@@ -757,9 +759,9 @@ class RE2 {
757
759
  static void FUZZING_ONLY_set_maximum_global_replace_count(int i);
758
760
 
759
761
  private:
760
- void Init(const StringPiece& pattern, const Options& options);
762
+ void Init(absl::string_view pattern, const Options& options);
761
763
 
762
- bool DoMatch(const StringPiece& text,
764
+ bool DoMatch(absl::string_view text,
763
765
  Anchor re_anchor,
764
766
  size_t* consumed,
765
767
  const Arg* const args[],
@@ -792,9 +794,9 @@ class RE2 {
792
794
  // Map from capture indices to names
793
795
  mutable const std::map<int, std::string>* group_names_;
794
796
 
795
- mutable std::once_flag rprog_once_;
796
- mutable std::once_flag named_groups_once_;
797
- mutable std::once_flag group_names_once_;
797
+ mutable absl::once_flag rprog_once_;
798
+ mutable absl::once_flag named_groups_once_;
799
+ mutable absl::once_flag group_names_once_;
798
800
  };
799
801
 
800
802
  /***** Implementation details *****/
@@ -805,7 +807,7 @@ namespace re2_internal {
805
807
  template <typename T> struct Parse3ary : public std::false_type {};
806
808
  template <> struct Parse3ary<void> : public std::true_type {};
807
809
  template <> struct Parse3ary<std::string> : public std::true_type {};
808
- template <> struct Parse3ary<StringPiece> : public std::true_type {};
810
+ template <> struct Parse3ary<absl::string_view> : public std::true_type {};
809
811
  template <> struct Parse3ary<char> : public std::true_type {};
810
812
  template <> struct Parse3ary<signed char> : public std::true_type {};
811
813
  template <> struct Parse3ary<unsigned char> : public std::true_type {};
@@ -829,6 +831,42 @@ template <> struct Parse4ary<unsigned long long> : public std::true_type {};
829
831
  template <typename T>
830
832
  bool Parse(const char* str, size_t n, T* dest, int radix);
831
833
 
834
+ // Support absl::optional<T> for all T with a stock parser.
835
+ template <typename T> struct Parse3ary<absl::optional<T>> : public Parse3ary<T> {};
836
+ template <typename T> struct Parse4ary<absl::optional<T>> : public Parse4ary<T> {};
837
+
838
+ template <typename T>
839
+ bool Parse(const char* str, size_t n, absl::optional<T>* dest) {
840
+ if (str == NULL) {
841
+ if (dest != NULL)
842
+ dest->reset();
843
+ return true;
844
+ }
845
+ T tmp;
846
+ if (Parse(str, n, &tmp)) {
847
+ if (dest != NULL)
848
+ dest->emplace(std::move(tmp));
849
+ return true;
850
+ }
851
+ return false;
852
+ }
853
+
854
+ template <typename T>
855
+ bool Parse(const char* str, size_t n, absl::optional<T>* dest, int radix) {
856
+ if (str == NULL) {
857
+ if (dest != NULL)
858
+ dest->reset();
859
+ return true;
860
+ }
861
+ T tmp;
862
+ if (Parse(str, n, &tmp, radix)) {
863
+ if (dest != NULL)
864
+ dest->emplace(std::move(tmp));
865
+ return true;
866
+ }
867
+ return false;
868
+ }
869
+
832
870
  } // namespace re2_internal
833
871
 
834
872
  class RE2::Arg {
@@ -955,7 +993,7 @@ class LazyRE2 {
955
993
 
956
994
  // Named accessor/initializer:
957
995
  RE2* get() const {
958
- std::call_once(once_, &LazyRE2::Init, this);
996
+ absl::call_once(once_, &LazyRE2::Init, this);
959
997
  return ptr_;
960
998
  }
961
999
 
@@ -965,7 +1003,7 @@ class LazyRE2 {
965
1003
  NoArg barrier_against_excess_initializers_;
966
1004
 
967
1005
  mutable RE2* ptr_;
968
- mutable std::once_flag once_;
1006
+ mutable absl::once_flag once_;
969
1007
 
970
1008
  private:
971
1009
  static void Init(const LazyRE2* lazy_re2) {
@@ -12,16 +12,15 @@
12
12
  #include <string.h>
13
13
  #include <algorithm>
14
14
  #include <map>
15
- #include <mutex>
16
15
  #include <string>
17
16
  #include <vector>
18
17
 
19
- #include "util/util.h"
18
+ #include "absl/base/call_once.h"
19
+ #include "absl/base/macros.h"
20
+ #include "absl/synchronization/mutex.h"
20
21
  #include "util/logging.h"
21
- #include "util/mutex.h"
22
22
  #include "util/utf.h"
23
23
  #include "re2/pod_array.h"
24
- #include "re2/stringpiece.h"
25
24
  #include "re2/walker-inl.h"
26
25
 
27
26
  namespace re2 {
@@ -76,12 +75,12 @@ bool Regexp::QuickDestroy() {
76
75
 
77
76
  // Similar to EmptyStorage in re2.cc.
78
77
  struct RefStorage {
79
- Mutex ref_mutex;
78
+ absl::Mutex ref_mutex;
80
79
  std::map<Regexp*, int> ref_map;
81
80
  };
82
81
  alignas(RefStorage) static char ref_storage[sizeof(RefStorage)];
83
82
 
84
- static inline Mutex* ref_mutex() {
83
+ static inline absl::Mutex* ref_mutex() {
85
84
  return &reinterpret_cast<RefStorage*>(ref_storage)->ref_mutex;
86
85
  }
87
86
 
@@ -93,20 +92,20 @@ int Regexp::Ref() {
93
92
  if (ref_ < kMaxRef)
94
93
  return ref_;
95
94
 
96
- MutexLock l(ref_mutex());
95
+ absl::MutexLock l(ref_mutex());
97
96
  return (*ref_map())[this];
98
97
  }
99
98
 
100
99
  // Increments reference count, returns object as convenience.
101
100
  Regexp* Regexp::Incref() {
102
101
  if (ref_ >= kMaxRef-1) {
103
- static std::once_flag ref_once;
104
- std::call_once(ref_once, []() {
102
+ static absl::once_flag ref_once;
103
+ absl::call_once(ref_once, []() {
105
104
  (void) new (ref_storage) RefStorage;
106
105
  });
107
106
 
108
107
  // Store ref count in overflow map.
109
- MutexLock l(ref_mutex());
108
+ absl::MutexLock l(ref_mutex());
110
109
  if (ref_ == kMaxRef) {
111
110
  // already overflowed
112
111
  (*ref_map())[this]++;
@@ -126,7 +125,7 @@ Regexp* Regexp::Incref() {
126
125
  void Regexp::Decref() {
127
126
  if (ref_ == kMaxRef) {
128
127
  // Ref count is stored in overflow map.
129
- MutexLock l(ref_mutex());
128
+ absl::MutexLock l(ref_mutex());
130
129
  int r = (*ref_map())[this] - 1;
131
130
  if (r < kMaxRef) {
132
131
  ref_ = static_cast<uint16_t>(r);
@@ -519,7 +518,7 @@ static const char *kErrorStrings[] = {
519
518
  };
520
519
 
521
520
  std::string RegexpStatus::CodeText(enum RegexpStatusCode code) {
522
- if (code < 0 || code >= arraysize(kErrorStrings))
521
+ if (code < 0 || code >= ABSL_ARRAYSIZE(kErrorStrings))
523
522
  code = kRegexpInternalError;
524
523
  return kErrorStrings[code];
525
524
  }
@@ -92,10 +92,9 @@
92
92
  #include <set>
93
93
  #include <string>
94
94
 
95
- #include "util/util.h"
95
+ #include "absl/strings/string_view.h"
96
96
  #include "util/logging.h"
97
97
  #include "util/utf.h"
98
- #include "re2/stringpiece.h"
99
98
 
100
99
  namespace re2 {
101
100
 
@@ -195,10 +194,10 @@ class RegexpStatus {
195
194
  ~RegexpStatus() { delete tmp_; }
196
195
 
197
196
  void set_code(RegexpStatusCode code) { code_ = code; }
198
- void set_error_arg(const StringPiece& error_arg) { error_arg_ = error_arg; }
197
+ void set_error_arg(absl::string_view error_arg) { error_arg_ = error_arg; }
199
198
  void set_tmp(std::string* tmp) { delete tmp_; tmp_ = tmp; }
200
199
  RegexpStatusCode code() const { return code_; }
201
- const StringPiece& error_arg() const { return error_arg_; }
200
+ absl::string_view error_arg() const { return error_arg_; }
202
201
  bool ok() const { return code() == kRegexpSuccess; }
203
202
 
204
203
  // Copies state from status.
@@ -213,9 +212,9 @@ class RegexpStatus {
213
212
  std::string Text() const;
214
213
 
215
214
  private:
216
- RegexpStatusCode code_; // Kind of error
217
- StringPiece error_arg_; // Piece of regexp containing syntax error.
218
- std::string* tmp_; // Temporary storage, possibly where error_arg_ is.
215
+ RegexpStatusCode code_; // Kind of error.
216
+ absl::string_view error_arg_; // Piece of regexp containing syntax error.
217
+ std::string* tmp_; // Temporary storage, possibly for error_arg_.
219
218
 
220
219
  RegexpStatus(const RegexpStatus&) = delete;
221
220
  RegexpStatus& operator=(const RegexpStatus&) = delete;
@@ -352,7 +351,7 @@ class Regexp {
352
351
  // Parses string s to produce regular expression, returned.
353
352
  // Caller must release return value with re->Decref().
354
353
  // On failure, sets *status (if status != NULL) and returns NULL.
355
- static Regexp* Parse(const StringPiece& s, ParseFlags flags,
354
+ static Regexp* Parse(absl::string_view s, ParseFlags flags,
356
355
  RegexpStatus* status);
357
356
 
358
357
  // Returns a _new_ simplified version of the current regexp.
@@ -369,7 +368,7 @@ class Regexp {
369
368
  // Parses the regexp src and then simplifies it and sets *dst to the
370
369
  // string representation of the simplified form. Returns true on success.
371
370
  // Returns false and sets *status (if status != NULL) on parse error.
372
- static bool SimplifyRegexp(const StringPiece& src, ParseFlags flags,
371
+ static bool SimplifyRegexp(absl::string_view src, ParseFlags flags,
373
372
  std::string* dst, RegexpStatus* status);
374
373
 
375
374
  // Returns the number of capturing groups in the regexp.
@@ -467,7 +466,7 @@ class Regexp {
467
466
  class ParseState;
468
467
 
469
468
  friend class ParseState;
470
- friend bool ParseCharClass(StringPiece* s, Regexp** out_re,
469
+ friend bool ParseCharClass(absl::string_view* s, Regexp** out_re,
471
470
  RegexpStatus* status);
472
471
 
473
472
  // Helper for testing [sic].
@@ -9,13 +9,11 @@
9
9
  #include <memory>
10
10
  #include <utility>
11
11
 
12
- #include "util/util.h"
13
12
  #include "util/logging.h"
14
13
  #include "re2/pod_array.h"
15
14
  #include "re2/prog.h"
16
15
  #include "re2/re2.h"
17
16
  #include "re2/regexp.h"
18
- #include "re2/stringpiece.h"
19
17
 
20
18
  namespace re2 {
21
19
 
@@ -52,7 +50,7 @@ RE2::Set& RE2::Set::operator=(Set&& other) {
52
50
  return *this;
53
51
  }
54
52
 
55
- int RE2::Set::Add(const StringPiece& pattern, std::string* error) {
53
+ int RE2::Set::Add(absl::string_view pattern, std::string* error) {
56
54
  if (compiled_) {
57
55
  LOG(DFATAL) << "RE2::Set::Add() called after compiling";
58
56
  return -1;
@@ -121,11 +119,11 @@ bool RE2::Set::Compile() {
121
119
  return prog_ != nullptr;
122
120
  }
123
121
 
124
- bool RE2::Set::Match(const StringPiece& text, std::vector<int>* v) const {
122
+ bool RE2::Set::Match(absl::string_view text, std::vector<int>* v) const {
125
123
  return Match(text, v, NULL);
126
124
  }
127
125
 
128
- bool RE2::Set::Match(const StringPiece& text, std::vector<int>* v,
126
+ bool RE2::Set::Match(absl::string_view text, std::vector<int>* v,
129
127
  ErrorInfo* error_info) const {
130
128
  if (!compiled_) {
131
129
  if (error_info != NULL)
@@ -10,6 +10,7 @@
10
10
  #include <utility>
11
11
  #include <vector>
12
12
 
13
+ #include "absl/strings/string_view.h"
13
14
  #include "re2/re2.h"
14
15
 
15
16
  namespace re2 {
@@ -50,7 +51,7 @@ class RE2::Set {
50
51
  // Indices are assigned in sequential order starting from 0.
51
52
  // Errors do not increment the index; if error is not NULL, *error will hold
52
53
  // the error message from the parser.
53
- int Add(const StringPiece& pattern, std::string* error);
54
+ int Add(absl::string_view pattern, std::string* error);
54
55
 
55
56
  // Compiles the set in preparation for matching.
56
57
  // Returns false if the compiler runs out of memory.
@@ -61,12 +62,12 @@ class RE2::Set {
61
62
  // Returns true if text matches at least one of the regexps in the set.
62
63
  // Fills v (if not NULL) with the indices of the matching regexps.
63
64
  // Callers must not expect v to be sorted.
64
- bool Match(const StringPiece& text, std::vector<int>* v) const;
65
+ bool Match(absl::string_view text, std::vector<int>* v) const;
65
66
 
66
67
  // As above, but populates error_info (if not NULL) when none of the regexps
67
68
  // in the set matched. This can inform callers when DFA execution fails, for
68
69
  // example, because they might wish to handle that case differently.
69
- bool Match(const StringPiece& text, std::vector<int>* v,
70
+ bool Match(absl::string_view text, std::vector<int>* v,
70
71
  ErrorInfo* error_info) const;
71
72
 
72
73
  private:
@@ -8,7 +8,6 @@
8
8
 
9
9
  #include <string>
10
10
 
11
- #include "util/util.h"
12
11
  #include "util/logging.h"
13
12
  #include "util/utf.h"
14
13
  #include "re2/pod_array.h"
@@ -20,7 +19,7 @@ namespace re2 {
20
19
  // Parses the regexp src and then simplifies it and sets *dst to the
21
20
  // string representation of the simplified form. Returns true on success.
22
21
  // Returns false and sets *error (if error != NULL) on error.
23
- bool Regexp::SimplifyRegexp(const StringPiece& src, ParseFlags flags,
22
+ bool Regexp::SimplifyRegexp(absl::string_view src, ParseFlags flags,
24
23
  std::string* dst, RegexpStatus* status) {
25
24
  Regexp* re = Parse(src, flags, status);
26
25
  if (re == NULL)
@@ -0,0 +1,24 @@
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
+ #ifndef RE2_STRINGPIECE_H_
6
+ #define RE2_STRINGPIECE_H_
7
+
8
+ #include "absl/strings/string_view.h"
9
+
10
+ namespace re2 {
11
+
12
+ // RE2 has two versions: "sans Abseil" in the main branch; and "avec Abseil" in
13
+ // the abseil branch. This has led to a diamond dependency problem for projects
14
+ // like Envoy: as per https://github.com/google/re2/issues/388, GoogleTest took
15
+ // a dependency on RE2 avec Abseil, but other things depend on RE2 sans Abseil.
16
+ // To resolve this conflict until both versions can migrate to std::string_view
17
+ // (C++17), those other things must be able to #include "re2/stringpiece.h" and
18
+ // use re2::StringPiece. (This is a hack, obviously, but it beats telling every
19
+ // project in this situation that they have to perform source transformations.)
20
+ using StringPiece = absl::string_view;
21
+
22
+ } // namespace re2
23
+
24
+ #endif // RE2_STRINGPIECE_H_
@@ -27,7 +27,7 @@
27
27
  #include <stdint.h>
28
28
  #include <string.h>
29
29
 
30
- #include "util/util.h"
30
+ #include "absl/base/macros.h"
31
31
  #include "util/logging.h"
32
32
  #include "re2/pod_array.h"
33
33
  #include "re2/prog.h"
@@ -55,9 +55,8 @@ class Backtracker {
55
55
  public:
56
56
  explicit Backtracker(Prog* prog);
57
57
 
58
- bool Search(const StringPiece& text, const StringPiece& context,
59
- bool anchored, bool longest,
60
- StringPiece* submatch, int nsubmatch);
58
+ bool Search(absl::string_view text, absl::string_view context, bool anchored,
59
+ bool longest, absl::string_view* submatch, int nsubmatch);
61
60
 
62
61
  private:
63
62
  // Explores from instruction id at string position p looking for a match.
@@ -69,14 +68,14 @@ class Backtracker {
69
68
  bool Try(int id, const char* p);
70
69
 
71
70
  // Search parameters
72
- Prog* prog_; // program being run
73
- StringPiece text_; // text being searched
74
- StringPiece context_; // greater context of text being searched
75
- bool anchored_; // whether search is anchored at text.begin()
76
- bool longest_; // whether search wants leftmost-longest match
77
- bool endmatch_; // whether search must end at text.end()
78
- StringPiece *submatch_; // submatches to fill in
79
- int nsubmatch_; // # of submatches to fill in
71
+ Prog* prog_; // program being run
72
+ absl::string_view text_; // text being searched
73
+ absl::string_view context_; // greater context of text being searched
74
+ bool anchored_; // whether search is anchored at text.begin()
75
+ bool longest_; // whether search wants leftmost-longest match
76
+ bool endmatch_; // whether search must end at text.end()
77
+ absl::string_view* submatch_; // submatches to fill in
78
+ int nsubmatch_; // # of submatches to fill in
80
79
 
81
80
  // Search state
82
81
  const char* cap_[64]; // capture registers
@@ -96,9 +95,9 @@ Backtracker::Backtracker(Prog* prog)
96
95
  }
97
96
 
98
97
  // Runs a backtracking search.
99
- bool Backtracker::Search(const StringPiece& text, const StringPiece& context,
98
+ bool Backtracker::Search(absl::string_view text, absl::string_view context,
100
99
  bool anchored, bool longest,
101
- StringPiece* submatch, int nsubmatch) {
100
+ absl::string_view* submatch, int nsubmatch) {
102
101
  text_ = text;
103
102
  context_ = context;
104
103
  if (context_.data() == NULL)
@@ -112,17 +111,17 @@ bool Backtracker::Search(const StringPiece& text, const StringPiece& context,
112
111
  endmatch_ = prog_->anchor_end();
113
112
  submatch_ = submatch;
114
113
  nsubmatch_ = nsubmatch;
115
- CHECK_LT(2*nsubmatch_, static_cast<int>(arraysize(cap_)));
114
+ CHECK_LT(2*nsubmatch_, static_cast<int>(ABSL_ARRAYSIZE(cap_)));
116
115
  memset(cap_, 0, sizeof cap_);
117
116
 
118
117
  // We use submatch_[0] for our own bookkeeping,
119
118
  // so it had better exist.
120
- StringPiece sp0;
119
+ absl::string_view sp0;
121
120
  if (nsubmatch < 1) {
122
121
  submatch_ = &sp0;
123
122
  nsubmatch_ = 1;
124
123
  }
125
- submatch_[0] = StringPiece();
124
+ submatch_[0] = absl::string_view();
126
125
 
127
126
  // Allocate new visited_ bitmap -- size is proportional
128
127
  // to text, so have to reallocate on each call to Search.
@@ -203,7 +202,7 @@ bool Backtracker::Try(int id, const char* p) {
203
202
 
204
203
  case kInstCapture:
205
204
  if (0 <= ip->cap() &&
206
- ip->cap() < static_cast<int>(arraysize(cap_))) {
205
+ ip->cap() < static_cast<int>(ABSL_ARRAYSIZE(cap_))) {
207
206
  // Capture p to register, but save old value.
208
207
  const char* q = cap_[ip->cap()];
209
208
  cap_[ip->cap()] = p;
@@ -232,7 +231,7 @@ bool Backtracker::Try(int id, const char* p) {
232
231
  (longest_ && p > submatch_[0].data() + submatch_[0].size())) {
233
232
  // First match so far - or better match.
234
233
  for (int i = 0; i < nsubmatch_; i++)
235
- submatch_[i] = StringPiece(
234
+ submatch_[i] = absl::string_view(
236
235
  cap_[2 * i], static_cast<size_t>(cap_[2 * i + 1] - cap_[2 * i]));
237
236
  }
238
237
  return true;
@@ -243,16 +242,14 @@ bool Backtracker::Try(int id, const char* p) {
243
242
  }
244
243
 
245
244
  // Runs a backtracking search.
246
- bool Prog::UnsafeSearchBacktrack(const StringPiece& text,
247
- const StringPiece& context,
248
- Anchor anchor,
249
- MatchKind kind,
250
- StringPiece* match,
245
+ bool Prog::UnsafeSearchBacktrack(absl::string_view text,
246
+ absl::string_view context, Anchor anchor,
247
+ MatchKind kind, absl::string_view* match,
251
248
  int nmatch) {
252
249
  // If full match, we ask for an anchored longest match
253
250
  // and then check that match[0] == text.
254
251
  // So make sure match[0] exists.
255
- StringPiece sp0;
252
+ absl::string_view sp0;
256
253
  if (kind == kFullMatch) {
257
254
  anchor = kAnchored;
258
255
  if (nmatch < 1) {