aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-19 19:10:30 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-19 19:10:30 +0000
commitd7407dc92c7d19cafce429e7e1cf9819d3fc0b92 (patch)
treeb1682301e20128532bd5143096f2eee9f99794f1 /lib/Rewrite/HTMLRewrite.cpp
parent7e37c818f9f77608c602ffb32c1135e3cd0132a8 (diff)
Convert parts of Rewriter to StringRef based API.
- Please accept my sincere apologies for the gratuitous elimination of code duplication, manual string length counting, unnecessary strlen calls, etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79448 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp39
1 files changed, 18 insertions, 21 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index 68edda222b..a17dde8254 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -53,8 +53,8 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
const char *BufferStart,
const char *StartTag, const char *EndTag) {
// Insert the tag at the absolute start/end of the range.
- RB.InsertTextAfter(B, StartTag, strlen(StartTag));
- RB.InsertTextBefore(E, EndTag, strlen(EndTag));
+ RB.InsertTextAfter(B, StartTag);
+ RB.InsertTextBefore(E, EndTag);
// Scan the range to see if there is a \r or \n. If so, and if the line is
// not blank, insert tags on that line as well.
@@ -68,7 +68,7 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
// Okay, we found a newline in the range. If we have an open tag, we need
// to insert a close tag at the first non-whitespace before the newline.
if (HadOpenTag)
- RB.InsertTextBefore(LastNonWhiteSpace+1, EndTag, strlen(EndTag));
+ RB.InsertTextBefore(LastNonWhiteSpace+1, EndTag);
// Instead of inserting an open tag immediately after the newline, we
// wait until we see a non-whitespace character. This prevents us from
@@ -87,7 +87,7 @@ void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
default:
// If there is no tag open, do it now.
if (!HadOpenTag) {
- RB.InsertTextAfter(i, StartTag, strlen(StartTag));
+ RB.InsertTextAfter(i, StartTag);
HadOpenTag = true;
}
@@ -120,11 +120,11 @@ void html::EscapeText(Rewriter &R, FileID FID,
case ' ':
if (EscapeSpaces)
- RB.ReplaceText(FilePos, 1, "&nbsp;", 6);
+ RB.ReplaceText(FilePos, 1, "&nbsp;");
++ColNo;
break;
case '\f':
- RB.ReplaceText(FilePos, 1, "<hr>", 4);
+ RB.ReplaceText(FilePos, 1, "<hr>");
ColNo = 0;
break;
@@ -133,25 +133,26 @@ void html::EscapeText(Rewriter &R, FileID FID,
break;
unsigned NumSpaces = 8-(ColNo&7);
if (EscapeSpaces)
- RB.ReplaceText(FilePos, 1, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
- "&nbsp;&nbsp;&nbsp;", 6*NumSpaces);
+ RB.ReplaceText(FilePos, 1,
+ llvm::StringRef("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
+ "&nbsp;&nbsp;&nbsp;", 6*NumSpaces));
else
- RB.ReplaceText(FilePos, 1, " ", NumSpaces);
+ RB.ReplaceText(FilePos, 1, llvm::StringRef(" ", NumSpaces));
ColNo += NumSpaces;
break;
}
case '<':
- RB.ReplaceText(FilePos, 1, "&lt;", 4);
+ RB.ReplaceText(FilePos, 1, "&lt;");
++ColNo;
break;
case '>':
- RB.ReplaceText(FilePos, 1, "&gt;", 4);
+ RB.ReplaceText(FilePos, 1, "&gt;");
++ColNo;
break;
case '&':
- RB.ReplaceText(FilePos, 1, "&amp;", 5);
+ RB.ReplaceText(FilePos, 1, "&amp;");
++ColNo;
break;
}
@@ -211,12 +212,10 @@ static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo,
if (B == E) { // Handle empty lines.
OS << " </td></tr>";
- OS.flush();
- RB.InsertTextBefore(B, &Str[0], Str.size());
+ RB.InsertTextBefore(B, OS.str());
} else {
- OS.flush();
- RB.InsertTextBefore(B, &Str[0], Str.size());
- RB.InsertTextBefore(E, "</td></tr>", strlen("</td></tr>"));
+ RB.InsertTextBefore(B, OS.str());
+ RB.InsertTextBefore(E, "</td></tr>");
}
}
@@ -260,10 +259,8 @@ void html::AddLineNumbers(Rewriter& R, FileID FID) {
}
// Add one big table tag that surrounds all of the code.
- RB.InsertTextBefore(0, "<table class=\"code\">\n",
- strlen("<table class=\"code\">\n"));
-
- RB.InsertTextAfter(FileEnd - FileBeg, "</table>", strlen("</table>"));
+ RB.InsertTextBefore(0, "<table class=\"code\">\n");
+ RB.InsertTextAfter(FileEnd - FileBeg, "</table>");
}
void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID,