From a45409d8855a1e4538990507ef25e9b51c090193 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Wed, 17 Jun 2020 18:33:18 -0400 Subject: [Clang] Move clang::Job::printArg to llvm::sys::printArg. NFCI. This patch is to support/simplify https://reviews.llvm.org/D80833 --- llvm/lib/Support/Program.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'llvm/lib/Support/Program.cpp') 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 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" -- cgit v1.1