re2 1.10.2 → 1.11.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 (42) hide show
  1. package/.prettierrc +3 -1
  2. package/.travis.yml +1 -1
  3. package/README.md +9 -8
  4. package/lib/addon.cc +4 -6
  5. package/lib/exec.cc +8 -0
  6. package/lib/wrapped_re2.h +1 -1
  7. package/package.json +5 -3
  8. package/re2.d.ts +5 -1
  9. package/tests/test_exec.js +1 -0
  10. package/vendor/re2/bitstate.cc +5 -1
  11. package/vendor/re2/compile.cc +1 -1
  12. package/vendor/re2/dfa.cc +8 -11
  13. package/vendor/re2/nfa.cc +33 -16
  14. package/vendor/re2/onepass.cc +4 -4
  15. package/vendor/re2/parse.cc +32 -32
  16. package/vendor/{util → re2}/pod_array.h +3 -3
  17. package/vendor/re2/prefilter_tree.h +1 -1
  18. package/vendor/re2/prog.h +3 -3
  19. package/vendor/re2/re2.cc +3 -3
  20. package/vendor/re2/set.cc +2 -2
  21. package/vendor/re2/simplify.cc +1 -1
  22. package/vendor/{util → re2}/sparse_array.h +4 -4
  23. package/vendor/{util → re2}/sparse_set.h +4 -4
  24. package/vendor/re2/testing/backtrack.cc +4 -0
  25. package/vendor/re2/testing/dfa_test.cc +12 -10
  26. package/vendor/re2/testing/dump.cc +4 -10
  27. package/vendor/re2/testing/exhaustive1_test.cc +2 -7
  28. package/vendor/re2/testing/exhaustive2_test.cc +0 -1
  29. package/vendor/re2/testing/exhaustive_tester.cc +11 -8
  30. package/vendor/re2/testing/random_test.cc +9 -7
  31. package/vendor/re2/testing/regexp_benchmark.cc +435 -404
  32. package/vendor/re2/testing/regexp_generator.cc +1 -1
  33. package/vendor/re2/testing/tester.cc +19 -14
  34. package/vendor/re2/walker-inl.h +1 -1
  35. package/vendor/util/benchmark.cc +83 -113
  36. package/vendor/util/benchmark.h +138 -25
  37. package/vendor/util/flags.h +8 -11
  38. package/vendor/util/malloc_counter.h +19 -0
  39. package/vendor/util/pcre.cc +7 -31
  40. package/vendor/util/test.cc +4 -1
  41. package/vendor/util/test.h +4 -12
  42. package/vendor/util/util.h +8 -0
@@ -21,8 +21,8 @@
21
21
  #include <vector>
22
22
 
23
23
  #include "util/util.h"
24
- #include "util/sparse_array.h"
25
24
  #include "re2/prefilter.h"
25
+ #include "re2/sparse_array.h"
26
26
 
