aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-03-27 17:15:29 +0000
committerTed Kremenek <kremenek@apple.com>2008-03-27 17:15:29 +0000
commit053ef593fa9d2b890645a914eee203231fb34458 (patch)
tree2b56bcea2fbcc7cf8b09a677635e835fd13b1099 /lib/Rewrite/HTMLRewrite.cpp
parent1c33975b2192fa4536b1205a1809826ff6e03263 (diff)
Add html::EscapeText for std::string; use this function to escape text in message bubbles.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48884 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index b886bec38b..bb4ae86261 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -46,6 +46,32 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
}
}
+std::string html::EscapeText(const std::string& s, bool EscapeSpaces) {
+
+ unsigned len = s.size();
+ std::ostringstream os;
+
+ for (unsigned i = 0 ; i < len; ++i) {
+
+ char c = s[i];
+
+ switch (c) {
+ default:
+ os << c; break;
+
+ case ' ':
+ if (EscapeSpaces) os << "&#32;";
+ break;
+
+ case '<': os << "&lt;"; break;
+ case '>': os << "&gt;"; break;
+ case '&': os << "&amp;"; break;
+ }
+ }
+
+ return os.str();
+}
+
static void AddLineNumber(Rewriter& R, unsigned LineNo,
SourceLocation B, SourceLocation E) {