Stop using StringPiece::ToString().
Change-Id: Ia03c4bcce55d2784df9c4527e56bd5d4129cc9d5
Reviewed-on: https://code-review.googlesource.com/23010
Reviewed-by: Paul Wankadia <[email protected]>
diff --git a/re2/dfa.cc b/re2/dfa.cc
index bc81fea..50d1ad0 100644
--- a/re2/dfa.cc
+++ b/re2/dfa.cc
@@ -1779,7 +1779,7 @@
if (ExtraDebug) {
fprintf(stderr, "\nprogram:\n%s\n", prog_->DumpUnanchored().c_str());
fprintf(stderr, "text %s anchored=%d earliest=%d fwd=%d kind %d\n",
- text.ToString().c_str(), anchored, want_earliest_match,
+ string(text).c_str(), anchored, want_earliest_match,
run_forward, kind_);
}
diff --git a/re2/fuzzing/re2_fuzzer.cc b/re2/fuzzing/re2_fuzzer.cc
index d3cd145..5d2820b 100644
--- a/re2/fuzzing/re2_fuzzer.cc
+++ b/re2/fuzzing/re2_fuzzer.cc
@@ -45,7 +45,7 @@
RE2::Consume(&sp1, re, &i1, &i2, &i3, &i4);
RE2::FindAndConsume(&sp2, re, &d1, &d2, &d3, &d4);
- s3 = s4 = text.ToString();
+ s3 = s4 = string(text);
RE2::Replace(&s3, re, "");
RE2::GlobalReplace(&s4, re, "");
diff --git a/re2/nfa.cc b/re2/nfa.cc
index ac853f9..1a3e0af 100644
--- a/re2/nfa.cc
+++ b/re2/nfa.cc
@@ -492,8 +492,7 @@
if (ExtraDebug)
fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
- text.ToString().c_str(), context.ToString().c_str(), anchored,
- longest);
+ string(text).c_str(), string(context).c_str(), anchored, longest);
// Set up search.
Threadq* runq = &q0_;
diff --git a/re2/parse.cc b/re2/parse.cc
index 3374345..56b4244 100644
--- a/re2/parse.cc
+++ b/re2/parse.cc
@@ -609,7 +609,7 @@
Regexp* re = new Regexp(kLeftParen, flags_);
re->cap_ = ++ncap_;
if (name.data() != NULL)
- re->name_ = new string(name.ToString());
+ re->name_ = new string(name);
return PushRegexp(re);
}
@@ -1790,7 +1790,7 @@
// Look up the group in the ICU Unicode data. Because ICU provides full
// Unicode properties support, this could be more than a lookup by name.
::icu::UnicodeString ustr = ::icu::UnicodeString::fromUTF8(
- string("\\p{") + name.ToString() + string("}"));
+ string("\\p{") + string(name) + string("}"));
UErrorCode uerr = U_ZERO_ERROR;
::icu::UnicodeSet uset(ustr, uerr);
if (U_FAILURE(uerr)) {
diff --git a/re2/re2.cc b/re2/re2.cc
index 93729d9..7d787a8 100644
--- a/re2/re2.cc
+++ b/re2/re2.cc
@@ -99,8 +99,8 @@
static string trunc(const StringPiece& pattern) {
if (pattern.size() < 100)
- return pattern.ToString();
- return pattern.substr(0, 100).ToString() + "...";
+ return string(pattern);
+ return string(pattern.substr(0, 100)) + "...";
}
@@ -172,7 +172,7 @@
empty_group_names = new std::map<int, string>;
});
- pattern_ = pattern.ToString();
+ pattern_ = string(pattern);
options_.Copy(options);
entire_regexp_ = NULL;
suffix_regexp_ = NULL;
@@ -196,7 +196,7 @@
}
error_ = new string(status.Text());
error_code_ = RegexpErrorToRE2(status.code());
- error_arg_ = status.error_arg().ToString();
+ error_arg_ = string(status.error_arg());
return;
}
diff --git a/re2/set.cc b/re2/set.cc
index 8f736c4..9890de9 100644
--- a/re2/set.cc
+++ b/re2/set.cc
@@ -68,7 +68,7 @@
sub[1] = m;
re = re2::Regexp::Concat(sub, 2, pf);
}
- elem_.emplace_back(pattern.ToString(), re);
+ elem_.emplace_back(string(pattern), re);
return n;
}
diff --git a/re2/stringpiece.h b/re2/stringpiece.h
index 133cc82..1db7a2a 100644
--- a/re2/stringpiece.h
+++ b/re2/stringpiece.h
@@ -30,6 +30,7 @@
class StringPiece {
public:
+ typedef std::char_traits<char> traits_type;
typedef char value_type;
typedef char* pointer;
typedef const char* const_pointer;
@@ -90,6 +91,13 @@
size_ = len;
}
+ // Converts to `std::basic_string`.
+ template <typename A>
+ explicit operator std::basic_string<char, traits_type, A>() const {
+ if (!data_) return {};
+ return std::basic_string<char, traits_type, A>(data_, size_);
+ }
+
std::string as_string() const {
return std::string(data_, size_);
}
diff --git a/re2/testing/search_test.cc b/re2/testing/search_test.cc
index 144233e..a67b468 100644
--- a/re2/testing/search_test.cc
+++ b/re2/testing/search_test.cc
@@ -321,8 +321,8 @@
// Build a dummy ExhaustiveTest call that will trigger just
// this one test, so that we log the test case.
std::vector<string> atom, alpha, ops;
- atom.push_back(StringPiece(t.regexp).ToString());
- alpha.push_back(StringPiece(t.text).ToString());
+ atom.push_back(t.regexp);
+ alpha.push_back(t.text);
ExhaustiveTest(1, 0, atom, ops, 1, alpha, "", "");
}
}
diff --git a/re2/testing/string_generator_test.cc b/re2/testing/string_generator_test.cc
index 1f10a80..2c040a3 100644
--- a/re2/testing/string_generator_test.cc
+++ b/re2/testing/string_generator_test.cc
@@ -47,7 +47,7 @@
}
while (g.HasNext()) {
- string s = g.Next().ToString();
+ string s = string(g.Next());
n++;
// Check that all characters in s appear in alphabet.
diff --git a/re2/testing/tester.cc b/re2/testing/tester.cc
index 6e4807d..f85f791 100644
--- a/re2/testing/tester.cc
+++ b/re2/testing/tester.cc
@@ -220,7 +220,7 @@
}
// Create re string that will be used for RE and RE2.
- string re = regexp_str.ToString();
+ string re = string(regexp_str);
// Accomodate flags.
// Regexp::Latin1 will be accomodated below.
if (!(flags & Regexp::OneLine))