27
27
  namespace re2 {
28
28
 
package/vendor/re2/prog.h CHANGED
@@ -18,10 +18,10 @@
18
18
 
19
19
  #include "util/util.h"
20
20
  #include "util/logging.h"
21
- #include "util/pod_array.h"
22
- #include "util/sparse_array.h"
23
- #include "util/sparse_set.h"
21
+ #include "re2/pod_array.h"
24
22
  #include "re2/re2.h"
23
+ #include "re2/sparse_array.h"
24
+ #include "re2/sparse_set.h"
25
25
 
26
26
  namespace re2 {
27
27
 
package/vendor/re2/re2.cc CHANGED
@@ -24,11 +24,11 @@
24
24
 
25
25
  #include "util/util.h"
26
26
  #include "util/logging.h"
27
- #include "util/sparse_array.h"
28
27
  #include "util/strutil.h"
29
28
  #include "util/utf.h"
30
29
  #include "re2/prog.h"
31
30
  #include "re2/regexp.h"
31
+ #include "re2/sparse_array.h"
32
32
 
33
33
  namespace re2 {
34
34
 
@@ -408,7 +408,7 @@ int RE2::GlobalReplace(std::string* str,
408
408
  break;
409
409
  if (p < vec[0].data())
410
410
  out.append(p, vec[0].data() - p);
411
- if (vec[0].data() == lastend && vec[0].size() == 0) {
411
+ if (vec[0].data() == lastend && vec[0].empty()) {
412
412
  // Disallow empty match at end of last match: skip ahead.
413
413
  //
414
414
  // fullrune() takes int, not ptrdiff_t. However, it just looks
@@ -934,7 +934,7 @@ bool RE2::Rewrite(std::string* out,
934
934
  return false;
935
935
  }
936
936
  StringPiece snip = vec[n];
937
- if (snip.size() > 0)
937
+ if (!snip.empty())
938
938
  out->append(snip.data(), snip.size());
939
939
  } else if (c == '\\') {
940
940
  out->push_back('\\');
package/vendor/re2/set.cc CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
11
  #include "util/util.h"
12
12
  #include "util/logging.h"
13
- #include "util/pod_array.h"
14
- #include "re2/stringpiece.h"
13
+ #include "re2/pod_array.h"
15
14
  #include "re2/prog.h"
16
15
  #include "re2/re2.h"
17
16
  #include "re2/regexp.h"
17
+ #include "re2/stringpiece.h"
18
18
 
19
19
  namespace re2 {
20
20
 
@@ -10,8 +10,8 @@
10
10
 
11
11
  #include "util/util.h"
12
12
  #include "util/logging.h"
13
- #include "util/pod_array.h"
14
13
  #include "util/utf.h"
14
+ #include "re2/pod_array.h"
15
15
  #include "re2/regexp.h"
16
16
  #include "re2/walker-inl.h"
17
17
 
@@ -2,8 +2,8 @@
2
2
  // Use of this source code is governed by a BSD-style
3
3
  // license that can be found in the LICENSE file.
4
4
 
5
- #ifndef UTIL_SPARSE_ARRAY_H_
6
- #define UTIL_SPARSE_ARRAY_H_
5
+ #ifndef RE2_SPARSE_ARRAY_H_
6
+ #define RE2_SPARSE_ARRAY_H_
7
7
 
8
8
  // DESCRIPTION
9
9
  //
@@ -102,7 +102,7 @@
102
102
  #include <memory>
103
103
  #include <utility>
104
104
 
105
- #include "util/pod_array.h"
105
+ #include "re2/pod_array.h"
106
106
 
107
107
  namespace re2 {
108
108
 
@@ -389,4 +389,4 @@ template<typename Value> bool SparseArray<Value>::less(const IndexValue& a,
389
389
 
390
390
  } // namespace re2
391
391
 
392
- #endif // UTIL_SPARSE_ARRAY_H_
392
+ #endif // RE2_SPARSE_ARRAY_H_
@@ -2,8 +2,8 @@
2
2
  // Use of this source code is governed by a BSD-style
3
3
  // license that can be found in the LICENSE file.
4
4
 
5
- #ifndef UTIL_SPARSE_SET_H_
6
- #define UTIL_SPARSE_SET_H_
5
+ #ifndef RE2_SPARSE_SET_H_
6
+ #define RE2_SPARSE_SET_H_
7
7
 
8
8
  // DESCRIPTION
9
9
  //
@@ -61,7 +61,7 @@
61
61
  #include <memory>
62
62
  #include <utility>
63
63
 
64
- #include "util/pod_array.h"
64
+ #include "re2/pod_array.h"
65
65
 
66
66
  namespace re2 {
67
67
 
@@ -261,4 +261,4 @@ typedef SparseSetT<void> SparseSet;
261
261
 
262
262
  } // namespace re2
263
263
 
264
- #endif // UTIL_SPARSE_SET_H_
264
+ #endif // RE2_SPARSE_SET_H_
@@ -148,6 +148,10 @@ bool Backtracker::Search(const StringPiece& text, const StringPiece& context,
148
148
  cap_[0] = p;
149
149
  if (Visit(prog_->start(), p)) // Match must be leftmost; done.
150
150
  return true;
151
+ // Avoid invoking undefined behavior (arithmetic on a null pointer)
152
+ // by simply not continuing the loop.
153
+ if (p == NULL)
154
+ break;
151
155
  }
152
156
  return false;
153
157
  }
@@ -8,7 +8,9 @@
8
8
  #include <vector>
9
9
 
10
10
  #include "util/test.h"
11
+ #include "util/flags.h"
11
12
  #include "util/logging.h"
13
+ #include "util/malloc_counter.h"
12
14
  #include "util/strutil.h"
13
15
  #include "re2/prog.h"
14
16
  #include "re2/re2.h"
@@ -18,9 +20,9 @@
18
20
 
19
21
  static const bool UsingMallocCounter = false;
20
22
 
21
- DEFINE_int32(size, 8, "log2(number of DFA nodes)");
22
- DEFINE_int32(repeat, 2, "Repetition count.");
23
- DEFINE_int32(threads, 4, "number of threads");
23
+ DEFINE_FLAG(int, size, 8, "log2(number of DFA nodes)");
24
+ DEFINE_FLAG(int, repeat, 2, "Repetition count.");
25
+ DEFINE_FLAG(int, threads, 4, "number of threads");
24
26
 
25
27
  namespace re2 {
26
28
 
@@ -34,7 +36,7 @@ static void DoBuild(Prog* prog) {
34
36
  TEST(Multithreaded, BuildEntireDFA) {
35
37
  // Create regexp with 2^FLAGS_size states in DFA.
36
38
  std::string s = "a";
37
- for (int i = 0; i < FLAGS_size; i++)
39
+ for (int i = 0; i < GetFlag(FLAGS_size); i++)
38
40
  s += "[ab]";
39
41
  s += "b";
40
42
  Regexp* re = Regexp::Parse(s, Regexp::LikePerl, NULL);
@@ -52,14 +54,14 @@ TEST(Multithreaded, BuildEntireDFA) {
52
54
  }
53
55
 
54
56
  // Build the DFA simultaneously in a bunch of threads.
55
- for (int i = 0; i < FLAGS_repeat; i++) {
57
+ for (int i = 0; i < GetFlag(FLAGS_repeat); i++) {
56
58
  Prog* prog = re->CompileToProg(0);
57
59
  ASSERT_TRUE(prog != NULL);
58
60
 
59
61
  std::vector<std::thread> threads;
60
- for (int j = 0; j < FLAGS_threads; j++)
62
+ for (int j = 0; j < GetFlag(FLAGS_threads); j++)
61
63
  threads.emplace_back(DoBuild, prog);
62
- for (int j = 0; j < FLAGS_threads; j++)
64
+ for (int j = 0; j < GetFlag(FLAGS_threads); j++)
63
65
  threads[j].join();
64
66
 
65
67
  // One more compile, to make sure everything is okay.
@@ -259,14 +261,14 @@ TEST(Multithreaded, SearchDFA) {
259
261
 
260
262
  // Run the search simultaneously in a bunch of threads.
261
263
  // Reuse same flags for Multithreaded.BuildDFA above.
262
- for (int i = 0; i < FLAGS_repeat; i++) {
264
+ for (int i = 0; i < GetFlag(FLAGS_repeat); i++) {
263
265
  Prog* prog = re->CompileToProg(1<<n);
264
266
  ASSERT_TRUE(prog != NULL);
265
267
 
266
268
  std::vector<std::thread> threads;
267
- for (int j = 0; j < FLAGS_threads; j++)
269
+ for (int j = 0; j < GetFlag(FLAGS_threads); j++)
268
270
  threads.emplace_back(DoSearch, prog, match, no_match);
269
- for (int j = 0; j < FLAGS_threads; j++)
271
+ for (int j = 0; j < GetFlag(FLAGS_threads); j++)
270
272
  threads[j].join();
271
273
 
272
274
  delete prog;
@@ -25,9 +25,6 @@
25
25
  #include "re2/stringpiece.h"
26
26
  #include "re2/regexp.h"
27
27
 
28
- // Cause a link error if this file is used outside of testing.
29
- DECLARE_string(test_tmpdir);
30
-
31
28
  namespace re2 {
32
29
 
33
30
  static const char* kOpcodeNames[] = {
@@ -154,14 +151,11 @@ static void DumpRegexpAppending(Regexp* re, std::string* s) {
154
151
  }
155
152
 
156
153
  std::string Regexp::Dump() {
157
- std::string s;
158
-
159
- // Make sure being called from a unit test.
160
- if (FLAGS_test_tmpdir.empty()) {
161
- LOG(ERROR) << "Cannot use except for testing.";
162
- return s;
163
- }
154
+ // Make sure that we are being called from a unit test.
155
+ // Should cause a link error if used outside of testing.
156
+ CHECK(!::testing::TempDir().empty());
164
157
 
158
+ std::string s;
165
159
  DumpRegexpAppending(this, &s);
166
160
  return s;
167
161
  }
@@ -10,8 +10,6 @@
10
10
  #include "util/test.h"
11
11
  #include "re2/testing/exhaustive_tester.h"
12
12
 
13
- DECLARE_string(regexp_engines);
14
-
15
13
  namespace re2 {
16
14
 
17
15
  // Test simple repetition operators
@@ -34,11 +32,8 @@ TEST(Repetition, Capturing) {
34
32
  "%s* %s+ %s? %s*? %s+? %s??");
35
33
  ExhaustiveTest(3, 2, Split(" ", "a (a) b"), ops,
36
34
  7, Explode("ab"), "(?:%s)", "");
37
-
38
- // This would be a great test, but it runs forever when PCRE is enabled.
39
- if (FLAGS_regexp_engines.find("PCRE") == std::string::npos)
40
- ExhaustiveTest(3, 2, Split(" ", "a (a)"), ops,
41
- 50, Explode("a"), "(?:%s)", "");
35
+ ExhaustiveTest(3, 2, Split(" ", "a (a)"), ops,
36
+ 50, Explode("a"), "(?:%s)", "");
42
37
  }
43
38
 
44
39
  } // namespace re2
@@ -10,7 +10,6 @@
10
10
  #include <vector>
11
11
 
12
12
  #include "util/test.h"
13
- #include "re2/re2.h"
14
13
  #include "re2/testing/exhaustive_tester.h"
15
14
 
16
15
  namespace re2 {
@@ -14,6 +14,7 @@
14
14
  #include <stdio.h>
15
15
 
16
16
  #include "util/test.h"
17
+ #include "util/flags.h"
17
18
  #include "util/logging.h"
18
19
  #include "util/strutil.h"
19
20
  #include "re2/testing/exhaustive_tester.h"
@@ -24,11 +25,11 @@
24
25
  #define LOGGING 0
25
26
  #endif
26
27
 
27
- DEFINE_bool(show_regexps, false, "show regexps during testing");
28
+ DEFINE_FLAG(bool, show_regexps, false, "show regexps during testing");
28
29
 
29
- DEFINE_int32(max_bad_regexp_inputs, 1,
30
- "Stop testing a regular expression after finding this many "
31
- "strings that break it.");
30
+ DEFINE_FLAG(int, max_bad_regexp_inputs, 1,
31
+ "Stop testing a regular expression after finding this many "
32
+ "strings that break it.");
32
33
 
33
34
  namespace re2 {
34
35
 
@@ -66,7 +67,8 @@ static void PrintResult(const RE2& re, const StringPiece& input, RE2::Anchor anc
66
67
  printf("-");
67
68
  else
68
69
  printf("%td-%td",
69
- m[i].begin() - input.begin(), m[i].end() - input.begin());
70
+ m[i].begin() - input.begin(),
71
+ m[i].end() - input.begin());
70
72
  }
71
73
  }
72
74
 
@@ -76,10 +78,11 @@ static void PrintResult(const RE2& re, const StringPiece& input, RE2::Anchor anc
76
78
  void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) {
77
79
  regexps_++;
78
80
  std::string regexp = const_regexp;
79
- if (!topwrapper_.empty())
81
+ if (!topwrapper_.empty()) {
80
82
  regexp = StringPrintf(topwrapper_.c_str(), regexp.c_str());
83
+ }
81
84
 
82
- if (FLAGS_show_regexps) {
85
+ if (GetFlag(FLAGS_show_regexps)) {
83
86
  printf("\r%s", regexp.c_str());
84
87
  fflush(stdout);
85
88
  }
@@ -134,7 +137,7 @@ void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) {
134
137
  tests_++;
135
138
  if (!tester.TestInput(strgen_.Next())) {
136
139
  failures_++;
137
- if (++bad_inputs >= FLAGS_max_bad_regexp_inputs)
140
+ if (++bad_inputs >= GetFlag(FLAGS_max_bad_regexp_inputs))
138
141
  break;
139
142
  }
140
143
  }
@@ -9,12 +9,13 @@
9
9
  #include <vector>
10
10
 
11
11
  #include "util/test.h"
12
+ #include "util/flags.h"
12
13
  #include "re2/testing/exhaustive_tester.h"
13
14
 
14
- DEFINE_int32(regexpseed, 404, "Random regexp seed.");
15
- DEFINE_int32(regexpcount, 100, "How many random regexps to generate.");
16
- DEFINE_int32(stringseed, 200, "Random string seed.");
17
- DEFINE_int32(stringcount, 100, "How many random strings to generate.");
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.");
18
19
 
19
20
  namespace re2 {
20
21
 
@@ -37,8 +38,10 @@ static void RandomTest(int maxatoms, int maxops,
37
38
 
38
39
  ExhaustiveTester t(maxatoms, maxops, alphabet, ops,
39
40
  maxstrlen, stralphabet, wrapper, "");
40
- t.RandomStrings(FLAGS_stringseed, FLAGS_stringcount);
41
- t.GenerateRandom(FLAGS_regexpseed, FLAGS_regexpcount);
41
+ t.RandomStrings(GetFlag(FLAGS_stringseed),
42
+ GetFlag(FLAGS_stringcount));
43
+ t.GenerateRandom(GetFlag(FLAGS_regexpseed),
44
+ GetFlag(FLAGS_regexpcount));
42
45
  printf("%d regexps, %d tests, %d failures [%d/%d str]\n",
43
46
  t.regexps(), t.tests(), t.failures(), maxstrlen, (int)stralphabet.size());
44
47
  EXPECT_EQ(0, t.failures());
@@ -96,4 +99,3 @@ TEST(Random, Complicated) {
96
99
  }
97
100
 
98
101
  } // namespace re2
99
-