Get rid of `using std::string;`. (part 2 of N)

Change-Id: I3451b06b238ad93eefc1e2b387351ec6f0ff792d
Reviewed-on: https://code-review.googlesource.com/c/re2/+/39112
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/util/flags.h b/util/flags.h
index 5af1320..e0f1f42 100644
--- a/util/flags.h
+++ b/util/flags.h
@@ -20,10 +20,10 @@
 
 #define DEFINE_bool(name, deflt, desc) DEFINE_flag(bool, name, deflt, desc)
 #define DEFINE_int32(name, deflt, desc) DEFINE_flag(int32_t, name, deflt, desc)
-#define DEFINE_string(name, deflt, desc) DEFINE_flag(string, name, deflt, desc)
+#define DEFINE_string(name, deflt, desc) DEFINE_flag(std::string, name, deflt, desc)
 
 #define DECLARE_bool(name) DECLARE_flag(bool, name)
 #define DECLARE_int32(name) DECLARE_flag(int32_t, name)
-#define DECLARE_string(name) DECLARE_flag(string, name)
+#define DECLARE_string(name) DECLARE_flag(std::string, name)
 
 #endif  // UTIL_FLAGS_H_
diff --git a/util/logging.h b/util/logging.h
index c78f6c1..5b2217f 100644
--- a/util/logging.h
+++ b/util/logging.h
@@ -62,7 +62,7 @@
   }
   void Flush() {
     stream() << "\n";
-    string s = str_.str();
+    std::string s = str_.str();
     size_t n = s.size();
     if (fwrite(s.data(), 1, n, stderr) < n) {}  // shut up gcc
     flushed_ = true;
diff --git a/util/pcre.cc b/util/pcre.cc
index 78de292..93ac90c 100644
--- a/util/pcre.cc
+++ b/util/pcre.cc
@@ -99,7 +99,7 @@
 const PCRE::FindAndConsumeFunctor PCRE::FindAndConsume = { };
 
 // If a regular expression has no error, its error_ field points here
-static const string empty_string;
+static const std::string empty_string;
 
 void PCRE::Init(const char* pattern, Option options, int match_limit,
               int stack_limit, bool report_errors) {
@@ -114,7 +114,7 @@
   re_partial_ = NULL;
 
   if (options & ~(EnabledCompileOptions | EnabledExecOptions)) {
-    error_ = new string("illegal regexp option");
+    error_ = new std::string("illegal regexp option");
     PCREPORT(ERROR)
         << "Error compiling '" << pattern << "': illegal regexp option";
   } else {
@@ -131,13 +131,13 @@
 PCRE::PCRE(const char* pattern, Option option) {
   Init(pattern, option, 0, 0, true);
 }
-PCRE::PCRE(const string& pattern) {
+PCRE::PCRE(const std::string& pattern) {
   Init(pattern.c_str(), None, 0, 0, true);
 }
-PCRE::PCRE(const string& pattern, Option option) {
+PCRE::PCRE(const std::string& pattern, Option option) {
   Init(pattern.c_str(), option, 0, 0, true);
 }
-PCRE::PCRE(const string& pattern, const PCRE_Options& re_option) {
+PCRE::PCRE(const std::string& pattern, const PCRE_Options& re_option) {
   Init(pattern.c_str(), re_option.option(), re_option.match_limit(),
        re_option.stack_limit(), re_option.report_errors());
 }
@@ -176,7 +176,7 @@
   } else {
     // Tack a '\z' at the end of PCRE.  Parenthesize it first so that
     // the '\z' applies to all top-level alternatives in the regexp.
-    string wrapped = "(?:";  // A non-counting grouping operator
+    std::string wrapped = "(?:";  // A non-counting grouping operator
     wrapped += pattern_;
     wrapped += ")\\z";
     re = pcre_compile(wrapped.c_str(),
@@ -184,7 +184,7 @@
                       &error, &eoffset, NULL);
   }
   if (re == NULL) {
-    if (error_ == &empty_string) error_ = new string(error);
+    if (error_ == &empty_string) error_ = new std::string(error);
     PCREPORT(ERROR) << "Error compiling '" << pattern_ << "': " << error;
   }
   return re;
@@ -376,7 +376,7 @@
   }
 }
 
-bool PCRE::Replace(string *str,
+bool PCRE::Replace(std::string *str,
                  const PCRE& pattern,
                  const StringPiece& rewrite) {
   int vec[kVecSize] = {};
@@ -384,7 +384,7 @@
   if (matches == 0)
     return false;
 
-  string s;
+  std::string s;
   if (!pattern.Rewrite(&s, rewrite, *str, vec, matches))
     return false;
 
@@ -394,12 +394,12 @@
   return true;
 }
 
-int PCRE::GlobalReplace(string *str,
+int PCRE::GlobalReplace(std::string *str,
                       const PCRE& pattern,
                       const StringPiece& rewrite) {
   int count = 0;
   int vec[kVecSize] = {};
-  string out;
+  std::string out;
   size_t start = 0;
   bool last_match_was_empty_string = false;
 
@@ -455,7 +455,7 @@
 bool PCRE::Extract(const StringPiece &text,
                  const PCRE& pattern,
                  const StringPiece &rewrite,
-                 string *out) {
+                 std::string *out) {
   int vec[kVecSize] = {};
   int matches = pattern.TryMatch(text, 0, UNANCHORED, true, vec, kVecSize);
   if (matches == 0)
@@ -464,8 +464,8 @@
   return pattern.Rewrite(out, rewrite, text, vec, matches);
 }
 
-string PCRE::QuoteMeta(const StringPiece& unquoted) {
-  string result;
+std::string PCRE::QuoteMeta(const StringPiece& unquoted) {
+  std::string result;
   result.reserve(unquoted.size() << 1);
 
   // Escape any ascii character not in [A-Za-z_0-9].
@@ -669,7 +669,7 @@
   return b;
 }
 
-bool PCRE::Rewrite(string *out, const StringPiece &rewrite,
+bool PCRE::Rewrite(std::string *out, const StringPiece &rewrite,
                  const StringPiece &text, int *vec, int veclen) const {
   int number_of_capturing_groups = NumberOfCapturingGroups();
   for (const char *s = rewrite.data(), *end = s + rewrite.size();
@@ -705,7 +705,8 @@
   return true;
 }
 
-bool PCRE::CheckRewriteString(const StringPiece& rewrite, string* error) const {
+bool PCRE::CheckRewriteString(const StringPiece& rewrite,
+                              std::string* error) const {
   int max_token = -1;
   for (const char *s = rewrite.data(), *end = s + rewrite.size();
        s < end; s++) {
@@ -769,7 +770,7 @@
 
 bool PCRE::Arg::parse_string(const char* str, size_t n, void* dest) {
   if (dest == NULL) return true;
-  reinterpret_cast<string*>(dest)->assign(str, n);
+  reinterpret_cast<std::string*>(dest)->assign(str, n);
   return true;
 }
 
diff --git a/util/pcre.h b/util/pcre.h
index 10ec4f2..644dce6 100644
--- a/util/pcre.h
+++ b/util/pcre.h
@@ -67,7 +67,7 @@
 //
 // Example: extracts "ruby" into "s" and 1234 into "i"
 //    int i;
-//    string s;
+//    std::string s;
 //    CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i));
 //
 // Example: fails because string cannot be stored in integer
@@ -124,10 +124,10 @@
 // which represents a sub-range of a real string.
 //
 // Example: read lines of the form "var = value" from a string.
-//      string contents = ...;          // Fill string somehow
+//      std::string contents = ...;     // Fill string somehow
 //      StringPiece input(contents);    // Wrap a StringPiece around it
 //
-//      string var;
+//      std::string var;
 //      int value;
 //      while (PCRE::Consume(&input, "(\\w+) = (\\d+)\n", &var, &value)) {
 //        ...;
@@ -212,21 +212,21 @@
   // pass in a string or a "const char*" wherever an "PCRE" is expected.
   PCRE(const char* pattern);
   PCRE(const char* pattern, Option option);
-  PCRE(const string& pattern);
-  PCRE(const string& pattern, Option option);
+  PCRE(const std::string& pattern);
+  PCRE(const std::string& pattern, Option option);
   PCRE(const char *pattern, const PCRE_Options& re_option);
-  PCRE(const string& pattern, const PCRE_Options& re_option);
+  PCRE(const std::string& pattern, const PCRE_Options& re_option);
 
   ~PCRE();
 
   // The string specification for this PCRE.  E.g.
   //   PCRE re("ab*c?d+");
   //   re.pattern();    // "ab*c?d+"
-  const string& pattern() const { return pattern_; }
+  const std::string& pattern() const { return pattern_; }
 
   // If PCRE could not be created properly, returns an error string.
   // Else returns the empty string.
-  const string& error() const { return *error_; }
+  const std::string& error() const { return *error_; }
 
   // Whether the PCRE has hit a match limit during execution.
   // Not thread safe.  Intended only for testing.
@@ -241,12 +241,12 @@
   // Matches "text" against "pattern".  If pointer arguments are
   // supplied, copies matched sub-patterns into them.
   //
-  // You can pass in a "const char*" or a "string" for "text".
-  // You can pass in a "const char*" or a "string" or a "PCRE" for "pattern".
+  // You can pass in a "const char*" or a "std::string" for "text".
+  // You can pass in a "const char*" or a "std::string" or a "PCRE" for "pattern".
   //
   // The provided pointer arguments can be pointers to any scalar numeric
   // type, or one of:
-  //    string          (matched piece is copied to string)
+  //    std::string     (matched piece is copied to string)
   //    StringPiece     (StringPiece is mutated to point to matched piece)
   //    T               (where "bool T::ParseFrom(const char*, size_t)" exists)
   //    (void*)NULL     (the corresponding matched sub-pattern is not copied)
@@ -369,14 +369,14 @@
   // from the pattern.  \0 in "rewrite" refers to the entire matching
   // text.  E.g.,
   //
-  //   string s = "yabba dabba doo";
+  //   std::string s = "yabba dabba doo";
   //   CHECK(PCRE::Replace(&s, "b+", "d"));
   //
   // will leave "s" containing "yada dabba doo"
   //
   // Returns true if the pattern matches and a replacement occurs,
   // false otherwise.
-  static bool Replace(string *str,
+  static bool Replace(std::string *str,
                       const PCRE& pattern,
                       const StringPiece& rewrite);
 
@@ -384,13 +384,13 @@
   // the string with the rewrite.  Replacements are not subject to
   // re-matching.  E.g.,
   //
-  //   string s = "yabba dabba doo";
+  //   std::string s = "yabba dabba doo";
   //   CHECK(PCRE::GlobalReplace(&s, "b+", "d"));
   //
   // will leave "s" containing "yada dada doo"
   //
   // Returns the number of replacements made.
-  static int GlobalReplace(string *str,
+  static int GlobalReplace(std::string *str,
                            const PCRE& pattern,
                            const StringPiece& rewrite);
 
@@ -403,7 +403,7 @@
   static bool Extract(const StringPiece &text,
                       const PCRE& pattern,
                       const StringPiece &rewrite,
-                      string *out);
+                      std::string *out);
 
   // Check that the given @p rewrite string is suitable for use with
   // this PCRE.  It checks that:
@@ -418,7 +418,8 @@
   // @param error An error message is recorded here, iff we return false.
   //              Otherwise, it is unchanged.
   // @return true, iff @p rewrite is suitable for use with the PCRE.
-  bool CheckRewriteString(const StringPiece& rewrite, string* error) const;
+  bool CheckRewriteString(const StringPiece& rewrite,
+                          std::string* error) const;
 
   // Returns a copy of 'unquoted' with all potentially meaningful
   // regexp characters backslash-escaped.  The returned string, used
@@ -427,7 +428,7 @@
   //           1.5-2.0?
   //  becomes:
   //           1\.5\-2\.0\?
-  static string QuoteMeta(const StringPiece& unquoted);
+  static std::string QuoteMeta(const StringPiece& unquoted);
 
   /***** Generic matching interface (not so nice to use) *****/
 
@@ -473,7 +474,7 @@
 
   // Append the "rewrite" string, with backslash subsitutions from "text"
   // and "vec", to string "out".
-  bool Rewrite(string *out,
+  bool Rewrite(std::string *out,
                const StringPiece &rewrite,
                const StringPiece &text,
                int *vec,
@@ -491,15 +492,15 @@
   // Compile the regexp for the specified anchoring mode
   pcre* Compile(Anchor anchor);
 
-  string            pattern_;
-  Option            options_;
-  pcre*             re_full_;        // For full matches
-  pcre*             re_partial_;     // For partial matches
-  const string*     error_;          // Error indicator (or empty string)
-  bool              report_errors_;  // Silences error logging if false
-  int               match_limit_;    // Limit on execution resources
-  int               stack_limit_;    // Limit on stack resources (bytes)
-  mutable int32_t   hit_limit_;  // Hit limit during execution (bool)?
+  std::string         pattern_;
+  Option              options_;
+  pcre*               re_full_;        // For full matches
+  pcre*               re_partial_;     // For partial matches
+  const std::string*  error_;          // Error indicator (or empty string)
+  bool                report_errors_;  // Silences error logging if false
+  int                 match_limit_;    // Limit on execution resources
+  int                 stack_limit_;    // Limit on stack resources (bytes)
+  mutable int32_t     hit_limit_;      // Hit limit during execution (bool)
 
   PCRE(const PCRE&) = delete;
   PCRE& operator=(const PCRE&) = delete;
@@ -584,7 +585,7 @@
   MAKE_PARSER(unsigned char,      parse_uchar);
   MAKE_PARSER(float,              parse_float);
   MAKE_PARSER(double,             parse_double);
-  MAKE_PARSER(string,             parse_string);
+  MAKE_PARSER(std::string,        parse_string);
   MAKE_PARSER(StringPiece,        parse_stringpiece);
 
   MAKE_PARSER(short,              parse_short);
diff --git a/util/strutil.cc b/util/strutil.cc
index 8eabfa4..cc3b857 100644
--- a/util/strutil.cc
+++ b/util/strutil.cc
@@ -65,17 +65,17 @@
 //    Copies 'src' to result, escaping dangerous characters using
 //    C-style escape sequences.  'src' and 'dest' should not overlap.
 // ----------------------------------------------------------------------
-string CEscape(const StringPiece& src) {
+std::string CEscape(const StringPiece& src) {
   const size_t dest_len = src.size() * 4 + 1; // Maximum possible expansion
   char* dest = new char[dest_len];
   const size_t used = CEscapeString(src.data(), src.size(),
                                     dest, dest_len);
-  string s = string(dest, used);
+  std::string s = std::string(dest, used);
   delete[] dest;
   return s;
 }
 
-void PrefixSuccessor(string* prefix) {
+void PrefixSuccessor(std::string* prefix) {
   // We can increment the last character in the string and be done
   // unless that character is 255, in which case we have to erase the
   // last character and increment the previous character, unless that
@@ -92,7 +92,7 @@
   }
 }
 
-static void StringAppendV(string* dst, const char* format, va_list ap) {
+static void StringAppendV(std::string* dst, const char* format, va_list ap) {
   // First try with a small fixed size buffer
   char space[1024];
 
@@ -137,16 +137,16 @@
   }
 }
 
-string StringPrintf(const char* format, ...) {
+std::string StringPrintf(const char* format, ...) {
   va_list ap;
   va_start(ap, format);
-  string result;
+  std::string result;
   StringAppendV(&result, format, ap);
   va_end(ap);
   return result;
 }
 
-void SStringPrintf(string* dst, const char* format, ...) {
+void SStringPrintf(std::string* dst, const char* format, ...) {
   va_list ap;
   va_start(ap, format);
   dst->clear();
@@ -154,7 +154,7 @@
   va_end(ap);
 }
 
-void StringAppendF(string* dst, const char* format, ...) {
+void StringAppendF(std::string* dst, const char* format, ...) {
   va_list ap;
   va_start(ap, format);
   StringAppendV(dst, format, ap);
diff --git a/util/strutil.h b/util/strutil.h
index 2c3c104..b16981e 100644
--- a/util/strutil.h
+++ b/util/strutil.h
@@ -12,11 +12,11 @@
 
 namespace re2 {
 
-string CEscape(const StringPiece& src);
-void PrefixSuccessor(string* prefix);
-string StringPrintf(const char* format, ...);
-void SStringPrintf(string* dst, const char* format, ...);
-void StringAppendF(string* dst, const char* format, ...);
+std::string CEscape(const StringPiece& src);
+void PrefixSuccessor(std::string* prefix);
+std::string StringPrintf(const char* format, ...);
+void SStringPrintf(std::string* dst, const char* format, ...);
+void StringAppendF(std::string* dst, const char* format, ...);
 
 }  // namespace re2