cpp: header hygienization

* remove "using std::" declarations from header files
* add missing "std::" to some string declarations at some header files
* add "using std::string;" to some source files where necessary

--
Change-Id: Ib64f62b5add499d6171fa922227194ac992fa542
Reviewed-on: https://bazel-review.googlesource.com/#/c/6630/
MOS_MIGRATED_REVID=136355671
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index c14206d..b4899db 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -84,12 +84,9 @@
 
 #include "src/main/protobuf/command_server.grpc.pb.h"
 
-
 using blaze_util::Md5Digest;
 using blaze_util::die;
 using blaze_util::pdie;
-using std::set;
-using std::vector;
 
 // This should already be defined in sched.h, but it's not.
 #ifndef SCHED_BATCH
@@ -98,6 +95,10 @@
 
 namespace blaze {
 
+using std::set;
+using std::string;
+using std::vector;
+
 static void WriteFileToStreamOrDie(FILE *stream, const char *file_name);
 static string BuildServerRequest();
 static int GetServerPid(const string &server_dir);
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 648c0d4..7990286 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -41,10 +41,12 @@
 
 using blaze_util::die;
 using blaze_util::pdie;
-using std::vector;
 
 namespace blaze {
 
+using std::string;
+using std::vector;
+
 const char kServerPidFile[] = "server.pid.txt";
 const char kServerPidSymlink[] = "server.pid";
 
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 5fe17ae..06e9c9b 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -27,12 +27,10 @@
 
 namespace blaze {
 
-using std::string;
-
 extern const char kServerPidFile[];
 extern const char kServerPidSymlink[];
 
-string GetUserName();
+std::string GetUserName();
 
 // Returns the given path in absolute form.  Does not change paths that are
 // already absolute.
@@ -41,27 +39,27 @@
 //   MakeAbsolute("foo") --> "/bar/foo"
 //   MakeAbsolute("/foo") ---> "/foo"
 //   MakeAbsolute("C:/foo") ---> "C:/foo"
-string MakeAbsolute(const string &path);
+std::string MakeAbsolute(const std::string &path);
 
 // mkdir -p path. All newly created directories use the given mode.
 // Returns -1 on failure, sets errno.
-int MakeDirectories(const string &path, mode_t mode);
+int MakeDirectories(const std::string &path, mode_t mode);
 
 // Replaces 'content' with contents of file 'filename'.
 // Returns false on error. Can be called from a signal handler.
-bool ReadFile(const string &filename, string *content);
+bool ReadFile(const std::string &filename, std::string *content);
 
 // Replaces 'content' with contents of file descriptor 'fd'.
 // Returns false on error. Can be called from a signal handler.
-bool ReadFileDescriptor(int fd, string *content);
+bool ReadFileDescriptor(int fd, std::string *content);
 
 // Writes 'content' into file 'filename', and makes it executable.
 // Returns false on failure, sets errno.
-bool WriteFile(const string &content, const string &filename);
+bool WriteFile(const std::string &content, const std::string &filename);
 
 // Unlinks the file given by 'file_path'.
 // Returns true on success. In case of failure sets errno.
-bool UnlinkPath(const string &file_path);
+bool UnlinkPath(const std::string &file_path);
 
 // Returns true iff the current terminal is running inside an Emacs.
 bool IsEmacsTerminal();
@@ -92,27 +90,27 @@
 // "java -version" execution and is supposed to contain a string of the form
 // 'version "version-number"' in the first 255 bytes. If the string is found,
 // version-number is returned, else the empty string is returned.
-string ReadJvmVersion(const string& version_string);
+std::string ReadJvmVersion(const std::string &version_string);
 
 // Get the version string from the given java executable. The java executable
 // is supposed to output a string in the form '.*version ".*".*'. This method
 // will return the part in between the two quote or the empty string on failure
 // to match the good string.
-string GetJvmVersion(const string &java_exe);
+std::string GetJvmVersion(const std::string &java_exe);
 
 // Returns true iff jvm_version is at least the version specified by
 // version_spec.
 // jvm_version is supposed to be a string specifying a java runtime version
 // as specified by the JSR-56 appendix A. version_spec is supposed to be a
 // version is the format [0-9]+(.[1-9]+)*.
-bool CheckJavaVersionIsAtLeast(const string &jvm_version,
-                               const string &version_spec);
+bool CheckJavaVersionIsAtLeast(const std::string &jvm_version,
+                               const std::string &version_spec);
 
 // Converts a project identifier to string.
 // Workaround for mingw where std::to_string is not implemented.
 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015.
 template <typename T>
-string ToString(const T& value) {
+std::string ToString(const T &value) {
   std::ostringstream oss;
   oss << value;
   return oss.str();
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index 3f4c880..0c47920 100644
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -54,7 +54,8 @@
 // Replace the current process with the given program in the current working
 // directory, using the given argument vector.
 // This function does not return on success.
-void ExecuteProgram(const string& exe, const std::vector<string>& args_vector);
+void ExecuteProgram(const std::string& exe,
+                    const std::vector<std::string>& args_vector);
 
 class BlazeServerStartup {
  public:
@@ -67,13 +68,16 @@
 // that can be used to query if the server is still alive. The PID of the
 // daemon started is written into server_dir, both as a symlink (for legacy
 // reasons) and as a file.
-void ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
-                   const string& daemon_output, const string& server_dir,
+void ExecuteDaemon(const std::string& exe,
+                   const std::vector<std::string>& args_vector,
+                   const std::string& daemon_output,
+                   const std::string& server_dir,
                    BlazeServerStartup** server_startup);
 
 // Executes a subprocess and returns its standard output and standard error.
 // If this fails, exits with the appropriate error code.
-string RunProgram(const string& exe, const std::vector<string>& args_vector);
+std::string RunProgram(const std::string& exe,
+                       const std::vector<std::string>& args_vector);
 
 // Convert a path from Bazel internal form to underlying OS form.
 // On Unixes this is an identity operation.
@@ -93,18 +97,18 @@
 // Create a symlink to directory ``target`` at location ``link``.
 // Returns true on success, false on failure. The target must be absolute.
 // Implemented via junctions on Windows.
-bool SymlinkDirectories(const string &target, const string &link);
+bool SymlinkDirectories(const std::string& target, const std::string& link);
 
 // Reads which directory a symlink points to. Puts the target of the symlink
 // in ``result`` and returns if the operation was successful. Will not work on
 // symlinks that don't point to directories on Windows.
-bool ReadDirectorySymlink(const string &symlink, string *result);
+bool ReadDirectorySymlink(const std::string& symlink, std::string* result);
 
 // Compares two absolute paths. Necessary because the same path can have
 // multiple different names under msys2: "C:\foo\bar" or "C:/foo/bar"
 // (Windows-style) and "/c/foo/bar" (msys2 style). Returns if the paths are
 // equal.
-bool CompareAbsolutePaths(const string& a, const string& b);
+bool CompareAbsolutePaths(const std::string& a, const std::string& b);
 
 struct BlazeLock {
   int lockfd;
@@ -113,7 +117,7 @@
 // Acquires a lock on the output base. Exits if the lock cannot be acquired.
 // Sets ``lock`` to a value that can subsequently be passed to ReleaseLock().
 // Returns the number of milliseconds spent with waiting for the lock.
-uint64_t AcquireLock(const string& output_base, bool batch_mode,
+uint64_t AcquireLock(const std::string& output_base, bool batch_mode,
                      bool block, BlazeLock* blaze_lock);
 
 // Releases the lock on the output base. In case of an error, continues as
@@ -121,8 +125,8 @@
 void ReleaseLock(BlazeLock* blaze_lock);
 
 // Verifies whether the server process still exists. Returns true if it does.
-bool VerifyServerProcess(
-    int pid, const string& output_base, const string& install_base);
+bool VerifyServerProcess(int pid, const std::string& output_base,
+                         const std::string& install_base);
 
 // Kills a server process based on its PID. Returns true if the
 // server process was found and killed. This function can be called from a
@@ -130,7 +134,7 @@
 bool KillServerProcess(int pid);
 
 // Mark path as being excluded from backups (if supported by operating system).
-void ExcludePathFromBackup(const string &path);
+void ExcludePathFromBackup(const std::string& path);
 
 }  // namespace blaze
 
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index bb56efc..1cd1d81 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -29,16 +29,17 @@
 #include "src/main/cpp/util/strings.h"
 #include "src/main/cpp/workspace_layout.h"
 
-using std::list;
-using std::map;
-using std::set;
-using std::vector;
-
 // On OSX, there apparently is no header that defines this.
 extern char **environ;
 
 namespace blaze {
 
+using std::list;
+using std::map;
+using std::set;
+using std::string;
+using std::vector;
+
 constexpr char WorkspaceLayout::WorkspacePrefix[];
 
 OptionProcessor::RcOption::RcOption(int rcfile_index, const string& option)
diff --git a/src/main/cpp/option_processor.h b/src/main/cpp/option_processor.h
index bb777e9..472414d 100644
--- a/src/main/cpp/option_processor.h
+++ b/src/main/cpp/option_processor.h
@@ -26,8 +26,6 @@
 
 namespace blaze {
 
-using std::string;
-
 // This class is responsible for parsing the command line of the Blaze binary,
 // parsing blazerc files, and putting together the command that should be sent
 // to the server.
@@ -39,81 +37,76 @@
 
   // Parse a command line and the appropriate blazerc files. This should be
   // invoked only once per OptionProcessor object.
-  blaze_exit_code::ExitCode ParseOptions(const std::vector<string>& args,
-                                         const string& workspace,
-                                         const string& cwd,
-                                         string* error);
+  blaze_exit_code::ExitCode ParseOptions(const std::vector<std::string>& args,
+                                         const std::string& workspace,
+                                         const std::string& cwd,
+                                         std::string* error);
 
   blaze_exit_code::ExitCode ParseOptions(int argc, const char* argv[],
-                                         const string& workspace,
-                                         const string& cwd,
-                                         string* error);
+                                         const std::string& workspace,
+                                         const std::string& cwd,
+                                         std::string* error);
 
   // Get the Blaze command to be executed.
   // Returns an empty string if no command was found on the command line.
-  const string& GetCommand() const;
+  const std::string& GetCommand() const;
 
   // Gets the arguments to the command. This is put together from the default
   // options specified in the blazerc file(s), the command line, and various
   // bits and pieces of information about the environment the blaze binary is
   // executed in.
-  void GetCommandArguments(std::vector<string>* result) const;
+  void GetCommandArguments(std::vector<std::string>* result) const;
 
   StartupOptions* GetParsedStartupOptions() const;
 
-  virtual blaze_exit_code::ExitCode FindUserBlazerc(const char* cmdLineRcFile,
-                                                    const string& rc_basename,
-                                                    const string& workspace,
-                                                    string* user_blazerc_file,
-                                                    string* error);
+  virtual blaze_exit_code::ExitCode FindUserBlazerc(
+      const char* cmdLineRcFile, const std::string& rc_basename,
+      const std::string& workspace, std::string* user_blazerc_file,
+      std::string* error);
 
  private:
   class RcOption {
    public:
-    RcOption(int rcfile_index, const string& option);
+    RcOption(int rcfile_index, const std::string& option);
 
     const int rcfile_index() const { return rcfile_index_; }
-    const string& option() const { return option_; }
+    const std::string& option() const { return option_; }
 
    private:
     int rcfile_index_;
-    string option_;
+    std::string option_;
   };
 
   class RcFile {
    public:
-    RcFile(const string& filename, int index);
+    RcFile(const std::string& filename, int index);
     blaze_exit_code::ExitCode Parse(
-        const string& workspace,
-        std::vector<RcFile*>* rcfiles,
-        std::map<string, std::vector<RcOption> >* rcoptions,
-        string* error);
-    const string& Filename() const { return filename_; }
+        const std::string& workspace, std::vector<RcFile*>* rcfiles,
+        std::map<std::string, std::vector<RcOption> >* rcoptions,
+        std::string* error);
+    const std::string& Filename() const { return filename_; }
     const int Index() const { return index_; }
 
    private:
-    static blaze_exit_code::ExitCode Parse(const string& workspace,
-                                           const string& filename,
-                                           const int index,
-                                           std::vector<RcFile*>* rcfiles,
-                                           std::map<string,
-                                           std::vector<RcOption> >* rcoptions,
-                                           std::list<string>* import_stack,
-                                           string* error);
+    static blaze_exit_code::ExitCode Parse(
+        const std::string& workspace, const std::string& filename,
+        const int index, std::vector<RcFile*>* rcfiles,
+        std::map<std::string, std::vector<RcOption> >* rcoptions,
+        std::list<std::string>* import_stack, std::string* error);
 
-    string filename_;
+    std::string filename_;
     int index_;
   };
 
-  void AddRcfileArgsAndOptions(bool batch, const string& cwd);
-  blaze_exit_code::ExitCode ParseStartupOptions(string *error);
+  void AddRcfileArgsAndOptions(bool batch, const std::string& cwd);
+  blaze_exit_code::ExitCode ParseStartupOptions(std::string* error);
 
   std::vector<RcFile*> blazercs_;
-  std::map<string, std::vector<RcOption> > rcoptions_;
-  std::vector<string> args_;
+  std::map<std::string, std::vector<RcOption> > rcoptions_;
+  std::vector<std::string> args_;
   unsigned int startup_args_;
-  string command_;
-  std::vector<string> command_arguments_;
+  std::string command_;
+  std::vector<std::string> command_arguments_;
   bool initialized_;
   std::unique_ptr<StartupOptions> parsed_startup_options_;
 };
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index 85ec97c..06b941d 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -31,6 +31,7 @@
 
 namespace blaze {
 
+using std::string;
 using std::vector;
 
 StartupOptions::StartupOptions() : StartupOptions("Bazel") {}
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index b7b4c3f..7754dad 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -23,8 +23,6 @@
 
 namespace blaze {
 
-using std::string;
-
 // This class holds the parsed startup options for Blaze.
 // These options and their defaults must be kept in sync with those in
 // src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java.
@@ -55,22 +53,24 @@
   // Returns the exit code after processing the argument. "error" will contain
   // a descriptive string for any return value other than
   // blaze_exit_code::SUCCESS.
-  blaze_exit_code::ExitCode ProcessArg(
-      const string &arg, const string &next_arg, const string &rcfile,
-      bool *is_space_separated, string *error);
+  blaze_exit_code::ExitCode ProcessArg(const std::string &arg,
+                                       const std::string &next_arg,
+                                       const std::string &rcfile,
+                                       bool *is_space_separated,
+                                       std::string *error);
 
   // Adds any other options needed to result.
   //
   // TODO(jmmv): Now that we support site-specific options via subclasses of
   // StartupOptions, the "ExtraOptions" concept makes no sense; remove it.
-  virtual void AddExtraOptions(std::vector<string> *result) const;
+  virtual void AddExtraOptions(std::vector<std::string> *result) const;
 
   // Checks if Blaze needs to be re-executed.  Does not return, if so.
   //
   // Returns the exit code after the check. "error" will contain a descriptive
   // string for any return value other than blaze_exit_code::SUCCESS.
   virtual blaze_exit_code::ExitCode CheckForReExecuteOptions(
-      int argc, const char *argv[], string *error);
+      int argc, const char *argv[], std::string *error);
 
   // Checks extra fields when processing arg.
   //
@@ -81,57 +81,59 @@
   // TODO(jmmv): Now that we support site-specific options via subclasses of
   // StartupOptions, the "ExtraOptions" concept makes no sense; remove it.
   virtual blaze_exit_code::ExitCode ProcessArgExtra(
-    const char *arg, const char *next_arg, const string &rcfile,
-    const char **value, bool *is_processed, string *error);
+      const char *arg, const char *next_arg, const std::string &rcfile,
+      const char **value, bool *is_processed, std::string *error);
 
   // Return the default path to the JDK used to run Blaze itself
   // (must be an absolute directory).
-  virtual string GetDefaultHostJavabase() const;
+  virtual std::string GetDefaultHostJavabase() const;
 
   // Returns the path to the JVM. This should be called after parsing
   // the startup options.
-  virtual string GetJvm();
+  virtual std::string GetJvm();
 
   // Returns the executable used to start the Blaze server, typically the given
   // JVM.
-  virtual string GetExe(const string &jvm, const string &jar_path);
+  virtual std::string GetExe(const std::string &jvm,
+                             const std::string &jar_path);
 
   // Adds JVM prefix flags to be set. These will be added before all other
   // JVM flags.
-  virtual void AddJVMArgumentPrefix(const string &javabase,
-    std::vector<string> *result) const;
+  virtual void AddJVMArgumentPrefix(const std::string &javabase,
+                                    std::vector<std::string> *result) const;
 
   // Adds JVM suffix flags. These will be added after all other JVM flags, and
   // just before the Blaze server startup flags.
-  virtual void AddJVMArgumentSuffix(const string &real_install_dir,
-    const string &jar_path, std::vector<string> *result) const;
+  virtual void AddJVMArgumentSuffix(const std::string &real_install_dir,
+                                    const std::string &jar_path,
+                                    std::vector<std::string> *result) const;
 
   // Adds JVM tuning flags for Blaze.
   //
   // Returns the exit code after this operation. "error" will be set to a
   // descriptive string for any value other than blaze_exit_code::SUCCESS.
   virtual blaze_exit_code::ExitCode AddJVMArguments(
-    const string &host_javabase, std::vector<string> *result,
-    const std::vector<string> &user_options, string *error) const;
+      const std::string &host_javabase, std::vector<std::string> *result,
+      const std::vector<std::string> &user_options, std::string *error) const;
 
   // The capitalized name of this binary.
-  const string product_name;
+  const std::string product_name;
 
   // Blaze's output base.  Everything is relative to this.  See
   // the BlazeDirectories Java class for details.
-  string output_base;
+  std::string output_base;
 
   // Installation base for a specific release installation.
-  string install_base;
+  std::string install_base;
 
   // The toplevel directory containing Blaze's output.  When Blaze is
   // run by a test, we use TEST_TMPDIR, simplifying the correct
   // hermetic invocation of Blaze from tests.
-  string output_root;
+  std::string output_root;
 
   // Blaze's output_user_root. Used only for computing install_base and
   // output_base.
-  string output_user_root;
+  std::string output_user_root;
 
   // Whether to put the execroot at $OUTPUT_BASE/$WORKSPACE_NAME (if false) or
   // $OUTPUT_BASE/execroot/$WORKSPACE_NAME (if true).
@@ -144,9 +146,9 @@
 
   bool host_jvm_debug;
 
-  string host_jvm_profile;
+  std::string host_jvm_profile;
 
-  std::vector<string> host_jvm_args;
+  std::vector<std::string> host_jvm_args;
 
   bool batch;
 
@@ -182,31 +184,31 @@
   // A string to string map specifying where each option comes from. If the
   // value is empty, it was on the command line, if it is a string, it comes
   // from a blazerc file, if a key is not present, it is the default.
-  std::map<string, string> option_sources;
+  std::map<std::string, std::string> option_sources;
 
   // Sanity check for the startup options
   virtual blaze_exit_code::ExitCode ValidateStartupOptions(
-      const std::vector<string>& args, string* error);
+      const std::vector<std::string> &args, std::string *error);
 
   // Returns the GetHostJavabase. This should be called after parsing
   // the --host_javabase option.
-  string GetHostJavabase();
+  std::string GetHostJavabase();
 
   // Port for gRPC command server. 0 means let the kernel choose, -1 means no
   // gRPC command server.
   int command_port;
 
   // Invocation policy proto. May be NULL.
-  const char* invocation_policy;
+  const char *invocation_policy;
 
  protected:
   // Constructor for subclasses only so that site-specific extensions of this
   // class can override the product name.  The product_name must be the
   // capitalized version of the name, as in "Bazel".
-  explicit StartupOptions(const string& product_name);
+  explicit StartupOptions(const std::string &product_name);
 
  private:
-  string host_javabase;
+  std::string host_javabase;
 };
 
 }  // namespace blaze
diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc
index f453176..0957a56 100644
--- a/src/main/cpp/util/file.cc
+++ b/src/main/cpp/util/file.cc
@@ -18,14 +18,16 @@
 #include <cstdlib>
 #include <vector>
 
-#include "src/main/cpp/util/exit_code.h"
 #include "src/main/cpp/util/errors.h"
+#include "src/main/cpp/util/exit_code.h"
 #include "src/main/cpp/util/strings.h"
 
 using std::pair;
 
 namespace blaze_util {
 
+using std::string;
+
 pair<string, string> SplitPath(const string &path) {
   size_t pos = path.rfind('/');
 
diff --git a/src/main/cpp/util/file.h b/src/main/cpp/util/file.h
index 6e7707b..238ccf0 100644
--- a/src/main/cpp/util/file.h
+++ b/src/main/cpp/util/file.h
@@ -18,18 +18,16 @@
 
 namespace blaze_util {
 
-using std::string;
-
 // Returns the part of the path before the final "/".  If there is a single
 // leading "/" in the path, the result will be the leading "/".  If there is
 // no "/" in the path, the result is the empty prefix of the input (i.e., "").
-string Dirname(const string &path);
+std::string Dirname(const std::string &path);
 
 // Returns the part of the path after the final "/".  If there is no
 // "/" in the path, the result is the same as the input.
-string Basename(const string &path);
+std::string Basename(const std::string &path);
 
-string JoinPath(const string &path1, const string &path2);
+std::string JoinPath(const std::string &path1, const std::string &path2);
 
 }  // namespace blaze_util
 
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index 51df0dc..ff85e21 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -18,15 +18,16 @@
 #include <unistd.h>  // access
 #include <vector>
 
-#include "src/main/cpp/util/file.h"
-#include "src/main/cpp/util/exit_code.h"
 #include "src/main/cpp/util/errors.h"
+#include "src/main/cpp/util/exit_code.h"
+#include "src/main/cpp/util/file.h"
 #include "src/main/cpp/util/strings.h"
 
-using std::pair;
-
 namespace blaze_util {
 
+using std::pair;
+using std::string;
+
 string Which(const string &executable) {
   char *path_cstr = getenv("PATH");
   if (path_cstr == NULL || path_cstr[0] == '\0') {
diff --git a/src/main/cpp/util/file_posix.h b/src/main/cpp/util/file_posix.h
index 42ced01..1d247bc 100644
--- a/src/main/cpp/util/file_posix.h
+++ b/src/main/cpp/util/file_posix.h
@@ -19,12 +19,10 @@
 
 namespace blaze_util {
 
-using std::string;
-
 // Checks each element of the PATH variable for executable. If none is found, ""
 // is returned.  Otherwise, the full path to executable is returned. Can die if
 // looking up PATH fails.
-string Which(const string &executable);
+std::string Which(const std::string &executable);
 
 }  // namespace blaze_util
 
diff --git a/src/main/cpp/util/md5.cc b/src/main/cpp/util/md5.cc
index d25c292..7703785 100644
--- a/src/main/cpp/util/md5.cc
+++ b/src/main/cpp/util/md5.cc
@@ -57,6 +57,8 @@
 
 namespace blaze_util {
 
+using std::string;
+
 static const unsigned int k8Bytes = 64;
 static const unsigned int k8ByteMask = 63;
 
diff --git a/src/main/cpp/util/md5.h b/src/main/cpp/util/md5.h
index e4c5836..d153a44 100644
--- a/src/main/cpp/util/md5.h
+++ b/src/main/cpp/util/md5.h
@@ -26,8 +26,6 @@
 
 namespace blaze_util {
 
-using std::string;
-
 // The <code>Context</code> class performs the actual MD5
 // computation. It works incrementally and can be fed a single byte at
 // a time if desired.
@@ -55,7 +53,7 @@
 
   // Produces a hexadecimal string representation of this digest in the form:
   // [0-9a-f]{32}
-  string String() const;
+  std::string String() const;
 
  private:
   void Transform(const unsigned char* buffer, unsigned int len);
diff --git a/src/main/cpp/util/numbers.cc b/src/main/cpp/util/numbers.cc
index 46feb81..b0ac398 100644
--- a/src/main/cpp/util/numbers.cc
+++ b/src/main/cpp/util/numbers.cc
@@ -24,6 +24,8 @@
 
 namespace blaze_util {
 
+using std::string;
+
 static const int32_t kint32min = static_cast<int32_t>(~0x7FFFFFFF);
 static const int32_t kint32max = static_cast<int32_t>(0x7FFFFFFF);
 
diff --git a/src/main/cpp/util/numbers.h b/src/main/cpp/util/numbers.h
index 2dca80f..f1ef6f7 100644
--- a/src/main/cpp/util/numbers.h
+++ b/src/main/cpp/util/numbers.h
@@ -18,9 +18,7 @@
 
 namespace blaze_util {
 
-using std::string;
-
-bool safe_strto32(const string &text, int *value);
+bool safe_strto32(const std::string &text, int *value);
 
 int32_t strto32(const char *str, char **endptr, int base);
 
diff --git a/src/main/cpp/util/strings.cc b/src/main/cpp/util/strings.cc
index 3df0b9e..e20bf80 100644
--- a/src/main/cpp/util/strings.cc
+++ b/src/main/cpp/util/strings.cc
@@ -21,10 +21,11 @@
 
 #include "src/main/cpp/util/exit_code.h"
 
-using std::vector;
-
 namespace blaze_util {
 
+using std::string;
+using std::vector;
+
 static const char kSeparator[] = " \n\t\r";
 
 // # Table generated by this Python code (bit 0x02 is currently unused):
diff --git a/src/main/cpp/util/strings.h b/src/main/cpp/util/strings.h
index 0dca219..4724558 100644
--- a/src/main/cpp/util/strings.h
+++ b/src/main/cpp/util/strings.h
@@ -23,16 +23,14 @@
 
 namespace blaze_util {
 
-using std::string;
-
 extern const unsigned char kAsciiPropertyBits[256];
 #define kApb kAsciiPropertyBits
 
 static inline bool ascii_isspace(unsigned char c) { return kApb[c] & 0x08; }
 
-bool starts_with(const string &haystack, const string &needle);
+bool starts_with(const std::string &haystack, const std::string &needle);
 
-bool ends_with(const string &haystack, const string &needle);
+bool ends_with(const std::string &haystack, const std::string &needle);
 
 // Matches a prefix (which must be a char* literal!) against the beginning of
 // str. Returns a pointer past the prefix, or NULL if the prefix wasn't matched.
@@ -41,9 +39,10 @@
 //
 // The ""'s catch people who don't pass in a literal for "prefix"
 #ifndef strprefix
-#define strprefix(str, prefix) \
-  (strncmp(str, prefix, sizeof("" prefix "")-1) == 0 ? \
-      str + sizeof(prefix)-1 : NULL)
+#define strprefix(str, prefix)                         \
+  (strncmp(str, prefix, sizeof("" prefix "") - 1) == 0 \
+       ? str + sizeof(prefix) - 1                      \
+       : NULL)
 #endif
 
 // Matches a prefix; returns a pointer past the prefix, or NULL if not found.
@@ -54,55 +53,57 @@
 // (Like strprefix() and strcaseprefix() but not restricted to searching for
 // char* literals). Templated so searching a const char* returns a const char*,
 // and searching a non-const char* returns a non-const char*.
-template<class CharStar>
-inline CharStar var_strprefix(CharStar str, const char* prefix) {
+template <class CharStar>
+inline CharStar var_strprefix(CharStar str, const char *prefix) {
   const int len = strlen(prefix);
-  return strncmp(str, prefix, len) == 0 ?  str + len : NULL;
+  return strncmp(str, prefix, len) == 0 ? str + len : NULL;
 }
 
 // Returns a mutable char* pointing to a string's internal buffer, which may not
 // be null-terminated. Returns NULL for an empty string. If not non-null,
 // writing through this pointer will modify the string.
-inline char* string_as_array(string* str) {
+inline char *string_as_array(std::string *str) {
   // DO NOT USE const_cast<char*>(str->data())! See the unittest for why.
   return str->empty() ? NULL : &*str->begin();
 }
 
 // Join the elements of pieces separated by delimeter.  Returns the joined
 // string in output.
-void JoinStrings(
-    const std::vector<string> &pieces, const char delimeter, string *output);
+void JoinStrings(const std::vector<std::string> &pieces, const char delimeter,
+                 std::string *output);
 
 // Splits contents by delimeter.  Skips empty subsections.
-std::vector<string> Split(const string &contents, const char delimeter);
+std::vector<std::string> Split(const std::string &contents,
+                               const char delimeter);
 
 // Same as above, but adds results to output.
-void SplitStringUsing(
-    const string &contents, const char delimeter, std::vector<string> *output);
+void SplitStringUsing(const std::string &contents, const char delimeter,
+                      std::vector<std::string> *output);
 
 // Same as above, but adds results to output. Returns number of elements added.
-size_t SplitQuotedStringUsing(const string &contents, const char delimeter,
-                              std::vector<string> *output);
+size_t SplitQuotedStringUsing(const std::string &contents, const char delimeter,
+                              std::vector<std::string> *output);
 
 // Global replace of oldsub with newsub.
-void Replace(const string &oldsub, const string &newsub, string *str);
+void Replace(const std::string &oldsub, const std::string &newsub,
+             std::string *str);
 
 // Removes whitespace from both ends of a string.
-void StripWhitespace(string *str);
+void StripWhitespace(std::string *str);
 
 // Tokenizes str on whitespace and places the tokens in words. Splits on spaces,
 // newlines, carriage returns, and tabs. Respects single and double quotes (that
 // is, "a string of 'some stuff'" would be 4 tokens). If the comment character
 // is found (outside of quotes), the rest of the string will be ignored. Any
 // token can be escaped with \, e.g., "this\\ is\\ one\\ token".
-void Tokenize(
-    const string &str, const char &comment, std::vector<string> *words);
+void Tokenize(const std::string &str, const char &comment,
+              std::vector<std::string> *words);
 
 // Evaluate a format string and store the result in 'str'.
-void StringPrintf(string *str, const char *format, ...);
+void StringPrintf(std::string *str, const char *format, ...);
 
 // Convert str to lower case. No locale handling, this is just for ASCII.
-void ToLower(string* str);
+void ToLower(std::string *str);
 
 }  // namespace blaze_util
 
diff --git a/src/main/cpp/workspace_layout.cc b/src/main/cpp/workspace_layout.cc
index 0a44ee8..d4836b5 100644
--- a/src/main/cpp/workspace_layout.cc
+++ b/src/main/cpp/workspace_layout.cc
@@ -21,6 +21,7 @@
 
 namespace blaze {
 
+using std::string;
 using std::vector;
 
 static const char kWorkspaceMarker[] = "WORKSPACE";
diff --git a/src/main/cpp/workspace_layout.h b/src/main/cpp/workspace_layout.h
index cdcf5a0..62de291 100644
--- a/src/main/cpp/workspace_layout.h
+++ b/src/main/cpp/workspace_layout.h
@@ -19,8 +19,6 @@
 
 namespace blaze {
 
-using std::string;
-
 // Provides methods to compute paths related to the workspace.
 //
 // All methods in this class ought to be static because we reference them as
@@ -34,7 +32,7 @@
   WorkspaceLayout() = delete;
 
   // Returns the directory to use for storing outputs.
-  static string GetOutputRoot();
+  static std::string GetOutputRoot();
 
   // Given the working directory, returns the nearest enclosing directory with a
   // WORKSPACE file in it.  If there is no such enclosing directory, returns "".
@@ -46,30 +44,30 @@
   //
   // The returned path is relative or absolute depending on whether cwd was
   // relative or absolute.
-  static string GetWorkspace(const string &cwd);
+  static std::string GetWorkspace(const std::string& cwd);
 
   // Returns if workspace is a valid build workspace.
-  static bool InWorkspace(const string &workspace);
+  static bool InWorkspace(const std::string& workspace);
 
   // Returns the basename for the rc file.
-  static string RcBasename();
+  static std::string RcBasename();
 
   // Returns the candidate pathnames for the RC files.
-  static void FindCandidateBlazercPaths(const string& workspace,
-                                        const string& cwd,
-                                        const std::vector<string>& args,
-                                        std::vector<string>* result);
+  static void FindCandidateBlazercPaths(const std::string& workspace,
+                                        const std::string& cwd,
+                                        const std::vector<std::string>& args,
+                                        std::vector<std::string>* result);
 
   // Returns the candidate pathnames for the RC file in the workspace,
   // the first readable one of which will be chosen.
   // It is ok if no usable candidate exists.
-  static void WorkspaceRcFileSearchPath(std::vector<string>* candidates);
+  static void WorkspaceRcFileSearchPath(std::vector<std::string>* candidates);
 
   // Turn a %workspace%-relative import into its true name in the filesystem.
   // path_fragment is modified in place.
   // Unlike WorkspaceRcFileSearchPath, it is an error if no import file exists.
-  static bool WorkspaceRelativizeRcFilePath(const string &workspace,
-                                            string *path_fragment);
+  static bool WorkspaceRelativizeRcFilePath(const std::string& workspace,
+                                            std::string* path_fragment);
 
   static constexpr char WorkspacePrefix[] = "%workspace%/";
   static const int WorkspacePrefixLength = sizeof WorkspacePrefix - 1;
diff --git a/src/test/cpp/blaze_util_test.cc b/src/test/cpp/blaze_util_test.cc
index 99b81e3..cfa73c9 100644
--- a/src/test/cpp/blaze_util_test.cc
+++ b/src/test/cpp/blaze_util_test.cc
@@ -26,6 +26,8 @@
 
 namespace blaze {
 
+using std::string;
+
 static bool Symlink(const string& old_path, const string& new_path) {
   return symlink(old_path.c_str(), new_path.c_str()) == 0;
 }
diff --git a/src/test/cpp/util/file_test.cc b/src/test/cpp/util/file_test.cc
index 48b08b3..9ea3a85 100644
--- a/src/test/cpp/util/file_test.cc
+++ b/src/test/cpp/util/file_test.cc
@@ -17,7 +17,7 @@
 namespace blaze_util {
 
 TEST(BlazeUtil, JoinPath) {
-  string path = JoinPath("", "");
+  std::string path = JoinPath("", "");
   ASSERT_EQ("", path);
 
   path = JoinPath("a", "b");
diff --git a/src/test/cpp/util/strings_test.cc b/src/test/cpp/util/strings_test.cc
index 9f89bea..91c7f9c 100644
--- a/src/test/cpp/util/strings_test.cc
+++ b/src/test/cpp/util/strings_test.cc
@@ -14,10 +14,11 @@
 #include "src/main/cpp/util/strings.h"
 #include "gtest/gtest.h"
 
-using std::vector;
-
 namespace blaze_util {
 
+using std::string;
+using std::vector;
+
 TEST(BlazeUtil, JoinStrings) {
   vector<string> pieces;
   string output;