diff options
author | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2020-06-17 18:33:18 -0400 |
---|---|---|
committer | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2020-06-18 09:17:13 -0400 |
commit | a45409d8855a1e4538990507ef25e9b51c090193 (patch) | |
tree | 5e1cc17595d8b3ded5895935e86aed1b0c97ae43 /llvm/lib/Support/Program.cpp | |
parent | 92d8ad02e92fed3884169ba5d98056fe4fa5660d (diff) | |
download | llvm-a45409d8855a1e4538990507ef25e9b51c090193.zip llvm-a45409d8855a1e4538990507ef25e9b51c090193.tar.gz llvm-a45409d8855a1e4538990507ef25e9b51c090193.tar.bz2 |
[Clang] Move clang::Job::printArg to llvm::sys::printArg. NFCI.
This patch is to support/simplify https://reviews.llvm.org/D80833
Diffstat (limited to 'llvm/lib/Support/Program.cpp')
-rw-r--r-- | llvm/lib/Support/Program.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp index d90cb45..5294f65 100644 --- a/llvm/lib/Support/Program.cpp +++ b/llvm/lib/Support/Program.cpp @@ -13,6 +13,7 @@ #include "llvm/Support/Program.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/llvm-config.h" +#include "llvm/Support/raw_ostream.h" #include <system_error> using namespace llvm; using namespace sys; @@ -75,6 +76,24 @@ bool sys::commandLineFitsWithinSystemLimits(StringRef Program, return commandLineFitsWithinSystemLimits(Program, StringRefArgs); } +void sys::printArg(raw_ostream &OS, StringRef Arg, bool Quote) { + const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos; + + if (!Quote && !Escape) { + OS << Arg; + return; + } + + // Quote and escape. This isn't really complete, but good enough. + OS << '"'; + for (const auto c : Arg) { + if (c == '"' || c == '\\' || c == '$') + OS << '\\'; + OS << c; + } + OS << '"'; +} + // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX #include "Unix/Program.inc" |