mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
StringRef'ize escapeAndPrintString
Swift SVN r13911
This commit is contained in:
@@ -56,40 +56,38 @@ CommandOutput::getAnyOutputForType(types::ID type) const {
|
||||
return getAdditionalOutputForType(type);
|
||||
}
|
||||
|
||||
static void escapeAndPrintString(llvm::raw_ostream &os, const char *str) {
|
||||
StringRef String(str);
|
||||
if (String.empty()) {
|
||||
static void escapeAndPrintString(llvm::raw_ostream &os, StringRef Str) {
|
||||
if (Str.empty()) {
|
||||
// Special-case the empty string.
|
||||
os << "\"\"";
|
||||
return;
|
||||
}
|
||||
|
||||
bool NeedsEscape = String.find_first_of(" \"\\$") != StringRef::npos;
|
||||
bool NeedsEscape = Str.find_first_of(" \"\\$") != StringRef::npos;
|
||||
|
||||
if (!NeedsEscape) {
|
||||
// This string doesn't have anything we need to escape, so print it directly
|
||||
os << str;
|
||||
os << Str;
|
||||
return;
|
||||
}
|
||||
|
||||
// Quote and escape. This isn't really complete, but is good enough, and
|
||||
// matches how Clang's Command handles escaping arguments.
|
||||
os << '"';
|
||||
for (const char c : String) {
|
||||
for (const char c : Str) {
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\\':
|
||||
case '$':
|
||||
// These characters need to be escaped.
|
||||
os << '\\';
|
||||
// Fall-through to the default case, since we still need to print the
|
||||
// character.
|
||||
default:
|
||||
os << c;
|
||||
case '"':
|
||||
case '\\':
|
||||
case '$':
|
||||
// These characters need to be escaped.
|
||||
os << '\\';
|
||||
// Fall-through to the default case, since we still need to print the
|
||||
// character.
|
||||
default:
|
||||
os << c;
|
||||
}
|
||||
}
|
||||
os << '"';
|
||||
|
||||
}
|
||||
|
||||
void Command::printCommandLine(llvm::raw_ostream &os) const {
|
||||
|
||||
Reference in New Issue
Block a user