Do not escape UNICODE when writing out target info.

Escaping unicode characters results in invalid JSON.

- Refactor writeEscaped routine into StringExtras

Resolves rdar://90108531
This commit is contained in:
Artem Chikin
2022-03-16 12:12:46 -07:00
parent cf05e61b0b
commit 57518b5894
8 changed files with 50 additions and 39 deletions

View File

@@ -23,6 +23,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace swift;
@@ -1392,3 +1393,27 @@ Optional<StringRef> swift::stripWithCompletionHandlerSuffix(StringRef name) {
return None;
}
void swift::writeEscaped(llvm::StringRef Str, llvm::raw_ostream &OS) {
for (unsigned i = 0, e = Str.size(); i != e; ++i) {
unsigned char c = Str[i];
switch (c) {
case '\\':
OS << '\\' << '\\';
break;
case '\t':
OS << '\\' << 't';
break;
case '\n':
OS << '\\' << 'n';
break;
case '"':
OS << '\\' << '"';
break;
default:
OS << c;
break;
}
}
}