forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathre2.patch
3684 lines (3334 loc) · 146 KB
/
re2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/BUILD b/BUILD
index 00330b6..8d44eba 100644
--- BUILD
+++ BUILD
@@ -50,7 +50,6 @@ cc_library(
"re2/simplify.cc",
"re2/sparse_array.h",
"re2/sparse_set.h",
- "re2/stringpiece.cc",
"re2/tostring.cc",
"re2/unicode_casefold.cc",
"re2/unicode_casefold.h",
@@ -70,7 +69,6 @@ cc_library(
"re2/filtered_re2.h",
"re2/re2.h",
"re2/set.h",
- "re2/stringpiece.h",
],
copts = select({
":wasm": [],
@@ -86,6 +84,9 @@ cc_library(
":windows": [],
"//conditions:default": ["-pthread"],
}),
+ deps = [
+ "@com_google_absl//absl/strings",
+ ],
visibility = ["//visibility:public"],
)
diff --git a/WORKSPACE b/WORKSPACE
index b35619c..908e100 100644
--- WORKSPACE
+++ WORKSPACE
@@ -5,3 +5,11 @@
# Bazel (http://bazel.io/) WORKSPACE file for RE2.
workspace(name = "com_googlesource_code_re2")
+
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
+
+git_repository(
+ name = "com_google_absl",
+ commit = "278e0a0", # release 20210324.2
+ remote = "https://github.com/abseil/abseil-cpp.git",
+)
diff --git a/re2/bitstate.cc b/re2/bitstate.cc
index 877e548..2b742dd 100644
--- re2/bitstate.cc
+++ re2/bitstate.cc
@@ -42,9 +42,9 @@ class BitState {
// The usual Search prototype.
// Can only call Search once per BitState.
- bool Search(const StringPiece& text, const StringPiece& context,
+ bool Search(const absl::string_view& text, const absl::string_view& context,
bool anchored, bool longest,
- StringPiece* submatch, int nsubmatch);
+ absl::string_view* submatch, int nsubmatch);
private:
inline bool ShouldVisit(int id, const char* p);
@@ -54,12 +54,12 @@ class BitState {
// Search parameters
Prog* prog_; // program being run
- StringPiece text_; // text being searched
- StringPiece context_; // greater context of text being searched
+ absl::string_view text_; // text being searched
+ absl::string_view context_; // greater context of text being searched
bool anchored_; // whether search is anchored at text.begin()
bool longest_; // whether search wants leftmost-longest match
bool endmatch_; // whether match must end at text.end()
- StringPiece* submatch_; // submatches to fill in
+ absl::string_view* submatch_; // submatches to fill in
int nsubmatch_; // # of submatches to fill in
// Search state
@@ -257,7 +257,7 @@ bool BitState::TrySearch(int id0, const char* p0) {
(longest_ && p > submatch_[0].data() + submatch_[0].size())) {
for (int i = 0; i < nsubmatch_; i++)
submatch_[i] =
- StringPiece(cap_[2 * i],
+ absl::string_view(cap_[2 * i],
static_cast<size_t>(cap_[2 * i + 1] - cap_[2 * i]));
}
@@ -285,9 +285,9 @@ bool BitState::TrySearch(int id0, const char* p0) {
}
// Search text (within context) for prog_.
-bool BitState::Search(const StringPiece& text, const StringPiece& context,
+bool BitState::Search(const absl::string_view& text, const absl::string_view& context,
bool anchored, bool longest,
- StringPiece* submatch, int nsubmatch) {
+ absl::string_view* submatch, int nsubmatch) {
// Search parameters.
text_ = text;
context_ = context;
@@ -303,7 +303,7 @@ bool BitState::Search(const StringPiece& text, const StringPiece& context,
submatch_ = submatch;
nsubmatch_ = nsubmatch;
for (int i = 0; i < nsubmatch_; i++)
- submatch_[i] = StringPiece();
+ submatch_[i] = absl::string_view();
// Allocate scratch space.
int nvisited = prog_->list_count() * static_cast<int>(text.size()+1);
@@ -353,16 +353,16 @@ bool BitState::Search(const StringPiece& text, const StringPiece& context,
}
// Bit-state search.
-bool Prog::SearchBitState(const StringPiece& text,
- const StringPiece& context,
+bool Prog::SearchBitState(const absl::string_view& text,
+ const absl::string_view& context,
Anchor anchor,
MatchKind kind,
- StringPiece* match,
+ absl::string_view* match,
int nmatch) {
// If full match, we ask for an anchored longest match
// and then check that match[0] == text.
// So make sure match[0] exists.
- StringPiece sp0;
+ absl::string_view sp0;
if (kind == kFullMatch) {
anchor = kAnchored;
if (nmatch < 1) {
diff --git a/re2/compile.cc b/re2/compile.cc
index 61d801a..4862de2 100644
--- re2/compile.cc
+++ re2/compile.cc
@@ -1243,7 +1243,7 @@ Prog* Compiler::CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem) {
// Make sure DFA has enough memory to operate,
// since we're not going to fall back to the NFA.
bool dfa_failed = false;
- StringPiece sp = "hello, world";
+ absl::string_view sp = "hello, world";
prog->SearchDFA(sp, sp, Prog::kAnchored, Prog::kManyMatch,
NULL, &dfa_failed, NULL);
if (dfa_failed) {
diff --git a/re2/dfa.cc b/re2/dfa.cc
index d47c7d5..f81d00c 100644
--- re2/dfa.cc
+++ re2/dfa.cc
@@ -44,7 +44,7 @@
#include "re2/prog.h"
#include "re2/re2.h"
#include "re2/sparse_set.h"
-#include "re2/stringpiece.h"
+#include "absl/strings/string_view.h"
// Silence "zero-sized array in struct/union" warning for DFA::State::next_.
#ifdef _MSC_VER
@@ -88,7 +88,7 @@ class DFA {
// returning the leftmost end of the match instead of the rightmost one.
// If the DFA cannot complete the search (for example, if it is out of
// memory), it sets *failed and returns false.
- bool Search(const StringPiece& text, const StringPiece& context,
+ bool Search(const absl::string_view& text, const absl::string_view& context,
bool anchored, bool want_earliest_match, bool run_forward,
bool* failed, const char** ep, SparseSet* matches);
@@ -238,7 +238,7 @@ class DFA {
// Search parameters
struct SearchParams {
- SearchParams(const StringPiece& text, const StringPiece& context,
+ SearchParams(const absl::string_view& text, const absl::string_view& context,
RWLocker* cache_lock)
: text(text),
context(context),
@@ -252,8 +252,8 @@ class DFA {
ep(NULL),
matches(NULL) {}
- StringPiece text;
- StringPiece context;
+ absl::string_view text;
+ absl::string_view context;
bool anchored;
bool can_prefix_accel;
bool want_earliest_match;
@@ -1623,8 +1623,8 @@ bool DFA::FastSearchLoop(SearchParams* params) {
// state for the DFA search loop. Fills in params and returns true on success.
// Returns false on failure.
bool DFA::AnalyzeSearch(SearchParams* params) {
- const StringPiece& text = params->text;
- const StringPiece& context = params->context;
+ const absl::string_view& text = params->text;
+ const absl::string_view& context = params->context;
// Sanity check: make sure that text lies within context.
if (BeginPtr(text) < BeginPtr(context) || EndPtr(text) > EndPtr(context)) {
@@ -1728,8 +1728,8 @@ bool DFA::AnalyzeSearchHelper(SearchParams* params, StartInfo* info,
}
// The actual DFA search: calls AnalyzeSearch and then FastSearchLoop.
-bool DFA::Search(const StringPiece& text,
- const StringPiece& context,
+bool DFA::Search(const absl::string_view& text,
+ const absl::string_view& context,
bool anchored,
bool want_earliest_match,
bool run_forward,
@@ -1823,12 +1823,12 @@ void Prog::DeleteDFA(DFA* dfa) {
//
// This is the only external interface (class DFA only exists in this file).
//
-bool Prog::SearchDFA(const StringPiece& text, const StringPiece& const_context,
- Anchor anchor, MatchKind kind, StringPiece* match0,
+bool Prog::SearchDFA(const absl::string_view& text, const absl::string_view& const_context,
+ Anchor anchor, MatchKind kind, absl::string_view* match0,
bool* failed, SparseSet* matches) {
*failed = false;
- StringPiece context = const_context;
+ absl::string_view context = const_context;
if (context.data() == NULL)
context = text;
bool caret = anchor_start();
@@ -1889,10 +1889,10 @@ bool Prog::SearchDFA(const StringPiece& text, const StringPiece& const_context,
if (match0) {
if (reversed_)
*match0 =
- StringPiece(ep, static_cast<size_t>(text.data() + text.size() - ep));
+ absl::string_view(ep, static_cast<size_t>(text.data() + text.size() - ep));
else
*match0 =
- StringPiece(text.data(), static_cast<size_t>(ep - text.data()));
+ absl::string_view(text.data(), static_cast<size_t>(ep - text.data()));
}
return true;
}
@@ -1905,7 +1905,7 @@ int DFA::BuildAllStates(const Prog::DFAStateCallback& cb) {
// Pick out start state for unanchored search
// at beginning of text.
RWLocker l(&cache_mutex_);
- SearchParams params(StringPiece(), StringPiece(), &l);
+ SearchParams params(absl::string_view(), absl::string_view(), &l);
params.anchored = false;
if (!AnalyzeSearch(¶ms) ||
params.start == NULL ||
@@ -1993,7 +1993,7 @@ bool DFA::PossibleMatchRange(std::string* min, std::string* max, int maxlen) {
// Pick out start state for anchored search at beginning of text.
RWLocker l(&cache_mutex_);
- SearchParams params(StringPiece(), StringPiece(), &l);
+ SearchParams params(absl::string_view(), absl::string_view(), &l);
params.anchored = true;
if (!AnalyzeSearch(¶ms))
return false;
diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc
index 5df9745..e888e6e 100644
--- re2/filtered_re2.cc
+++ re2/filtered_re2.cc
@@ -46,7 +46,7 @@ FilteredRE2& FilteredRE2::operator=(FilteredRE2&& other) {
return *this;
}
-RE2::ErrorCode FilteredRE2::Add(const StringPiece& pattern,
+RE2::ErrorCode FilteredRE2::Add(const absl::string_view& pattern,
const RE2::Options& options, int* id) {
RE2* re = new RE2(pattern, options);
RE2::ErrorCode code = re->error_code();
@@ -85,14 +85,14 @@ void FilteredRE2::Compile(std::vector<std::string>* atoms) {
compiled_ = true;
}
-int FilteredRE2::SlowFirstMatch(const StringPiece& text) const {
+int FilteredRE2::SlowFirstMatch(const absl::string_view& text) const {
for (size_t i = 0; i < re2_vec_.size(); i++)
if (RE2::PartialMatch(text, *re2_vec_[i]))
return static_cast<int>(i);
return -1;
}
-int FilteredRE2::FirstMatch(const StringPiece& text,
+int FilteredRE2::FirstMatch(const absl::string_view& text,
const std::vector<int>& atoms) const {
if (!compiled_) {
LOG(DFATAL) << "FirstMatch called before Compile.";
@@ -107,7 +107,7 @@ int FilteredRE2::FirstMatch(const StringPiece& text,
}
bool FilteredRE2::AllMatches(
- const StringPiece& text,
+ const absl::string_view& text,
const std::vector<int>& atoms,
std::vector<int>* matching_regexps) const {
matching_regexps->clear();
diff --git a/re2/filtered_re2.h b/re2/filtered_re2.h
index dd618c7..5d55a78 100644
--- re2/filtered_re2.h
+++ re2/filtered_re2.h
@@ -47,7 +47,7 @@ class FilteredRE2 {
// Uses RE2 constructor to create a RE2 object (re). Returns
// re->error_code(). If error_code is other than NoError, then re is
// deleted and not added to re2_vec_.
- RE2::ErrorCode Add(const StringPiece& pattern,
+ RE2::ErrorCode Add(const absl::string_view& pattern,
const RE2::Options& options,
int* id);
@@ -63,17 +63,17 @@ class FilteredRE2 {
// Returns -1 on no match. Can be called prior to Compile.
// Does not do any filtering: simply tries to Match the
// regexps in a loop.
- int SlowFirstMatch(const StringPiece& text) const;
+ int SlowFirstMatch(const absl::string_view& text) const;
// Returns the index of the first matching regexp.
// Returns -1 on no match. Compile has to be called before
// calling this.
- int FirstMatch(const StringPiece& text,
+ int FirstMatch(const absl::string_view& text,
const std::vector<int>& atoms) const;
// Returns the indices of all matching regexps, after first clearing
// matched_regexps.
- bool AllMatches(const StringPiece& text,
+ bool AllMatches(const absl::string_view& text,
const std::vector<int>& atoms,
std::vector<int>* matching_regexps) const;
diff --git a/re2/nfa.cc b/re2/nfa.cc
index c7339f8..defb31e 100644
--- re2/nfa.cc
+++ re2/nfa.cc
@@ -60,9 +60,9 @@ class NFA {
// Submatch[0] is the entire match. When there is a choice in
// which text matches each subexpression, the submatch boundaries
// are chosen to match what a backtracking implementation would choose.
- bool Search(const StringPiece& text, const StringPiece& context,
+ bool Search(const absl::string_view& text, const absl::string_view& context,
bool anchored, bool longest,
- StringPiece* submatch, int nsubmatch);
+ absl::string_view* submatch, int nsubmatch);
private:
struct Thread {
@@ -92,7 +92,7 @@ class NFA {
// Enqueues only the ByteRange instructions that match byte c.
// context is used (with p) for evaluating empty-width specials.
// p is the current input position, and t0 is the current thread.
- void AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
+ void AddToThreadq(Threadq* q, int id0, int c, const absl::string_view& context,
const char* p, Thread* t0);
// Run runq on byte c, appending new states to nextq.
@@ -102,7 +102,7 @@ class NFA {
// p-1 will be used when processing Match instructions.
// Frees all the threads on runq.
// If there is a shortcut to the end, returns that shortcut.
- int Step(Threadq* runq, Threadq* nextq, int c, const StringPiece& context,
+ int Step(Threadq* runq, Threadq* nextq, int c, const absl::string_view& context,
const char* p);
// Returns text version of capture information, for debugging.
@@ -192,7 +192,7 @@ void NFA::Decref(Thread* t) {
// Enqueues only the ByteRange instructions that match byte c.
// context is used (with p) for evaluating empty-width specials.
// p is the current input position, and t0 is the current thread.
-void NFA::AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
+void NFA::AddToThreadq(Threadq* q, int id0, int c, const absl::string_view& context,
const char* p, Thread* t0) {
if (id0 == 0)
return;
@@ -328,7 +328,7 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
// p-1 will be used when processing Match instructions.
// Frees all the threads on runq.
// If there is a shortcut to the end, returns that shortcut.
-int NFA::Step(Threadq* runq, Threadq* nextq, int c, const StringPiece& context,
+int NFA::Step(Threadq* runq, Threadq* nextq, int c, const absl::string_view& context,
const char* p) {
nextq->clear();
@@ -445,13 +445,13 @@ std::string NFA::FormatCapture(const char** capture) {
return s;
}
-bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
+bool NFA::Search(const absl::string_view& text, const absl::string_view& const_context,
bool anchored, bool longest,
- StringPiece* submatch, int nsubmatch) {
+ absl::string_view* submatch, int nsubmatch) {
if (start_ == 0)
return false;
- StringPiece context = const_context;
+ absl::string_view context = const_context;
if (context.data() == NULL)
context = text;
@@ -617,7 +617,7 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
if (matched_) {
for (int i = 0; i < nsubmatch; i++)
submatch[i] =
- StringPiece(match_[2 * i],
+ absl::string_view(match_[2 * i],
static_cast<size_t>(match_[2 * i + 1] - match_[2 * i]));
if (ExtraDebug)
fprintf(stderr, "match (%td,%td)\n",
@@ -629,14 +629,14 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
}
bool
-Prog::SearchNFA(const StringPiece& text, const StringPiece& context,
+Prog::SearchNFA(const absl::string_view& text, const absl::string_view& context,
Anchor anchor, MatchKind kind,
- StringPiece* match, int nmatch) {
+ absl::string_view* match, int nmatch) {
if (ExtraDebug)
Dump();
NFA nfa(this);
- StringPiece sp;
+ absl::string_view sp;
if (kind == kFullMatch) {
anchor = kAnchored;
if (nmatch == 0) {
diff --git a/re2/onepass.cc b/re2/onepass.cc
index 2639746..dd6a38b 100644
--- re2/onepass.cc
+++ re2/onepass.cc
@@ -64,7 +64,7 @@
#include "re2/pod_array.h"
#include "re2/prog.h"
#include "re2/sparse_set.h"
-#include "re2/stringpiece.h"
+#include "absl/strings/string_view.h"
// Silence "zero-sized array in struct/union" warning for OneState::action.
#ifdef _MSC_VER
@@ -189,7 +189,7 @@ void OnePass_Checks() {
"kMaxCap disagrees with kMaxOnePassCapture");
}
-static bool Satisfy(uint32_t cond, const StringPiece& context, const char* p) {
+static bool Satisfy(uint32_t cond, const absl::string_view& context, const char* p) {
uint32_t satisfied = Prog::EmptyFlags(context, p);
if (cond & kEmptyAllFlags & ~satisfied)
return false;
@@ -211,10 +211,10 @@ static inline OneState* IndexToNode(uint8_t* nodes, int statesize,
return reinterpret_cast<OneState*>(nodes + statesize*nodeindex);
}
-bool Prog::SearchOnePass(const StringPiece& text,
- const StringPiece& const_context,
+bool Prog::SearchOnePass(const absl::string_view& text,
+ const absl::string_view& const_context,
Anchor anchor, MatchKind kind,
- StringPiece* match, int nmatch) {
+ absl::string_view* match, int nmatch) {
if (anchor != kAnchored && kind != kFullMatch) {
LOG(DFATAL) << "Cannot use SearchOnePass for unanchored matches.";
return false;
@@ -234,7 +234,7 @@ bool Prog::SearchOnePass(const StringPiece& text,
for (int i = 0; i < ncap; i++)
matchcap[i] = NULL;
- StringPiece context = const_context;
+ absl::string_view context = const_context;
if (context.data() == NULL)
context = text;
if (anchor_start() && BeginPtr(context) != BeginPtr(text))
@@ -340,7 +340,7 @@ done:
return false;
for (int i = 0; i < nmatch; i++)
match[i] =
- StringPiece(matchcap[2 * i],
+ absl::string_view(matchcap[2 * i],
static_cast<size_t>(matchcap[2 * i + 1] - matchcap[2 * i]));
return true;
}
diff --git a/re2/parse.cc b/re2/parse.cc
index 85f16f0..3a79c99 100644
--- re2/parse.cc
+++ re2/parse.cc
@@ -31,7 +31,7 @@
#include "util/utf.h"
#include "re2/pod_array.h"
#include "re2/regexp.h"
-#include "re2/stringpiece.h"
+#include "absl/strings/string_view.h"
#include "re2/unicode_casefold.h"
#include "re2/unicode_groups.h"
#include "re2/walker-inl.h"
@@ -70,7 +70,7 @@ void Regexp::FUZZING_ONLY_set_maximum_repeat_count(int i) {
class Regexp::ParseState {
public:
- ParseState(ParseFlags flags, const StringPiece& whole_regexp,
+ ParseState(ParseFlags flags, const absl::string_view& whole_regexp,
RegexpStatus* status);
~ParseState();
@@ -107,18 +107,18 @@ class Regexp::ParseState {
// Pushes a repeat operator regexp onto the stack.
// A valid argument for the operator must already be on the stack.
// s is the name of the operator, for use in error messages.
- bool PushRepeatOp(RegexpOp op, const StringPiece& s, bool nongreedy);
+ bool PushRepeatOp(RegexpOp op, const absl::string_view& s, bool nongreedy);
// Pushes a repetition regexp onto the stack.
// A valid argument for the operator must already be on the stack.
- bool PushRepetition(int min, int max, const StringPiece& s, bool nongreedy);
+ bool PushRepetition(int min, int max, const absl::string_view& s, bool nongreedy);
// Checks whether a particular regexp op is a marker.
bool IsMarker(RegexpOp op);
// Processes a left parenthesis in the input.
// Pushes a marker onto the stack.
- bool DoLeftParen(const StringPiece& name);
+ bool DoLeftParen(const absl::string_view& name);
bool DoLeftParenNoCapture();
// Processes a vertical bar in the input.
@@ -142,23 +142,23 @@ class Regexp::ParseState {
// Parse a character class into *out_re.
// Removes parsed text from s.
- bool ParseCharClass(StringPiece* s, Regexp** out_re,
+ bool ParseCharClass(absl::string_view* s, Regexp** out_re,
RegexpStatus* status);
// Parse a character class character into *rp.
// Removes parsed text from s.
- bool ParseCCCharacter(StringPiece* s, Rune *rp,
- const StringPiece& whole_class,
+ bool ParseCCCharacter(absl::string_view* s, Rune *rp,
+ const absl::string_view& whole_class,
RegexpStatus* status);
// Parse a character class range into rr.
// Removes parsed text from s.
- bool ParseCCRange(StringPiece* s, RuneRange* rr,
- const StringPiece& whole_class,
+ bool ParseCCRange(absl::string_view* s, RuneRange* rr,
+ const absl::string_view& whole_class,
RegexpStatus* status);
// Parse a Perl flag set or non-capturing group from s.
- bool ParsePerlFlags(StringPiece* s);
+ bool ParsePerlFlags(absl::string_view* s);
// Finishes the current concatenation,
@@ -177,7 +177,7 @@ class Regexp::ParseState {
private:
ParseFlags flags_;
- StringPiece whole_regexp_;
+ absl::string_view whole_regexp_;
RegexpStatus* status_;
Regexp* stacktop_;
int ncap_; // number of capturing parens seen
@@ -192,7 +192,7 @@ const RegexpOp kLeftParen = static_cast<RegexpOp>(kMaxRegexpOp+1);
const RegexpOp kVerticalBar = static_cast<RegexpOp>(kMaxRegexpOp+2);
Regexp::ParseState::ParseState(ParseFlags flags,
- const StringPiece& whole_regexp,
+ const absl::string_view& whole_regexp,
RegexpStatus* status)
: flags_(flags), whole_regexp_(whole_regexp),
status_(status), stacktop_(NULL), ncap_(0) {
@@ -472,7 +472,7 @@ bool Regexp::ParseState::PushSimpleOp(RegexpOp op) {
// Pushes a repeat operator regexp onto the stack.
// A valid argument for the operator must already be on the stack.
// The char c is the name of the operator, for use in error messages.
-bool Regexp::ParseState::PushRepeatOp(RegexpOp op, const StringPiece& s,
+bool Regexp::ParseState::PushRepeatOp(RegexpOp op, const absl::string_view& s,
bool nongreedy) {
if (stacktop_ == NULL || IsMarker(stacktop_->op())) {
status_->set_code(kRegexpRepeatArgument);
@@ -566,7 +566,7 @@ int RepetitionWalker::ShortVisit(Regexp* re, int parent_arg) {
// Pushes a repetition regexp onto the stack.
// A valid argument for the operator must already be on the stack.
bool Regexp::ParseState::PushRepetition(int min, int max,
- const StringPiece& s,
+ const absl::string_view& s,
bool nongreedy) {
if ((max != -1 && max < min) ||
min > maximum_repeat_count ||
@@ -609,7 +609,7 @@ bool Regexp::ParseState::IsMarker(RegexpOp op) {
// Processes a left parenthesis in the input.
// Pushes a marker onto the stack.
-bool Regexp::ParseState::DoLeftParen(const StringPiece& name) {
+bool Regexp::ParseState::DoLeftParen(const absl::string_view& name) {
Regexp* re = new Regexp(kLeftParen, flags_);
re->cap_ = ++ncap_;
if (name.data() != NULL)
@@ -1325,7 +1325,7 @@ bool Regexp::ParseState::MaybeConcatString(int r, ParseFlags flags) {
// Parses a decimal integer, storing it in *np.
// Sets *s to span the remainder of the string.
-static bool ParseInteger(StringPiece* s, int* np) {
+static bool ParseInteger(absl::string_view* s, int* np) {
if (s->empty() || !isdigit((*s)[0] & 0xFF))
return false;
// Disallow leading zeros.
@@ -1351,10 +1351,10 @@ static bool ParseInteger(StringPiece* s, int* np) {
// sets *hi to -1 to signify this.
// {,2} is NOT a valid suffix.
// The Maybe in the name signifies that the regexp parse
-// doesn't fail even if ParseRepetition does, so the StringPiece
+// doesn't fail even if ParseRepetition does, so the absl::string_view
// s must NOT be edited unless MaybeParseRepetition returns true.
-static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
- StringPiece s = *sp;
+static bool MaybeParseRepetition(absl::string_view* sp, int* lo, int* hi) {
+ absl::string_view s = *sp;
if (s.empty() || s[0] != '{')
return false;
s.remove_prefix(1); // '{'
@@ -1385,12 +1385,12 @@ static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
return true;
}
-// Removes the next Rune from the StringPiece and stores it in *r.
+// Removes the next Rune from the absl::string_view and stores it in *r.
// Returns number of bytes removed from sp.
// Behaves as though there is a terminating NUL at the end of sp.
// Argument order is backwards from usual Google style
// but consistent with chartorune.
-static int StringPieceToRune(Rune *r, StringPiece *sp, RegexpStatus* status) {
+static int StringViewToRune(Rune *r, absl::string_view *sp, RegexpStatus* status) {
// fullrune() takes int, not size_t. However, it just looks
// at the leading byte and treats any length >= 4 the same.
if (fullrune(sp->data(), static_cast<int>(std::min(size_t{4}, sp->size())))) {
@@ -1411,18 +1411,18 @@ static int StringPieceToRune(Rune *r, StringPiece *sp, RegexpStatus* status) {
if (status != NULL) {
status->set_code(kRegexpBadUTF8);
- status->set_error_arg(StringPiece());
+ status->set_error_arg(absl::string_view());
}
return -1;
}
// Returns whether name is valid UTF-8.
// If not, sets status to kRegexpBadUTF8.
-static bool IsValidUTF8(const StringPiece& s, RegexpStatus* status) {
- StringPiece t = s;
+static bool IsValidUTF8(const absl::string_view& s, RegexpStatus* status) {
+ absl::string_view t = s;
Rune r;
while (!t.empty()) {
- if (StringPieceToRune(&r, &t, status) < 0)
+ if (StringViewToRune(&r, &t, status) < 0)
return false;
}
return true;
@@ -1450,23 +1450,23 @@ static int UnHex(int c) {
// Parse an escape sequence (e.g., \n, \{).
// Sets *s to span the remainder of the string.
// Sets *rp to the named character.
-static bool ParseEscape(StringPiece* s, Rune* rp,
+static bool ParseEscape(absl::string_view* s, Rune* rp,
RegexpStatus* status, int rune_max) {
const char* begin = s->data();
if (s->empty() || (*s)[0] != '\\') {
// Should not happen - caller always checks.
status->set_code(kRegexpInternalError);
- status->set_error_arg(StringPiece());
+ status->set_error_arg(absl::string_view());
return false;
}
if (s->size() == 1) {
status->set_code(kRegexpTrailingBackslash);
- status->set_error_arg(StringPiece());
+ status->set_error_arg(absl::string_view());
return false;
}
Rune c, c1;
s->remove_prefix(1); // backslash
- if (StringPieceToRune(&c, s, status) < 0)
+ if (StringViewToRune(&c, s, status) < 0)
return false;
int code;
switch (c) {
@@ -1516,7 +1516,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
case 'x':
if (s->empty())
goto BadEscape;
- if (StringPieceToRune(&c, s, status) < 0)
+ if (StringViewToRune(&c, s, status) < 0)
return false;
if (c == '{') {
// Any number of digits in braces.
@@ -1525,7 +1525,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
// Perl accepts any text at all; it ignores all text
// after the first non-hex digit. We require only hex digits,
// and at least one.
- if (StringPieceToRune(&c, s, status) < 0)
+ if (StringViewToRune(&c, s, status) < 0)
return false;
int nhex = 0;
code = 0;
@@ -1536,7 +1536,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
goto BadEscape;
if (s->empty())
goto BadEscape;
- if (StringPieceToRune(&c, s, status) < 0)
+ if (StringViewToRune(&c, s, status) < 0)
return false;
}
if (c != '}' || nhex == 0)
@@ -1547,7 +1547,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
// Easy case: two hex digits.
if (s->empty())
goto BadEscape;
- if (StringPieceToRune(&c1, s, status) < 0)
+ if (StringViewToRune(&c1, s, status) < 0)
return false;
if (!IsHex(c) || !IsHex(c1))
goto BadEscape;
@@ -1595,7 +1595,7 @@ BadEscape:
// Unrecognized escape sequence.
status->set_code(kRegexpBadEscape);
status->set_error_arg(
- StringPiece(begin, static_cast<size_t>(s->data() - begin)));
+ absl::string_view(begin, static_cast<size_t>(s->data() - begin)));
return false;
}
@@ -1623,21 +1623,21 @@ void CharClassBuilder::AddRangeFlags(
}
// Look for a group with the given name.
-static const UGroup* LookupGroup(const StringPiece& name,
+static const UGroup* LookupGroup(const absl::string_view& name,
const UGroup *groups, int ngroups) {
// Simple name lookup.
for (int i = 0; i < ngroups; i++)
- if (StringPiece(groups[i].name) == name)
+ if (absl::string_view(groups[i].name) == name)
return &groups[i];
return NULL;
}
// Look for a POSIX group with the given name (e.g., "[:^alpha:]")
-static const UGroup* LookupPosixGroup(const StringPiece& name) {
+static const UGroup* LookupPosixGroup(const absl::string_view& name) {
return LookupGroup(name, posix_groups, num_posix_groups);
}
-static const UGroup* LookupPerlGroup(const StringPiece& name) {
+static const UGroup* LookupPerlGroup(const absl::string_view& name) {
return LookupGroup(name, perl_groups, num_perl_groups);
}
@@ -1648,9 +1648,9 @@ static URange32 any32[] = { { 65536, Runemax } };
static UGroup anygroup = { "Any", +1, any16, 1, any32, 1 };
// Look for a Unicode group with the given name (e.g., "Han")
-static const UGroup* LookupUnicodeGroup(const StringPiece& name) {
+static const UGroup* LookupUnicodeGroup(const absl::string_view& name) {
// Special case: "Any" means any.
- if (name == StringPiece("Any"))
+ if (name == absl::string_view("Any"))
return &anygroup;
return LookupGroup(name, unicode_groups, num_unicode_groups);
}
@@ -1707,15 +1707,15 @@ static void AddUGroup(CharClassBuilder *cc, const UGroup *g, int sign,
// not the Perl empty-string classes (\b \B \A \Z \z).
// On success, sets *s to span the remainder of the string
// and returns the corresponding UGroup.
-// The StringPiece must *NOT* be edited unless the call succeeds.
-const UGroup* MaybeParsePerlCCEscape(StringPiece* s, Regexp::ParseFlags parse_flags) {
+// The absl::string_view must *NOT* be edited unless the call succeeds.
+const UGroup* MaybeParsePerlCCEscape(absl::string_view* s, Regexp::ParseFlags parse_flags) {
if (!(parse_flags & Regexp::PerlClasses))
return NULL;
if (s->size() < 2 || (*s)[0] != '\\')
return NULL;
- // Could use StringPieceToRune, but there aren't
+ // Could use StringViewToRune, but there aren't
// any non-ASCII Perl group names.
- StringPiece name(s->data(), 2);
+ absl::string_view name(s->data(), 2);
const UGroup *g = LookupPerlGroup(name);
if (g == NULL)
return NULL;
@@ -1731,7 +1731,7 @@ enum ParseStatus {
// Maybe parses a Unicode character group like \p{Han} or \P{Han}
// (the latter is a negated group).
-ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
+ParseStatus ParseUnicodeGroup(absl::string_view* s, Regexp::ParseFlags parse_flags,
CharClassBuilder *cc,
RegexpStatus* status) {
// Decide whether to parse.
@@ -1747,34 +1747,34 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
int sign = +1; // -1 = negated char class
if (c == 'P')
sign = -sign;
- StringPiece seq = *s; // \p{Han} or \pL
- StringPiece name; // Han or L
+ absl::string_view seq = *s; // \p{Han} or \pL
+ absl::string_view name; // Han or L
s->remove_prefix(2); // '\\', 'p'
- if (!StringPieceToRune(&c, s, status))
+ if (!StringViewToRune(&c, s, status))
return kParseError;
if (c != '{') {
// Name is the bit of string we just skipped over for c.
const char* p = seq.data() + 2;
- name = StringPiece(p, static_cast<size_t>(s->data() - p));
+ name = absl::string_view(p, static_cast<size_t>(s->data() - p));
} else {
// Name is in braces. Look for closing }
size_t end = s->find('}', 0);
- if (end == StringPiece::npos) {
+ if (end == absl::string_view::npos) {
if (!IsValidUTF8(seq, status))
return kParseError;
status->set_code(kRegexpBadCharRange);
status->set_error_arg(seq);
return kParseError;
}
- name = StringPiece(s->data(), end); // without '}'
+ name = absl::string_view(s->data(), end); // without '}'
s->remove_prefix(end + 1); // with '}'
if (!IsValidUTF8(name, status))
return kParseError;
}
// Chop seq where s now begins.
- seq = StringPiece(seq.data(), static_cast<size_t>(s->data() - seq.data()));
+ seq = absl::string_view(seq.data(), static_cast<size_t>(s->data() - seq.data()));
if (!name.empty() && name[0] == '^') {
sign = -sign;
@@ -1821,7 +1821,7 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
// Parses a character class name like [:alnum:].
// Sets *s to span the remainder of the string.
// Adds the ranges corresponding to the class to ranges.
-static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
+static ParseStatus ParseCCName(absl::string_view* s, Regexp::ParseFlags parse_flags,
CharClassBuilder *cc,
RegexpStatus* status) {
// Check begins with [:
@@ -1841,7 +1841,7 @@ static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
// Got it. Check that it's valid.
q += 2;
- StringPiece name(p, static_cast<size_t>(q - p));
+ absl::string_view name(p, static_cast<size_t>(q - p));
const UGroup *g = LookupPosixGroup(name);
if (g == NULL) {
@@ -1859,8 +1859,8 @@ static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
// There are fewer special characters here than in the rest of the regexp.
// Sets *s to span the remainder of the string.
// Sets *rp to the character.
-bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
- const StringPiece& whole_class,
+bool Regexp::ParseState::ParseCCCharacter(absl::string_view* s, Rune *rp,
+ const absl::string_view& whole_class,
RegexpStatus* status) {
if (s->empty()) {
status->set_code(kRegexpMissingBracket);
@@ -1874,7 +1874,7 @@ bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
return ParseEscape(s, rp, status, rune_max_);
// Otherwise take the next rune.
- return StringPieceToRune(rp, s, status) >= 0;
+ return StringViewToRune(rp, s, status) >= 0;
}
// Parses a character class character, or, if the character
@@ -1882,10 +1882,10 @@ bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
// For single characters, rr->lo == rr->hi.
// Sets *s to span the remainder of the string.
// Sets *rp to the character.
-bool Regexp::ParseState::ParseCCRange(StringPiece* s, RuneRange* rr,
- const StringPiece& whole_class,
+bool Regexp::ParseState::ParseCCRange(absl::string_view* s, RuneRange* rr,
+ const absl::string_view& whole_class,
RegexpStatus* status) {
- StringPiece os = *s;
+ absl::string_view os = *s;
if (!ParseCCCharacter(s, &rr->lo, whole_class, status))
return false;
// [a-] means (a|-), so check for final ].
@@ -1896,7 +1896,7 @@ bool Regexp::ParseState::ParseCCRange(StringPiece* s, RuneRange* rr,
if (rr->hi < rr->lo) {
status->set_code(kRegexpBadCharRange);
status->set_error_arg(
- StringPiece(os.data(), static_cast<size_t>(s->data() - os.data())));
+ absl::string_view(os.data(), static_cast<size_t>(s->data() - os.data())));
return false;
}
} else {
@@ -1908,14 +1908,14 @@ bool Regexp::ParseState::ParseCCRange(StringPiece* s, RuneRange* rr,
// Parses a possibly-negated character class expression like [^abx-z[:digit:]].
// Sets *s to span the remainder of the string.
// Sets *out_re to the regexp for the class.
-bool Regexp::ParseState::ParseCharClass(StringPiece* s,
+bool Regexp::ParseState::ParseCharClass(absl::string_view* s,
Regexp** out_re,
RegexpStatus* status) {
- StringPiece whole_class = *s;
+ absl::string_view whole_class = *s;
if (s->empty() || (*s)[0] != '[') {
// Caller checked this.
status->set_code(kRegexpInternalError);
- status->set_error_arg(StringPiece());
+ status->set_error_arg(absl::string_view());
return false;
}
bool negated = false;
@@ -1937,16 +1937,16 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
// Except that Perl allows - anywhere.
if ((*s)[0] == '-' && !first && !(flags_&PerlX) &&
(s->size() == 1 || (*s)[1] != ']')) {
- StringPiece t = *s;
+ absl::string_view t = *s;
t.remove_prefix(1); // '-'
Rune r;
- int n = StringPieceToRune(&r, &t, status);
+ int n = StringViewToRune(&r, &t, status);
if (n < 0) {
re->Decref();
return false;
}
status->set_code(kRegexpBadCharRange);
- status->set_error_arg(StringPiece(s->data(), 1+n));
+ status->set_error_arg(absl::string_view(s->data(), 1+n));
re->Decref();
return false;
}
@@ -2016,7 +2016,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
}
// Returns whether name is a valid capture name.
-static bool IsValidCaptureName(const StringPiece& name) {
+static bool IsValidCaptureName(const absl::string_view& name) {
if (name.empty())
return false;
@@ -2030,17 +2030,17 @@ static bool IsValidCaptureName(const StringPiece& name) {
// if they start doing that for capture names, we won't follow suit.
static const CharClass* const cc = []() {
CharClassBuilder ccb;
- for (StringPiece group :
+ for (absl::string_view group :
{"Lu", "Ll", "Lt", "Lm", "Lo", "Nl", "Mn", "Mc", "Nd", "Pc"})
AddUGroup(&ccb, LookupGroup(group, unicode_groups, num_unicode_groups),
+1, Regexp::NoParseFlags);
return ccb.GetCharClass();
}();
- StringPiece t = name;
+ absl::string_view t = name;
Rune r;
while (!t.empty()) {
- if (StringPieceToRune(&r, &t, NULL) < 0)
+ if (StringViewToRune(&r, &t, NULL) < 0)
return false;
if (cc->Contains(r))
continue;
@@ -2054,8 +2054,8 @@ static bool IsValidCaptureName(const StringPiece& name) {
// The caller must check that s begins with "(?".
// Returns true on success. If the Perl flag is not
// well-formed or not supported, sets status_ and returns false.
-bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
- StringPiece t = *s;
+bool Regexp::ParseState::ParsePerlFlags(absl::string_view* s) {
+ absl::string_view t = *s;
// Caller is supposed to check this.
if (!(flags_ & PerlX) || t.size() < 2 || t[0] != '(' || t[1] != '?') {
@@ -2084,7 +2084,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
if (t.size() > 2 && t[0] == 'P' && t[1] == '<') {
// Pull out name.
size_t end = t.find('>', 2);
- if (end == StringPiece::npos) {
+ if (end == absl::string_view::npos) {
if (!IsValidUTF8(*s, status_))
return false;
status_->set_code(kRegexpBadNamedCapture);
@@ -2093,8 +2093,8 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
}
// t is "P<name>...", t[end] == '>'
- StringPiece capture(t.data()-2, end+3); // "(?P<name>"
- StringPiece name(t.data()+2, end-2); // "name"
+ absl::string_view capture(t.data()-2, end+3); // "(?P<name>"
+ absl::string_view name(t.data()+2, end-2); // "name"
if (!IsValidUTF8(name, status_))
return false;
if (!IsValidCaptureName(name)) {
@@ -2120,7 +2120,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
for (bool done = false; !done; ) {