Skip to content

Commit 0e35179

Browse files
committed
Get rid of using std::string;. (part 6 of N)
Change-Id: Ib035703780c88764b952ac09421a0e0524fc00ec Reviewed-on: https://code-review.googlesource.com/c/re2/+/39134 Reviewed-by: Paul Wankadia <[email protected]>
1 parent b049f8e commit 0e35179

15 files changed

+91
-86
lines changed

re2/testing/compile_test.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ TEST(TestRegexpCompileToProg, Simple) {
129129
continue;
130130
}
131131
ASSERT_TRUE(re->CompileToProg(1) == NULL);
132-
string s = prog->Dump();
132+
std::string s = prog->Dump();
133133
if (s != t.code) {
134134
LOG(ERROR) << "Incorrect compiled code for: " << t.regexp;
135135
LOG(ERROR) << "Want:\n" << t.code;
@@ -143,7 +143,7 @@ TEST(TestRegexpCompileToProg, Simple) {
143143
}
144144

145145
static void DumpByteMap(StringPiece pattern, Regexp::ParseFlags flags,
146-
string* bytemap) {
146+
std::string* bytemap) {
147147
Regexp* re = Regexp::Parse(pattern, flags, NULL);
148148
EXPECT_TRUE(re != NULL);
149149

@@ -158,7 +158,7 @@ static void DumpByteMap(StringPiece pattern, Regexp::ParseFlags flags,
158158
TEST(TestCompile, Latin1Ranges) {
159159
// The distinct byte ranges involved in the Latin-1 dot ([^\n]).
160160

161-
string bytemap;
161+
std::string bytemap;
162162

163163
DumpByteMap(".", Regexp::PerlX|Regexp::Latin1, &bytemap);
164164
EXPECT_EQ("[00-09] -> 0\n"
@@ -168,7 +168,7 @@ TEST(TestCompile, Latin1Ranges) {
168168
}
169169

170170
TEST(TestCompile, OtherByteMapTests) {
171-
string bytemap;
171+
std::string bytemap;
172172

173173
// Test that "absent" ranges are mapped to the same byte class.
174174
DumpByteMap("[0-9A-Fa-f]+", Regexp::PerlX|Regexp::Latin1, &bytemap);
@@ -207,7 +207,7 @@ TEST(TestCompile, UTF8Ranges) {
207207
// Once, erroneously split between 0x3f and 0x40 because it is
208208
// a 6-bit boundary.
209209

210-
string bytemap;
210+
std::string bytemap;
211211

212212
DumpByteMap(".", Regexp::PerlX, &bytemap);
213213
EXPECT_EQ("[00-09] -> 0\n"
@@ -240,7 +240,7 @@ TEST(TestCompile, InsufficientMemory) {
240240
}
241241

242242
static void Dump(StringPiece pattern, Regexp::ParseFlags flags,
243-
string* forward, string* reverse) {
243+
std::string* forward, std::string* reverse) {
244244
Regexp* re = Regexp::Parse(pattern, flags, NULL);
245245
EXPECT_TRUE(re != NULL);
246246

@@ -265,7 +265,7 @@ TEST(TestCompile, Bug26705922) {
265265
// Bug in the compiler caused inefficient bytecode to be generated for Unicode
266266
// groups: common suffixes were cached, but common prefixes were not factored.
267267

268-
string forward, reverse;
268+
std::string forward, reverse;
269269

270270
Dump("[\\x{10000}\\x{10010}]", Regexp::LikePerl, &forward, &reverse);
271271
EXPECT_EQ("3. byte [f0-f0] 0 -> 4\n"
@@ -320,7 +320,7 @@ TEST(TestCompile, Bug35237384) {
320320
// Bug in the compiler caused inefficient bytecode to be generated for
321321
// nested nullable subexpressions.
322322

323-
string forward;
323+
std::string forward;
324324

325325
Dump("a**{3,}", Regexp::Latin1|Regexp::NeverCapture, &forward, NULL);
326326
EXPECT_EQ("3+ byte [61-61] 1 -> 3\n"

re2/testing/dfa_test.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void DoBuild(Prog* prog) {
3333

3434
TEST(Multithreaded, BuildEntireDFA) {
3535
// Create regexp with 2^FLAGS_size states in DFA.
36-
string s = "a";
36+
std::string s = "a";
3737
for (int i = 0; i < FLAGS_size; i++)
3838
s += "[ab]";
3939
s += "b";
@@ -116,15 +116,15 @@ TEST(SingleThreaded, BuildEntireDFA) {
116116
// DeBruijn string causes the DFA to need to create a new state at every
117117
// position in the input, never reusing any states until it gets to the
118118
// end of the string. This is the worst possible case for DFA execution.
119-
static string DeBruijnString(int n) {
119+
static std::string DeBruijnString(int n) {
120120
CHECK_LT(n, static_cast<int>(8*sizeof(int)));
121121
CHECK_GT(n, 0);
122122

123123
std::vector<bool> did(size_t{1}<<n);
124124
for (int i = 0; i < 1<<n; i++)
125125
did[i] = false;
126126

127-
string s;
127+
std::string s;
128128
for (int i = 0; i < n-1; i++)
129129
s.append("0");
130130
int bits = 0;
@@ -180,8 +180,8 @@ TEST(SingleThreaded, SearchDFA) {
180180

181181
// The De Bruijn string for n ends with a 1 followed by n 0s in a row,
182182
// which is not a match for 0[01]{n}$. Adding one more 0 is a match.
183-
string no_match = DeBruijnString(n);
184-
string match = no_match + "0";
183+
std::string no_match = DeBruijnString(n);
184+
std::string match = no_match + "0";
185185

186186
int64_t usage;
187187
int64_t peak_usage;
@@ -243,8 +243,8 @@ TEST(Multithreaded, SearchDFA) {
243243
Regexp* re = Regexp::Parse(StringPrintf("0[01]{%d}$", n),
244244
Regexp::LikePerl, NULL);
245245
ASSERT_TRUE(re != NULL);
246-
string no_match = DeBruijnString(n);
247-
string match = no_match + "0";
246+
std::string no_match = DeBruijnString(n);
247+
std::string match = no_match + "0";
248248

249249
// Check that single-threaded code works.
250250
{
@@ -356,7 +356,7 @@ TEST(DFA, Callback) {
356356
ASSERT_TRUE(re != NULL);
357357
Prog* prog = re->CompileToProg(0);
358358
ASSERT_TRUE(prog != NULL);
359-
string dump;
359+
std::string dump;
360360
prog->BuildEntireDFA(Prog::kLongestMatch, [&](const int* next, bool match) {
361361
ASSERT_TRUE(next != NULL);
362362
if (!dump.empty())

re2/testing/dump.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static const char* kOpcodeNames[] = {
5757

5858
// Create string representation of regexp with explicit structure.
5959
// Nothing pretty, just for testing.
60-
static void DumpRegexpAppending(Regexp* re, string* s) {
60+
static void DumpRegexpAppending(Regexp* re, std::string* s) {
6161
if (re->op() < 0 || re->op() >= arraysize(kOpcodeNames)) {
6262
StringAppendF(s, "op%d", re->op());
6363
} else {
@@ -136,7 +136,7 @@ static void DumpRegexpAppending(Regexp* re, string* s) {
136136
DumpRegexpAppending(re->sub()[0], s);
137137
break;
138138
case kRegexpCharClass: {
139-
string sep;
139+
std::string sep;
140140
for (CharClass::iterator it = re->cc()->begin();
141141
it != re->cc()->end(); ++it) {
142142
RuneRange rr = *it;
@@ -153,8 +153,8 @@ static void DumpRegexpAppending(Regexp* re, string* s) {
153153
s->append("}");
154154
}
155155

156-
string Regexp::Dump() {
157-
string s;
156+
std::string Regexp::Dump() {
157+
std::string s;
158158

159159
// Make sure being called from a unit test.
160160
if (FLAGS_test_tmpdir.empty()) {

re2/testing/exhaustive1_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace re2 {
1616

1717
// Test simple repetition operators
1818
TEST(Repetition, Simple) {
19-
std::vector<string> ops = Split(" ",
19+
std::vector<std::string> ops = Split(" ",
2020
"%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} "
2121
"%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} "
2222
"%s* %s+ %s? %s*? %s+? %s??");
@@ -28,15 +28,15 @@ TEST(Repetition, Simple) {
2828

2929
// Test capturing parens -- (a) -- inside repetition operators
3030
TEST(Repetition, Capturing) {
31-
std::vector<string> ops = Split(" ",
31+
std::vector<std::string> ops = Split(" ",
3232
"%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} "
3333
"%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} "
3434
"%s* %s+ %s? %s*? %s+? %s??");
3535
ExhaustiveTest(3, 2, Split(" ", "a (a) b"), ops,
3636
7, Explode("ab"), "(?:%s)", "");
3737

3838
// This would be a great test, but it runs forever when PCRE is enabled.
39-
if (FLAGS_regexp_engines.find("PCRE") == string::npos)
39+
if (FLAGS_regexp_engines.find("PCRE") == std::string::npos)
4040
ExhaustiveTest(3, 2, Split(" ", "a (a)"), ops,
4141
50, Explode("a"), "(?:%s)", "");
4242
}

re2/testing/exhaustive2_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ TEST(EmptyString, Exhaustive) {
2424

2525
// Test escaped versions of regexp syntax.
2626
TEST(Punctuation, Literals) {
27-
std::vector<string> alphabet = Explode("()*+?{}[]\\^$.");
28-
std::vector<string> escaped = alphabet;
27+
std::vector<std::string> alphabet = Explode("()*+?{}[]\\^$.");
28+
std::vector<std::string> escaped = alphabet;
2929
for (size_t i = 0; i < escaped.size(); i++)
3030
escaped[i] = "\\" + escaped[i];
3131
ExhaustiveTest(1, 1, escaped, RegexpGenerator::EgrepOps(),
@@ -63,7 +63,7 @@ TEST(LineEnds, Exhaustive) {
6363
// provides a mechanism, and RE2 could add new syntax if needed.
6464
//
6565
// TEST(Newlines, Exhaustive) {
66-
// std::vector<string> empty_vector;
66+
// std::vector<std::string> empty_vector;
6767
// ExhaustiveTest(1, 1, Split(" ", "\\n . a [^a]"),
6868
// RegexpGenerator::EgrepOps(),
6969
// 4, Explode("a\n"), "");

re2/testing/exhaustive3_test.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@ namespace re2 {
1717

1818
// Test simple character classes by themselves.
1919
TEST(CharacterClasses, Exhaustive) {
20-
std::vector<string> atoms = Split(" ",
20+
std::vector<std::string> atoms = Split(" ",
2121
"[a] [b] [ab] [^bc] [b-d] [^b-d] []a] [-a] [a-] [^-a] [a-b-c] a b .");
2222
ExhaustiveTest(2, 1, atoms, RegexpGenerator::EgrepOps(),
2323
5, Explode("ab"), "", "");
2424
}
2525

2626
// Test simple character classes inside a___b (for example, a[a]b).
2727
TEST(CharacterClasses, ExhaustiveAB) {
28-
std::vector<string> atoms = Split(" ",
28+
std::vector<std::string> atoms = Split(" ",
2929
"[a] [b] [ab] [^bc] [b-d] [^b-d] []a] [-a] [a-] [^-a] [a-b-c] a b .");
3030
ExhaustiveTest(2, 1, atoms, RegexpGenerator::EgrepOps(),
3131
5, Explode("ab"), "a%sb", "");
3232
}
3333

3434
// Returns UTF8 for Rune r
35-
static string UTF8(Rune r) {
35+
static std::string UTF8(Rune r) {
3636
char buf[UTFmax+1];
3737
buf[runetochar(buf, &r)] = 0;
38-
return string(buf);
38+
return std::string(buf);
3939
}
4040

4141
// Returns a vector of "interesting" UTF8 characters.
4242
// Unicode is now too big to just return all of them,
4343
// so UTF8Characters return a set likely to be good test cases.
44-
static const std::vector<string>& InterestingUTF8() {
44+
static const std::vector<std::string>& InterestingUTF8() {
4545
static bool init;
46-
static std::vector<string> v;
46+
static std::vector<std::string> v;
4747

4848
if (init)
4949
return v;
@@ -70,26 +70,26 @@ static const std::vector<string>& InterestingUTF8() {
7070

7171
// Test interesting UTF-8 characters against character classes.
7272
TEST(InterestingUTF8, SingleOps) {
73-
std::vector<string> atoms = Split(" ",
73+
std::vector<std::string> atoms = Split(" ",
7474
". ^ $ \\a \\f \\n \\r \\t \\v \\d \\D \\s \\S \\w \\W \\b \\B "
7575
"[[:alnum:]] [[:alpha:]] [[:blank:]] [[:cntrl:]] [[:digit:]] "
7676
"[[:graph:]] [[:lower:]] [[:print:]] [[:punct:]] [[:space:]] "
7777
"[[:upper:]] [[:xdigit:]] [\\s\\S] [\\d\\D] [^\\w\\W] [^\\d\\D]");
78-
std::vector<string> ops; // no ops
78+
std::vector<std::string> ops; // no ops
7979
ExhaustiveTest(1, 0, atoms, ops,
8080
1, InterestingUTF8(), "", "");
8181
}
8282

8383
// Test interesting UTF-8 characters against character classes,
8484
// but wrap everything inside AB.
8585
TEST(InterestingUTF8, AB) {
86-
std::vector<string> atoms = Split(" ",
86+
std::vector<std::string> atoms = Split(" ",
8787
". ^ $ \\a \\f \\n \\r \\t \\v \\d \\D \\s \\S \\w \\W \\b \\B "
8888
"[[:alnum:]] [[:alpha:]] [[:blank:]] [[:cntrl:]] [[:digit:]] "
8989
"[[:graph:]] [[:lower:]] [[:print:]] [[:punct:]] [[:space:]] "
9090
"[[:upper:]] [[:xdigit:]] [\\s\\S] [\\d\\D] [^\\w\\W] [^\\d\\D]");
91-
std::vector<string> ops; // no ops
92-
std::vector<string> alpha = InterestingUTF8();
91+
std::vector<std::string> ops; // no ops
92+
std::vector<std::string> alpha = InterestingUTF8();
9393
for (size_t i = 0; i < alpha.size(); i++)
9494
alpha[i] = "a" + alpha[i] + "b";
9595
ExhaustiveTest(1, 0, atoms, ops,

re2/testing/filtered_re2_test.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct FilterTestVars {
1919
FilterTestVars() {}
2020
explicit FilterTestVars(int min_atom_len) : f(min_atom_len) {}
2121

22-
std::vector<string> atoms;
22+
std::vector<std::string> atoms;
2323
std::vector<int> atom_indices;
2424
std::vector<int> matches;
2525
RE2::Options opts;
@@ -157,7 +157,7 @@ bool CheckExpectedAtoms(const char* atoms[],
157157
int n,
158158
const char* testname,
159159
struct FilterTestVars* v) {
160-
std::vector<string> expected;
160+
std::vector<std::string> expected;
161161
for (int i = 0; i < n; i++)
162162
expected.push_back(atoms[i]);
163163

@@ -200,8 +200,8 @@ TEST(FilteredRE2Test, AtomTests) {
200200
EXPECT_EQ(0, nfail);
201201
}
202202

203-
void FindAtomIndices(const std::vector<string>& atoms,
204-
const std::vector<string>& matched_atoms,
203+
void FindAtomIndices(const std::vector<std::string>& atoms,
204+
const std::vector<std::string>& matched_atoms,
205205
std::vector<int>* atom_indices) {
206206
atom_indices->clear();
207207
for (size_t i = 0; i < matched_atoms.size(); i++) {
@@ -220,13 +220,13 @@ TEST(FilteredRE2Test, MatchEmptyPattern) {
220220
// We are using the regexps used in one of the atom tests
221221
// for this test. Adding the EXPECT here to make sure
222222
// the index we use for the test is for the correct test.
223-
EXPECT_EQ("CheckEmptyPattern", string(t->testname));
223+
EXPECT_EQ("CheckEmptyPattern", std::string(t->testname));
224224
int nregexp;
225225
for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
226226
if (t->regexps[nregexp] == NULL)
227227
break;
228228
AddRegexpsAndCompile(t->regexps, nregexp, &v);
229-
string text = "0123";
229+
std::string text = "0123";
230230
std::vector<int> atom_ids;
231231
std::vector<int> matching_regexps;
232232
EXPECT_EQ(0, v.f.FirstMatch(text, atom_ids));
@@ -237,17 +237,17 @@ TEST(FilteredRE2Test, MatchTests) {
237237
AtomTest* t = &atom_tests[2];
238238
// We are using the regexps used in one of the atom tests
239239
// for this test.
240-
EXPECT_EQ("SubstrAtomRemovesSuperStrInOr", string(t->testname));
240+
EXPECT_EQ("SubstrAtomRemovesSuperStrInOr", std::string(t->testname));
241241
int nregexp;
242242
for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
243243
if (t->regexps[nregexp] == NULL)
244244
break;
245245
AddRegexpsAndCompile(t->regexps, nregexp, &v);
246246

247-
string text = "abc121212xyz";
247+
std::string text = "abc121212xyz";
248248
// atoms = abc
249249
std::vector<int> atom_ids;
250-
std::vector<string> atoms;
250+
std::vector<std::string> atoms;
251251
atoms.push_back("abc");
252252
FindAtomIndices(v.atoms, atoms, &atom_ids);
253253
std::vector<int> matching_regexps;

0 commit comments

Comments
 (0)