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
package/.prettierrc CHANGED
@@ -1,5 +1,7 @@
1
1
  {
2
2
  "printWidth": 160,
3
3
  "singleQuote": true,
4
- "bracketSpacing": false
4
+ "bracketSpacing": false,
5
+ "arrowParens": "avoid",
6
+ "trailingComma": "none"
5
7
  }
package/.travis.yml CHANGED
@@ -3,9 +3,9 @@ sudo: false
3
3
  language: node_js
4
4
 
5
5
  node_js:
6
- - "8"
7
6
  - "10"
8
7
  - "12"
8
+ - "14"
9
9
 
10
10
  addons:
11
11
  apt:
package/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # node-re2
2
2
 
3
3
  [![Build status][travis-image]][travis-url]
4
- [![Dependencies][deps-image]][deps-url]
5
- [![devDependencies][dev-deps-image]][dev-deps-url]
6
4
  [![NPM version][npm-image]][npm-url]
7
5
 
8
6
  [![Greenkeeper badge](https://badges.greenkeeper.io/uhop/node-re2.svg)](https://greenkeeper.io/)
9
-
7
+ [![Dependencies][deps-image]][deps-url]
8
+ [![devDependencies][dev-deps-image]][dev-deps-url]
10
9
 
11
10
  This project provides bindings for [RE2](https://github.com/google/re2):
12
11
  fast, safe alternative to backtracking regular expression engines written by [Russ Cox](http://swtch.com/~rsc/).
@@ -19,12 +18,14 @@ at his [Implementing Regular Expressions](http://swtch.com/~rsc/regexp/) page.
19
18
  but it lacks two features: backreferences and lookahead assertions. See below for more details.
20
19
 
21
20
  `RE2` object emulates standard `RegExp` making it a practical drop-in replacement in most cases.
22
- `RE2` is extended to provide `String`-based regular expression methods as well. To help converting
21
+ `RE2` is extended to provide `String`-based regular expression methods as well. To help to convert
23
22
  `RegExp` objects to `RE2` its constructor can take `RegExp` directly honoring all properties.
24
23
 
25
24
  It can work with [node.js buffers](http://nodejs.org/api/buffer.html) directly reducing overhead
26
25
  on recoding and copying characters, and making processing/parsing long files fast.
27
26
 
27
+ All documentation can be found in this README and in the [wiki](https://github.com/uhop/node-re2/wiki).
28
+
28
29
  ## Why use node-re2?
29
30
 
30
31
  The built-in Node.js regular expression engine can run in exponential time with a special combination:
@@ -347,12 +348,12 @@ for your platform, then run:
347
348
 
348
349
  npm install
349
350
 
350
- Or:
351
-
352
- yarn
353
-
354
351
  ## Release history
355
352
 
353
+ - 1.11.0 *Updated the way to initialize the extension (thx [BannerBomb](https://github.com/BannerBomb)).*
354
+ - 1.10.5 *Bugfix for optional groups (thx [Josh Yudaken](https://github.com/qix)), the latest version of `re2`.*
355
+ - 1.10.4 *Technical release: even better TypeScript types (thx [Louis Brann](https://github.com/louis-brann)).*
356
+ - 1.10.3 *Technical release: missing reference to TS types (thx [Jamie Magee](https://github.com/JamieMagee)).*
356
357
  - 1.10.2 *Technical release: added TypeScript types (thx [Jamie Magee](https://github.com/JamieMagee)).*
357
358
  - 1.10.1 *Updated `re2` to the latest version (thx [Jamie Magee](https://github.com/JamieMagee)), dropped Node 6.*
358
359
  - 1.10.0 *Added back support for Node 6 and Node 8. Now Node 6-12 is supported.*
package/lib/addon.cc CHANGED
@@ -26,7 +26,7 @@ static NAN_METHOD(GetUtf16Length)
26
26
  info.GetReturnValue().Set(-1);
27
27
  }
28
28
 
29
- void WrappedRE2::Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Object> module)
29
+ void WrappedRE2::Initialize(v8::Local<v8::Value> module, v8::Local<v8::Context> context)
30
30
  {
31
31
 
32
32
  // prepare constructor template
@@ -65,12 +65,10 @@ void WrappedRE2::Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Object>
65
65
  ctorTemplate.Reset(tpl);
66
66
 
67
67
  // return constructor as module's export
68
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), fun);
68
+ Nan::Set(module->ToObject(context).ToLocalChecked(), Nan::New("exports").ToLocalChecked(), fun);
69
69
  }
70
70
 
71
- void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Object> module)
71
+ NODE_MODULE_INIT()
72
72
  {
73
- WrappedRE2::Initialize(exports, module);
73
+ WrappedRE2::Initialize(module, context);
74
74
  }
75
-
76
- NODE_MODULE(re2, Initialize)
package/lib/exec.cc CHANGED
@@ -83,6 +83,10 @@ NAN_METHOD(WrappedRE2::Exec)
83
83
  {
84
84
  Nan::Set(result, i, Nan::CopyBuffer(item.data(), item.size()).ToLocalChecked());
85
85
  }
86
+ else
87
+ {
88
+ Nan::Set(result, i, Nan::Undefined());
89
+ }
86
90
  }
87
91
  Nan::Set(result, Nan::New("index").ToLocalChecked(), Nan::New<v8::Integer>(indexOffset + static_cast<int>(groups[0].data() - str.data)));
88
92
  }
@@ -95,6 +99,10 @@ NAN_METHOD(WrappedRE2::Exec)
95
99
  {
96
100
  Nan::Set(result, i, Nan::New(item.data(), item.size()).ToLocalChecked());
97
101
  }
102
+ else
103
+ {
104
+ Nan::Set(result, i, Nan::Undefined());
105
+ }
98
106
  }
99
107
  Nan::Set(result, Nan::New("index").ToLocalChecked(), Nan::New<v8::Integer>(indexOffset + static_cast<int>(getUtf16Length(str.data + lastIndex, groups[0].data()))));
100
108
  }
package/lib/wrapped_re2.h CHANGED
@@ -48,7 +48,7 @@ private:
48
48
  static Nan::Persistent<v8::FunctionTemplate> ctorTemplate;
49
49
 
50
50
  public:
51
- static void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Object> module);
51
+ static void Initialize(v8::Local<v8::Value> module, v8::Local<v8::Context> context);
52
52
 
53
53
  static inline bool HasInstance(v8::Local<v8::Object> object)
54
54
  {
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "re2",
3
- "version": "1.10.2",
3
+ "version": "1.11.0",
4
4
  "description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
5
5
  "homepage": "http://github.com/uhop/node-re2",
6
6
  "bugs": "http://github.com/uhop/node-re2/issues",
7
7
  "main": "re2.js",
8
+ "types": "re2.d.ts",
8
9
  "directories": {
9
10
  "test": "tests"
10
11
  },
11
12
  "dependencies": {
12
- "nan": "^2.14.0"
13
+ "nan": "^2.14.1"
13
14
  },
14
15
  "devDependencies": {
15
- "heya-unit": "^0.3.0"
16
+ "heya-unit": "^0.3.0",
17
+ "node-gyp": "^6.1.0"
16
18
  },
17
19
  "scripts": {
18
20
  "test": "node tests/tests.js"
package/re2.d.ts CHANGED
@@ -1 +1,5 @@
1
- export class RE2 extends RegExp {}
1
+ declare module 're2' {
2
+ class RE2 extends RegExp {}
3
+ export = RE2;
4
+ }
5
+
@@ -74,6 +74,7 @@ unit.add(module, [
74
74
 
75
75
  eval(t.TEST("result[1] === 'aaa'"));
76
76
  eval(t.TEST("result[2] === undefined"));
77
+ eval(t.TEST("result.length === 3"));
77
78
  },
78
79
  function test_execAnchoredToBeginning(t) {
79
80
  "use strict";
@@ -24,7 +24,7 @@
24
24
  #include <utility>
25
25
 
26
26
  #include "util/logging.h"
27
- #include "util/pod_array.h"
27
+ #include "re2/pod_array.h"
28
28
  #include "re2/prog.h"
29
29
  #include "re2/regexp.h"
30
30
 
@@ -342,6 +342,10 @@ bool BitState::Search(const StringPiece& text, const StringPiece& context,
342
342
  cap_[0] = p;
343
343
  if (TrySearch(prog_->start(), p)) // Match must be leftmost; done.
344
344
  return true;
345
+ // Avoid invoking undefined behavior (arithmetic on a null pointer)
346
+ // by simply not continuing the loop.
347
+ if (p == NULL)
348
+ break;
345
349
  }
346
350
  return false;
347
351
  }
@@ -14,8 +14,8 @@
14
14
  #include <utility>
15
15
 
16
16
  #include "util/logging.h"
17
- #include "util/pod_array.h"
18
17
  #include "util/utf.h"
18
+ #include "re2/pod_array.h"
19
19
  #include "re2/prog.h"
20
20
  #include "re2/re2.h"
21
21
  #include "re2/regexp.h"
package/vendor/re2/dfa.cc CHANGED
@@ -39,10 +39,10 @@
39
39
  #include "util/logging.h"
40
40
  #include "util/mix.h"
41
41
  #include "util/mutex.h"
42
- #include "util/pod_array.h"
43
- #include "util/sparse_set.h"
44
42
  #include "util/strutil.h"
43
+ #include "re2/pod_array.h"
45
44
  #include "re2/prog.h"
45
+ #include "re2/sparse_set.h"
46
46
  #include "re2/stringpiece.h"
47
47
 
48
48
  // Silence "zero-sized array in struct/union" warning for DFA::State::next_.
@@ -442,7 +442,7 @@ DFA::DFA(Prog* prog, Prog::MatchKind kind, int64_t max_mem)
442
442
  q1_(NULL),
443
443
  mem_budget_(max_mem) {
444
444
  if (ExtraDebug)
445
- fprintf(stderr, "\nkind %d\n%s\n", (int)kind_, prog_->DumpUnanchored().c_str());
445
+ fprintf(stderr, "\nkind %d\n%s\n", kind_, prog_->DumpUnanchored().c_str());
446
446
  int nmark = 0;
447
447
  if (kind_ == Prog::kLongestMatch)
448
448
  nmark = prog_->size();
@@ -989,8 +989,8 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
989
989
  }
990
990
 
991
991
  if (ExtraDebug)
992
- fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n", DumpWorkq(oldq).c_str(),
993
- c, flag, DumpWorkq(newq).c_str(), *ismatch);
992
+ fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n",
993
+ DumpWorkq(oldq).c_str(), c, flag, DumpWorkq(newq).c_str(), *ismatch);
994
994
  }
995
995
 
996
996
  // Processes input byte c in state, returning new state.
@@ -1367,8 +1367,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
1367
1367
 
1368
1368
  while (p != ep) {
1369
1369
  if (ExtraDebug)
1370
- fprintf(stderr, "@%td: %s\n",
1371
- p - bp, DumpState(s).c_str());
1370
+ fprintf(stderr, "@%td: %s\n", p - bp, DumpState(s).c_str());
1372
1371
 
1373
1372
  if (have_first_byte && s == start) {
1374
1373
  // In start state, only way out is to find first_byte,
@@ -1476,8 +1475,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
1476
1475
  else
1477
1476
  lastmatch = p + 1;
1478
1477
  if (ExtraDebug)
1479
- fprintf(stderr, "match @%td! [%s]\n",
1480
- lastmatch - bp, DumpState(s).c_str());
1478
+ fprintf(stderr, "match @%td! [%s]\n", lastmatch - bp, DumpState(s).c_str());
1481
1479
  if (params->matches != NULL && kind_ == Prog::kManyMatch) {
1482
1480
  for (int i = s->ninst_ - 1; i >= 0; i--) {
1483
1481
  int id = s->inst_[i];
@@ -1780,8 +1778,7 @@ bool DFA::Search(const StringPiece& text,
1780
1778
  if (ExtraDebug) {
1781
1779
  fprintf(stderr, "\nprogram:\n%s\n", prog_->DumpUnanchored().c_str());
1782
1780
  fprintf(stderr, "text %s anchored=%d earliest=%d fwd=%d kind %d\n",
1783
- std::string(text).c_str(), anchored, want_earliest_match,
1784
- run_forward, kind_);
1781
+ std::string(text).c_str(), anchored, want_earliest_match, run_forward, kind_);
1785
1782
  }
1786
1783
 
1787
1784
  RWLocker l(&cache_mutex_);
package/vendor/re2/nfa.cc CHANGED
@@ -31,13 +31,13 @@
31
31
  #include <utility>
32
32
  #include <vector>
33
33
 
34
- #include "re2/prog.h"
35
- #include "re2/regexp.h"
36
34
  #include "util/logging.h"
37
- #include "util/pod_array.h"
38
- #include "util/sparse_array.h"
39
- #include "util/sparse_set.h"
40
35
  #include "util/strutil.h"
36
+ #include "re2/pod_array.h"
37
+ #include "re2/prog.h"
38
+ #include "re2/regexp.h"
39
+ #include "re2/sparse_array.h"
40
+ #include "re2/sparse_set.h"
41
41
 
42
42
  namespace re2 {
43
43
 
@@ -382,10 +382,15 @@ int NFA::Step(Threadq* runq, Threadq* nextq, int c, const StringPiece& context,
382
382
  break;
383
383
 
384
384
  case kInstMatch: {
385
- // Avoid invoking undefined behavior when p happens
386
- // to be null - and p-1 would be meaningless anyway.
387
- if (p == NULL)
385
+ // Avoid invoking undefined behavior (arithmetic on a null pointer)
386
+ // by storing p instead of p-1. (What would the latter even mean?!)
387
+ // This complements the special case in NFA::Search().
388
+ if (p == NULL) {
389
+ CopyCapture(match_, t->capture);
390
+ match_[1] = p;
391
+ matched_ = true;
388
392
  break;
393
+ }
389
394
 
390
395
  if (endmatch_ && p-1 != etext_)
391
396
  break;
@@ -431,12 +436,12 @@ std::string NFA::FormatCapture(const char** capture) {
431
436
  if (capture[i] == NULL)
432
437
  s += "(?,?)";
433
438
  else if (capture[i+1] == NULL)
434
- s += StringPrintf("(%d,?)",
435
- (int)(capture[i] - btext_));
439
+ s += StringPrintf("(%td,?)",
440
+ capture[i] - btext_);
436
441
  else
437
- s += StringPrintf("(%d,%d)",
438
- (int)(capture[i] - btext_),
439
- (int)(capture[i+1] - btext_));
442
+ s += StringPrintf("(%td,%td)",
443
+ capture[i] - btext_,
444
+ capture[i+1] - btext_);
440
445
  }
441
446
  return s;
442
447
  }
@@ -493,8 +498,7 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
493
498
 
494
499
  if (ExtraDebug)
495
500
  fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
496
- std::string(text).c_str(), std::string(context).c_str(), anchored,
497
- longest);
501
+ std::string(text).c_str(), std::string(context).c_str(), anchored, longest);
498
502
 
499
503
  // Set up search.
500
504
  Threadq* runq = &q0_;
@@ -594,6 +598,18 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
594
598
  fprintf(stderr, "dead\n");
595
599
  break;
596
600
  }
601
+
602
+ // Avoid invoking undefined behavior (arithmetic on a null pointer)
603
+ // by simply not continuing the loop.
604
+ // This complements the special case in NFA::Step().
605
+ if (p == NULL) {
606
+ (void)Step(runq, nextq, p < etext_ ? p[0] & 0xFF : -1, context, p);
607
+ DCHECK_EQ(runq->size(), 0);
608
+ using std::swap;
609
+ swap(nextq, runq);
610
+ nextq->clear();
611
+ break;
612
+ }
597
613
  }
598
614
 
599
615
  for (Threadq::iterator i = runq->begin(); i != runq->end(); ++i)
@@ -606,7 +622,8 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
606
622
  static_cast<size_t>(match_[2 * i + 1] - match_[2 * i]));
607
623
  if (ExtraDebug)
608
624
  fprintf(stderr, "match (%td,%td)\n",
609
- match_[0] - btext_, match_[1] - btext_);
625
+ match_[0] - btext_,
626
+ match_[1] - btext_);
610
627
  return true;
611
628
  }
612
629
  return false;
@@ -59,11 +59,11 @@
59
59
 
60
60
  #include "util/util.h"
61
61
  #include "util/logging.h"
62
- #include "util/pod_array.h"
63
- #include "util/sparse_set.h"
64
62
  #include "util/strutil.h"
65
63
  #include "util/utf.h"
64
+ #include "re2/pod_array.h"
66
65
  #include "re2/prog.h"
66
+ #include "re2/sparse_set.h"
67
67
  #include "re2/stringpiece.h"
68
68
 
69
69
  // Silence "zero-sized array in struct/union" warning for OneState::action.
@@ -550,7 +550,7 @@ bool Prog::IsOnePass() {
550
550
  if (!AddQ(&workq, ip->out())) {
551
551
  if (ExtraDebug)
552
552
  LOG(ERROR) << StringPrintf(
553
- "Not OnePass: multiple paths %d -> %d\n", *it, ip->out());
553
+ "Not OnePass: multiple paths %d -> %d", *it, ip->out());
554
554
  goto fail;
555
555
  }
556
556
  id = ip->out();
@@ -561,7 +561,7 @@ bool Prog::IsOnePass() {
561
561
  // (3) is violated
562
562
  if (ExtraDebug)
563
563
  LOG(ERROR) << StringPrintf(
564
- "Not OnePass: multiple matches from %d\n", *it);
564
+ "Not OnePass: multiple matches from %d", *it);
565
565
  goto fail;
566
566
  }
567
567
  matched = true;
@@ -27,9 +27,9 @@
27
27
 
28
28
  #include "util/util.h"
29
29
  #include "util/logging.h"
30
- #include "util/pod_array.h"
31
30
  #include "util/strutil.h"
32
31
  #include "util/utf.h"
32
+ #include "re2/pod_array.h"
33
33
  #include "re2/regexp.h"
34
34
  #include "re2/stringpiece.h"
35
35
  #include "re2/unicode_casefold.h"
@@ -1323,14 +1323,14 @@ bool Regexp::ParseState::MaybeConcatString(int r, ParseFlags flags) {
1323
1323
  // Parses a decimal integer, storing it in *np.
1324
1324
  // Sets *s to span the remainder of the string.
1325
1325
  static bool ParseInteger(StringPiece* s, int* np) {
1326
- if (s->size() == 0 || !isdigit((*s)[0] & 0xFF))
1326
+ if (s->empty() || !isdigit((*s)[0] & 0xFF))
1327
1327
  return false;
1328
1328
  // Disallow leading zeros.
1329
1329
  if (s->size() >= 2 && (*s)[0] == '0' && isdigit((*s)[1] & 0xFF))
1330
1330
  return false;
1331
1331
  int n = 0;
1332
1332
  int c;
1333
- while (s->size() > 0 && isdigit(c = (*s)[0] & 0xFF)) {
1333
+ while (!s->empty() && isdigit(c = (*s)[0] & 0xFF)) {
1334
1334
  // Avoid overflow.
1335
1335
  if (n >= 100000000)
1336
1336
  return false;
@@ -1352,16 +1352,16 @@ static bool ParseInteger(StringPiece* s, int* np) {
1352
1352
  // s must NOT be edited unless MaybeParseRepetition returns true.
1353
1353
  static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
1354
1354
  StringPiece s = *sp;
1355
- if (s.size() == 0 || s[0] != '{')
1355
+ if (s.empty() || s[0] != '{')
1356
1356
  return false;
1357
1357
  s.remove_prefix(1); // '{'
1358
1358
  if (!ParseInteger(&s, lo))
1359
1359
  return false;
1360
- if (s.size() == 0)
1360
+ if (s.empty())
1361
1361
  return false;
1362
1362
  if (s[0] == ',') {
1363
1363
  s.remove_prefix(1); // ','
1364
- if (s.size() == 0)
1364
+ if (s.empty())
1365
1365
  return false;
1366
1366
  if (s[0] == '}') {
1367
1367
  // {2,} means at least 2
@@ -1375,7 +1375,7 @@ static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
1375
1375
  // {2} means exactly two
1376
1376
  *hi = *lo;
1377
1377
  }
1378
- if (s.size() == 0 || s[0] != '}')
1378
+ if (s.empty() || s[0] != '}')
1379
1379
  return false;
1380
1380
  s.remove_prefix(1); // '}'
1381
1381
  *sp = s;
@@ -1416,7 +1416,7 @@ static int StringPieceToRune(Rune *r, StringPiece *sp, RegexpStatus* status) {
1416
1416
  static bool IsValidUTF8(const StringPiece& s, RegexpStatus* status) {
1417
1417
  StringPiece t = s;
1418
1418
  Rune r;
1419
- while (t.size() > 0) {
1419
+ while (!t.empty()) {
1420
1420
  if (StringPieceToRune(&r, &t, status) < 0)
1421
1421
  return false;
1422
1422
  }
@@ -1448,13 +1448,13 @@ static int UnHex(int c) {
1448
1448
  static bool ParseEscape(StringPiece* s, Rune* rp,
1449
1449
  RegexpStatus* status, int rune_max) {
1450
1450
  const char* begin = s->data();
1451
- if (s->size() < 1 || (*s)[0] != '\\') {
1451
+ if (s->empty() || (*s)[0] != '\\') {
1452
1452
  // Should not happen - caller always checks.
1453
1453
  status->set_code(kRegexpInternalError);
1454
1454
  status->set_error_arg(StringPiece());
1455
1455
  return false;
1456
1456
  }
1457
- if (s->size() < 2) {
1457
+ if (s->size() == 1) {
1458
1458
  status->set_code(kRegexpTrailingBackslash);
1459
1459
  status->set_error_arg(StringPiece());
1460
1460
  return false;
@@ -1485,16 +1485,16 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
1485
1485
  case '6':
1486
1486
  case '7':
1487
1487
  // Single non-zero octal digit is a backreference; not supported.
1488
- if (s->size() == 0 || (*s)[0] < '0' || (*s)[0] > '7')
1488
+ if (s->empty() || (*s)[0] < '0' || (*s)[0] > '7')
1489
1489
  goto BadEscape;
1490
1490
  FALLTHROUGH_INTENDED;
1491
1491
  case '0':
1492
1492
  // consume up to three octal digits; already have one.
1493
1493
  code = c - '0';
1494
- if (s->size() > 0 && '0' <= (c = (*s)[0]) && c <= '7') {
1494
+ if (!s->empty() && '0' <= (c = (*s)[0]) && c <= '7') {
1495
1495
  code = code * 8 + c - '0';
1496
1496
  s->remove_prefix(1); // digit
1497
- if (s->size() > 0) {
1497
+ if (!s->empty()) {
1498
1498
  c = (*s)[0];
1499
1499
  if ('0' <= c && c <= '7') {
1500
1500
  code = code * 8 + c - '0';
@@ -1509,7 +1509,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
1509
1509
 
1510
1510
  // Hexadecimal escapes
1511
1511
  case 'x':
1512
- if (s->size() == 0)
1512
+ if (s->empty())
1513
1513
  goto BadEscape;
1514
1514
  if (StringPieceToRune(&c, s, status) < 0)
1515
1515
  return false;
@@ -1529,7 +1529,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
1529
1529
  code = code * 16 + UnHex(c);
1530
1530
  if (code > rune_max)
1531
1531
  goto BadEscape;
1532
- if (s->size() == 0)
1532
+ if (s->empty())
1533
1533
  goto BadEscape;
1534
1534
  if (StringPieceToRune(&c, s, status) < 0)
1535
1535
  return false;
@@ -1540,7 +1540,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
1540
1540
  return true;
1541
1541
  }
1542
1542
  // Easy case: two hex digits.
1543
- if (s->size() == 0)
1543
+ if (s->empty())
1544
1544
  goto BadEscape;
1545
1545
  if (StringPieceToRune(&c1, s, status) < 0)
1546
1546
  return false;
@@ -1771,7 +1771,7 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
1771
1771
  // Chop seq where s now begins.
1772
1772
  seq = StringPiece(seq.data(), static_cast<size_t>(s->data() - seq.data()));
1773
1773
 
1774
- if (name.size() > 0 && name[0] == '^') {
1774
+ if (!name.empty() && name[0] == '^') {
1775
1775
  sign = -sign;
1776
1776
  name.remove_prefix(1); // '^'
1777
1777
  }
@@ -1858,7 +1858,7 @@ static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
1858
1858
  bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
1859
1859
  const StringPiece& whole_class,
1860
1860
  RegexpStatus* status) {
1861
- if (s->size() == 0) {
1861
+ if (s->empty()) {
1862
1862
  status->set_code(kRegexpMissingBracket);
1863
1863
  status->set_error_arg(whole_class);
1864
1864
  return false;
@@ -1866,7 +1866,7 @@ bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
1866
1866
 
1867
1867
  // Allow regular escape sequences even though
1868
1868
  // many need not be escaped in this context.
1869
- if (s->size() >= 1 && (*s)[0] == '\\')
1869
+ if ((*s)[0] == '\\')
1870
1870
  return ParseEscape(s, rp, status, rune_max_);
1871
1871
 
1872
1872
  // Otherwise take the next rune.
@@ -1908,7 +1908,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
1908
1908
  Regexp** out_re,
1909
1909
  RegexpStatus* status) {
1910
1910
  StringPiece whole_class = *s;
1911
- if (s->size() == 0 || (*s)[0] != '[') {
1911
+ if (s->empty() || (*s)[0] != '[') {
1912
1912
  // Caller checked this.
1913
1913
  status->set_code(kRegexpInternalError);
1914
1914
  status->set_error_arg(StringPiece());
@@ -1918,7 +1918,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
1918
1918
  Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
1919
1919
  re->ccb_ = new CharClassBuilder;
1920
1920
  s->remove_prefix(1); // '['
1921
- if (s->size() > 0 && (*s)[0] == '^') {
1921
+ if (!s->empty() && (*s)[0] == '^') {
1922
1922
  s->remove_prefix(1); // '^'
1923
1923
  negated = true;
1924
1924
  if (!(flags_ & ClassNL) || (flags_ & NeverNL)) {
@@ -1928,7 +1928,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
1928
1928
  }
1929
1929
  }
1930
1930
  bool first = true; // ] is okay as first char in class
1931
- while (s->size() > 0 && ((*s)[0] != ']' || first)) {
1931
+ while (!s->empty() && ((*s)[0] != ']' || first)) {
1932
1932
  // - is only okay unescaped as first or last in class.
1933
1933
  // Except that Perl allows - anywhere.
1934
1934
  if ((*s)[0] == '-' && !first && !(flags_&PerlX) &&
@@ -1996,7 +1996,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
1996
1996
  // in the flags.
1997
1997
  re->ccb_->AddRangeFlags(rr.lo, rr.hi, flags_ | Regexp::ClassNL);
1998
1998
  }
1999
- if (s->size() == 0) {
1999
+ if (s->empty()) {
2000
2000
  status->set_code(kRegexpMissingBracket);
2001
2001
  status->set_error_arg(whole_class);
2002
2002
  re->Decref();
@@ -2016,7 +2016,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
2016
2016
  // Python rejects names starting with digits.
2017
2017
  // We don't enforce either of those.
2018
2018
  static bool IsValidCaptureName(const StringPiece& name) {
2019
- if (name.size() == 0)
2019
+ if (name.empty())
2020
2020
  return false;
2021
2021
  for (size_t i = 0; i < name.size(); i++) {
2022
2022
  int c = name[i];
@@ -2099,7 +2099,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
2099
2099
  int nflags = flags_;
2100
2100
  Rune c;
2101
2101
  for (bool done = false; !done; ) {
2102
- if (t.size() == 0)
2102
+ if (t.empty())
2103
2103
  goto BadPerlOp;
2104
2104
  if (StringPieceToRune(&c, &t, status_) < 0)
2105
2105
  return false;
@@ -2217,7 +2217,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
2217
2217
 
2218
2218
  if (global_flags & Literal) {
2219
2219
  // Special parse loop for literal string.
2220
- while (t.size() > 0) {
2220
+ while (!t.empty()) {
2221
2221
  Rune r;
2222
2222
  if (StringPieceToRune(&r, &t, status) < 0)
2223
2223
  return NULL;
@@ -2228,7 +2228,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
2228
2228
  }
2229
2229
 
2230
2230
  StringPiece lastunary = StringPiece();
2231
- while (t.size() > 0) {
2231
+ while (!t.empty()) {
2232
2232
  StringPiece isunary = StringPiece();
2233
2233
  switch (t[0]) {
2234
2234
  default: {
@@ -2312,11 +2312,11 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
2312
2312
  bool nongreedy = false;
2313
2313
  t.remove_prefix(1); // '*' or '+' or '?'
2314
2314
  if (ps.flags() & PerlX) {
2315
- if (t.size() > 0 && t[0] == '?') {
2315
+ if (!t.empty() && t[0] == '?') {
2316
2316
  nongreedy = true;
2317
2317
  t.remove_prefix(1); // '?'
2318
2318
  }
2319
- if (lastunary.size() > 0) {
2319
+ if (!lastunary.empty()) {
2320
2320
  // In Perl it is not allowed to stack repetition operators:
2321
2321
  // a** is a syntax error, not a double-star.
2322
2322
  // (and a++ means something else entirely, which we don't support!)
@@ -2347,11 +2347,11 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
2347
2347
  }
2348
2348
  bool nongreedy = false;
2349
2349
  if (ps.flags() & PerlX) {
2350
- if (t.size() > 0 && t[0] == '?') {
2350
+ if (!t.empty() && t[0] == '?') {
2351
2351
  nongreedy = true;
2352
2352
  t.remove_prefix(1); // '?'
2353
2353
  }
2354
- if (lastunary.size() > 0) {
2354
+ if (!lastunary.empty()) {
2355
2355
  // Not allowed to stack repetition operators.
2356
2356
  status->set_code(kRegexpRepeatOp);
2357
2357
  status->set_error_arg(StringPiece(
@@ -2405,7 +2405,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
2405
2405
 
2406
2406
  if (t[1] == 'Q') { // \Q ... \E: the ... is always literals
2407
2407
  t.remove_prefix(2); // '\\', 'Q'
2408
- while (t.size() > 0) {
2408
+ while (!t.empty()) {
2409
2409
  if (t.size() >= 2 && t[0] == '\\' && t[1] == 'E') {
2410
2410
  t.remove_prefix(2); // '\\', 'E'
2411
2411
  break;
@@ -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_POD_ARRAY_H_
6
- #define UTIL_POD_ARRAY_H_
5
+ #ifndef RE2_POD_ARRAY_H_
6
+ #define RE2_POD_ARRAY_H_
7
7
 
8
8
  #include <memory>
9
9
  #include <type_traits>
@@ -52,4 +52,4 @@ class PODArray {
52
52
 
53
53
  } // namespace re2
54
54
 
55
- #endif // UTIL_POD_ARRAY_H_
55
+ #endif // RE2_POD_ARRAY_H_