r283645 - Use StringRef in Command::printArg() instead of raw pointer (NFC)

Mehdi Amini via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 18:38:43 PDT 2016


Author: mehdi_amini
Date: Fri Oct  7 20:38:43 2016
New Revision: 283645

URL: http://llvm.org/viewvc/llvm-project?rev=283645&view=rev
Log:
Use StringRef in Command::printArg() instead of raw pointer (NFC)

Modified:
    cfe/trunk/include/clang/Driver/Job.h
    cfe/trunk/lib/Driver/Job.cpp

Modified: cfe/trunk/include/clang/Driver/Job.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Job.h?rev=283645&r1=283644&r2=283645&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Job.h (original)
+++ cfe/trunk/include/clang/Driver/Job.h Fri Oct  7 20:38:43 2016
@@ -116,7 +116,7 @@ public:
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
 
   /// Print a command argument, and optionally quote it.
-  static void printArg(llvm::raw_ostream &OS, const char *Arg, bool Quote);
+  static void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote);
 };
 
 /// Like Command, but with a fallback which is executed in case

Modified: cfe/trunk/lib/Driver/Job.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Job.cpp?rev=283645&r1=283644&r2=283645&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Job.cpp (original)
+++ cfe/trunk/lib/Driver/Job.cpp Fri Oct  7 20:38:43 2016
@@ -80,8 +80,8 @@ static int skipArgs(const char *Flag, bo
   return 0;
 }
 
-void Command::printArg(raw_ostream &OS, const char *Arg, bool Quote) {
-  const bool Escape = std::strpbrk(Arg, "\"\\$");
+void Command::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
+  const bool Escape = Arg.find_first_of("\"\\$") != StringRef::npos;
 
   if (!Quote && !Escape) {
     OS << Arg;
@@ -90,7 +90,7 @@ void Command::printArg(raw_ostream &OS,
 
   // Quote and escape. This isn't really complete, but good enough.
   OS << '"';
-  while (const char c = *Arg++) {
+  for (const char c : Arg) {
     if (c == '"' || c == '\\' || c == '$')
       OS << '\\';
     OS << c;




More information about the cfe-commits mailing list