summaryrefslogtreecommitdiffstats
path: root/include
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 /include
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 'include')
-rw-r--r--include/clang/Rewrite/Rewriter.h41
1 files changed, 19 insertions, 22 deletions
diff --git a/include/clang/Rewrite/Rewriter.h b/include/clang/Rewrite/Rewriter.h
index c3ee0175c3..36d1939def 100644
--- a/include/clang/Rewrite/Rewriter.h
+++ b/include/clang/Rewrite/Rewriter.h
@@ -22,6 +22,7 @@
#include <cstring>
#include <string>
#include "clang/Rewrite/DeltaTree.h"
+#include "llvm/ADT/StringRef.h"
namespace clang {
class SourceManager;
@@ -59,7 +60,7 @@ public:
/// the buffer is specified relative to the original SourceBuffer. The
/// text is inserted after the specified location.
///
- void InsertText(unsigned OrigOffset, const char *StrData, unsigned StrLen,
+ void InsertText(unsigned OrigOffset, const llvm::StringRef &Str,
bool InsertAfter = true);
@@ -67,25 +68,23 @@ public:
/// where the offset in the buffer is specified relative to the original
/// SourceBuffer.
///
- void InsertTextBefore(unsigned OrigOffset, const char *StrData,
- unsigned StrLen) {
- InsertText(OrigOffset, StrData, StrLen, false);
+ void InsertTextBefore(unsigned OrigOffset, const llvm::StringRef &Str) {
+ InsertText(OrigOffset, Str, false);
}
/// InsertText - Insert some text at the specified point, where the offset in
/// the buffer is specified relative to the original SourceBuffer. The
/// text is inserted after the specified location. This is method is the
/// same as InsertText with "InsertAfter == false".
- void InsertTextAfter(unsigned OrigOffset, const char *StrData,
- unsigned StrLen) {
- InsertText(OrigOffset, StrData, StrLen);
+ void InsertTextAfter(unsigned OrigOffset, const llvm::StringRef &Str) {
+ InsertText(OrigOffset, Str);
}
/// ReplaceText - This method replaces a range of characters in the input
/// buffer with a new string. This is effectively a combined "remove/insert"
/// operation.
void ReplaceText(unsigned OrigOffset, unsigned OrigLength,
- const char *NewStr, unsigned NewLength);
+ const llvm::StringRef &NewStr);
private: // Methods only usable by Rewriter.
@@ -159,7 +158,7 @@ public:
/// InsertText - Insert the specified string at the specified location in the
/// original buffer. This method returns true (and does nothing) if the input
/// location was not rewritable, false otherwise.
- bool InsertText(SourceLocation Loc, const char *StrData, unsigned StrLen,
+ bool InsertText(SourceLocation Loc, const llvm::StringRef &Str,
bool InsertAfter = true);
/// InsertTextAfter - Insert the specified string at the specified location in
@@ -167,9 +166,8 @@ public:
/// the input location was not rewritable, false otherwise. Text is
/// inserted after any other text that has been previously inserted
/// at the some point (the default behavior for InsertText).
- bool InsertTextAfter(SourceLocation Loc, const char *StrData,
- unsigned StrLen) {
- return InsertText(Loc, StrData, StrLen);
+ bool InsertTextAfter(SourceLocation Loc, const llvm::StringRef &Str) {
+ return InsertText(Loc, Str, false);
}
/// InsertText - Insert the specified string at the specified location in the
@@ -177,27 +175,26 @@ public:
/// location was not rewritable, false otherwise. Text is
/// inserted before any other text that has been previously inserted
/// at the some point.
- bool InsertTextBefore(SourceLocation Loc, const char *StrData,
- unsigned StrLen) {
- return InsertText(Loc, StrData, StrLen, false);
+ bool InsertTextBefore(SourceLocation Loc, const llvm::StringRef &Str) {
+ return InsertText(Loc, Str, false);
}
bool InsertCStrBefore(SourceLocation Loc, const char* Str) {
- return InsertTextBefore(Loc, Str, strlen(Str));
+ return InsertTextBefore(Loc, Str);
}
bool InsertCStrAfter(SourceLocation Loc, const char* Str) {
- return InsertTextAfter(Loc, Str, strlen(Str));
+ return InsertTextAfter(Loc, Str);
}
- bool InsertStrBefore(SourceLocation Loc, const std::string& S) {
- return S.empty() ? false : InsertTextBefore(Loc, &S[0], S.size());
+ bool InsertStrBefore(SourceLocation Loc, const std::string& Str) {
+ return InsertTextBefore(Loc, Str);
}
- bool InsertStrAfter(SourceLocation Loc, const std::string& S) {
- return S.empty() ? false : InsertTextAfter(Loc, &S[0], S.size());
+ bool InsertStrAfter(SourceLocation Loc, const std::string& Str) {
+ return InsertTextAfter(Loc, Str);
}
@@ -208,7 +205,7 @@ public:
/// buffer with a new string. This is effectively a combined "remove/insert"
/// operation.
bool ReplaceText(SourceLocation Start, unsigned OrigLength,
- const char *NewStr, unsigned NewLength);
+ const llvm::StringRef &NewStr);
/// ReplaceStmt - This replaces a Stmt/Expr with another, using the pretty
/// printer to generate the replacement code. This returns true if the input