Added variant of "InsertText" in the Rewriter to support inserting text both
*before* and after a specific location.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48504 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Rewrite/Rewriter.cpp b/lib/Rewrite/Rewriter.cpp
index e3cc977..7b35cf1 100644
--- a/lib/Rewrite/Rewriter.cpp
+++ b/lib/Rewrite/Rewriter.cpp
@@ -101,11 +101,13 @@
}
void RewriteBuffer::InsertText(unsigned OrigOffset,
- const char *StrData, unsigned StrLen) {
+ const char *StrData, unsigned StrLen,
+ bool InsertAfter) {
+
// Nothing to insert, exit early.
if (StrLen == 0) return;
- unsigned RealOffset = getMappedOffset(OrigOffset, true);
+ unsigned RealOffset = getMappedOffset(OrigOffset, InsertAfter);
assert(RealOffset <= Buffer.size() && "Invalid location");
// Insert the new characters.
@@ -207,12 +209,12 @@
/// InsertText - Insert the specified string at the specified location in the
/// original buffer.
-bool Rewriter::InsertText(SourceLocation Loc,
- const char *StrData, unsigned StrLen) {
+bool Rewriter::InsertText(SourceLocation Loc, const char *StrData,
+ unsigned StrLen, bool InsertAfter) {
if (!isRewritable(Loc)) return true;
unsigned FileID;
unsigned StartOffs = getLocationOffsetAndFileID(Loc, FileID);
- getEditBuffer(FileID).InsertText(StartOffs, StrData, StrLen);
+ getEditBuffer(FileID).InsertText(StartOffs, StrData, StrLen, InsertAfter);
return false;
}