Skip to content

Commit

Permalink
Get rid of using std::string;. (part 6 of N)
Browse files Browse the repository at this point in the history
Change-Id: Ib035703780c88764b952ac09421a0e0524fc00ec
Reviewed-on: https://code-review.googlesource.com/c/re2/+/39134
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Mar 18, 2019
1 parent b049f8e commit 0e35179
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 86 deletions.
16 changes: 8 additions & 8 deletions re2/testing/compile_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ TEST(TestRegexpCompileToProg, Simple) {
continue;
}
ASSERT_TRUE(re->CompileToProg(1) == NULL);
string s = prog->Dump();
std::string s = prog->Dump();
if (s != t.code) {
LOG(ERROR) << "Incorrect compiled code for: " << t.regexp;
LOG(ERROR) << "Want:\n" << t.code;
Expand All @@ -143,7 +143,7 @@ TEST(TestRegexpCompileToProg, Simple) {
}

static void DumpByteMap(StringPiece pattern, Regexp::ParseFlags flags,
string* bytemap) {
std::string* bytemap) {
Regexp* re = Regexp::Parse(pattern, flags, NULL);
EXPECT_TRUE(re != NULL);

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

string bytemap;
std::string bytemap;

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

TEST(TestCompile, OtherByteMapTests) {
string bytemap;
std::string bytemap;

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

string bytemap;
std::string bytemap;

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

static void Dump(StringPiece pattern, Regexp::ParseFlags flags,
string* forward, string* reverse) {
std::string* forward, std::string* reverse) {
Regexp* re = Regexp::Parse(pattern, flags, NULL);
EXPECT_TRUE(re != NULL);

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

string forward, reverse;
std::string forward, reverse;

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

string forward;
std::string forward;

Dump("a**{3,}", Regexp::Latin1|Regexp::NeverCapture, &forward, NULL);
EXPECT_EQ("3+ byte [61-61] 1 -> 3\n"
Expand Down
16 changes: 8 additions & 8 deletions re2/testing/dfa_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void DoBuild(Prog* prog) {

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

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

string s;
std::string s;
for (int i = 0; i < n-1; i++)
s.append("0");
int bits = 0;
Expand Down Expand Up @@ -180,8 +180,8 @@ TEST(SingleThreaded, SearchDFA) {

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

int64_t usage;
int64_t peak_usage;
Expand Down Expand Up @@ -243,8 +243,8 @@ TEST(Multithreaded, SearchDFA) {
Regexp* re = Regexp::Parse(StringPrintf("0[01]{%d}$", n),
Regexp::LikePerl, NULL);
ASSERT_TRUE(re != NULL);
string no_match = DeBruijnString(n);
string match = no_match + "0";
std::string no_match = DeBruijnString(n);
std::string match = no_match + "0";

// Check that single-threaded code works.
{
Expand Down Expand Up @@ -356,7 +356,7 @@ TEST(DFA, Callback) {
ASSERT_TRUE(re != NULL);
Prog* prog = re->CompileToProg(0);
ASSERT_TRUE(prog != NULL);
string dump;
std::string dump;
prog->BuildEntireDFA(Prog::kLongestMatch, [&](const int* next, bool match) {
ASSERT_TRUE(next != NULL);
if (!dump.empty())
Expand Down
8 changes: 4 additions & 4 deletions re2/testing/dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static const char* kOpcodeNames[] = {

// Create string representation of regexp with explicit structure.
// Nothing pretty, just for testing.
static void DumpRegexpAppending(Regexp* re, string* s) {
static void DumpRegexpAppending(Regexp* re, std::string* s) {
if (re->op() < 0 || re->op() >= arraysize(kOpcodeNames)) {
StringAppendF(s, "op%d", re->op());
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ static void DumpRegexpAppending(Regexp* re, string* s) {
DumpRegexpAppending(re->sub()[0], s);
break;
case kRegexpCharClass: {
string sep;
std::string sep;
for (CharClass::iterator it = re->cc()->begin();
it != re->cc()->end(); ++it) {
RuneRange rr = *it;
Expand All @@ -153,8 +153,8 @@ static void DumpRegexpAppending(Regexp* re, string* s) {
s->append("}");
}

string Regexp::Dump() {
string s;
std::string Regexp::Dump() {
std::string s;

// Make sure being called from a unit test.
if (FLAGS_test_tmpdir.empty()) {
Expand Down
6 changes: 3 additions & 3 deletions re2/testing/exhaustive1_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace re2 {

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

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

// This would be a great test, but it runs forever when PCRE is enabled.
if (FLAGS_regexp_engines.find("PCRE") == string::npos)
if (FLAGS_regexp_engines.find("PCRE") == std::string::npos)
ExhaustiveTest(3, 2, Split(" ", "a (a)"), ops,
50, Explode("a"), "(?:%s)", "");
}
Expand Down
6 changes: 3 additions & 3 deletions re2/testing/exhaustive2_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TEST(EmptyString, Exhaustive) {

// Test escaped versions of regexp syntax.
TEST(Punctuation, Literals) {
std::vector<string> alphabet = Explode("()*+?{}[]\\^$.");
std::vector<string> escaped = alphabet;
std::vector<std::string> alphabet = Explode("()*+?{}[]\\^$.");
std::vector<std::string> escaped = alphabet;
for (size_t i = 0; i < escaped.size(); i++)
escaped[i] = "\\" + escaped[i];
ExhaustiveTest(1, 1, escaped, RegexpGenerator::EgrepOps(),
Expand Down Expand Up @@ -63,7 +63,7 @@ TEST(LineEnds, Exhaustive) {
// provides a mechanism, and RE2 could add new syntax if needed.
//
// TEST(Newlines, Exhaustive) {
// std::vector<string> empty_vector;
// std::vector<std::string> empty_vector;
// ExhaustiveTest(1, 1, Split(" ", "\\n . a [^a]"),
// RegexpGenerator::EgrepOps(),
// 4, Explode("a\n"), "");
Expand Down
22 changes: 11 additions & 11 deletions re2/testing/exhaustive3_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ namespace re2 {

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

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

// Returns UTF8 for Rune r
static string UTF8(Rune r) {
static std::string UTF8(Rune r) {
char buf[UTFmax+1];
buf[runetochar(buf, &r)] = 0;
return string(buf);
return std::string(buf);
}

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

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

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

// Test interesting UTF-8 characters against character classes,
// but wrap everything inside AB.
TEST(InterestingUTF8, AB) {
std::vector<string> atoms = Split(" ",
std::vector<std::string> atoms = Split(" ",
". ^ $ \\a \\f \\n \\r \\t \\v \\d \\D \\s \\S \\w \\W \\b \\B "
"[[:alnum:]] [[:alpha:]] [[:blank:]] [[:cntrl:]] [[:digit:]] "
"[[:graph:]] [[:lower:]] [[:print:]] [[:punct:]] [[:space:]] "
"[[:upper:]] [[:xdigit:]] [\\s\\S] [\\d\\D] [^\\w\\W] [^\\d\\D]");
std::vector<string> ops; // no ops
std::vector<string> alpha = InterestingUTF8();
std::vector<std::string> ops; // no ops
std::vector<std::string> alpha = InterestingUTF8();
for (size_t i = 0; i < alpha.size(); i++)
alpha[i] = "a" + alpha[i] + "b";
ExhaustiveTest(1, 0, atoms, ops,
Expand Down
18 changes: 9 additions & 9 deletions re2/testing/filtered_re2_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct FilterTestVars {
FilterTestVars() {}
explicit FilterTestVars(int min_atom_len) : f(min_atom_len) {}

std::vector<string> atoms;
std::vector<std::string> atoms;
std::vector<int> atom_indices;
std::vector<int> matches;
RE2::Options opts;
Expand Down Expand Up @@ -157,7 +157,7 @@ bool CheckExpectedAtoms(const char* atoms[],
int n,
const char* testname,
struct FilterTestVars* v) {
std::vector<string> expected;
std::vector<std::string> expected;
for (int i = 0; i < n; i++)
expected.push_back(atoms[i]);

Expand Down Expand Up @@ -200,8 +200,8 @@ TEST(FilteredRE2Test, AtomTests) {
EXPECT_EQ(0, nfail);
}

void FindAtomIndices(const std::vector<string>& atoms,
const std::vector<string>& matched_atoms,
void FindAtomIndices(const std::vector<std::string>& atoms,
const std::vector<std::string>& matched_atoms,
std::vector<int>* atom_indices) {
atom_indices->clear();
for (size_t i = 0; i < matched_atoms.size(); i++) {
Expand All @@ -220,13 +220,13 @@ TEST(FilteredRE2Test, MatchEmptyPattern) {
// We are using the regexps used in one of the atom tests
// for this test. Adding the EXPECT here to make sure
// the index we use for the test is for the correct test.
EXPECT_EQ("CheckEmptyPattern", string(t->testname));
EXPECT_EQ("CheckEmptyPattern", std::string(t->testname));
int nregexp;
for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
if (t->regexps[nregexp] == NULL)
break;
AddRegexpsAndCompile(t->regexps, nregexp, &v);
string text = "0123";
std::string text = "0123";
std::vector<int> atom_ids;
std::vector<int> matching_regexps;
EXPECT_EQ(0, v.f.FirstMatch(text, atom_ids));
Expand All @@ -237,17 +237,17 @@ TEST(FilteredRE2Test, MatchTests) {
AtomTest* t = &atom_tests[2];
// We are using the regexps used in one of the atom tests
// for this test.
EXPECT_EQ("SubstrAtomRemovesSuperStrInOr", string(t->testname));
EXPECT_EQ("SubstrAtomRemovesSuperStrInOr", std::string(t->testname));
int nregexp;
for (nregexp = 0; nregexp < arraysize(t->regexps); nregexp++)
if (t->regexps[nregexp] == NULL)
break;
AddRegexpsAndCompile(t->regexps, nregexp, &v);

string text = "abc121212xyz";
std::string text = "abc121212xyz";
// atoms = abc
std::vector<int> atom_ids;
std::vector<string> atoms;
std::vector<std::string> atoms;
atoms.push_back("abc");
FindAtomIndices(v.atoms, atoms, &atom_ids);
std::vector<int> matching_regexps;
Expand Down
Loading

0 comments on commit 0e35179

Please sign in to comment.