summaryrefslogtreecommitdiff
path: root/lib/Support/StringExtras.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/StringExtras.cpp')
-rw-r--r--lib/Support/StringExtras.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp
index 21157a14086d..386d74a47983 100644
--- a/lib/Support/StringExtras.cpp
+++ b/lib/Support/StringExtras.cpp
@@ -58,6 +58,33 @@ void llvm::SplitString(StringRef Source,
}
}
+void llvm::printEscapedString(StringRef Name, raw_ostream &Out) {
+ for (unsigned i = 0, e = Name.size(); i != e; ++i) {
+ unsigned char C = Name[i];
+ if (isPrint(C) && C != '\\' && C != '"')
+ Out << C;
+ else
+ Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
+ }
+}
+
+void llvm::printHTMLEscaped(StringRef String, raw_ostream &Out) {
+ for (char C : String) {
+ if (C == '&')
+ Out << "&amp;";
+ else if (C == '<')
+ Out << "&lt;";
+ else if (C == '>')
+ Out << "&gt;";
+ else if (C == '\"')
+ Out << "&quot;";
+ else if (C == '\'')
+ Out << "&apos;";
+ else
+ Out << C;
+ }
+}
+
void llvm::printLowerCase(StringRef String, raw_ostream &Out) {
for (const char C : String)
Out << toLower(C);