With this I can now insert stuff before tabs, woo.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42942 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Rewrite/Rewriter.cpp b/Rewrite/Rewriter.cpp
index 94fbe6e..41c5c6f 100644
--- a/Rewrite/Rewriter.cpp
+++ b/Rewrite/Rewriter.cpp
@@ -96,8 +96,17 @@
void RewriteBuffer::InsertText(unsigned OrigOffset,
const char *StrData, unsigned StrLen) {
+ // Nothing to insert, exit early.
if (StrLen == 0) return;
- // FIXME:
+
+ unsigned RealOffset = getMappedOffset(OrigOffset, true);
+ assert(RealOffset <= Buffer.size() && "Invalid location");
+
+ // Remove the dead characters.
+ Buffer.insert(Buffer.begin()+RealOffset, StrData, StrData+StrLen);
+
+ // Add a delta so that future changes are offset correctly.
+ AddDelta(OrigOffset, StrLen);
}
/// ReplaceText - This method replaces a range of characters in the input
@@ -105,7 +114,7 @@
/// operation.
void RewriteBuffer::ReplaceText(unsigned OrigOffset, unsigned OrigLength,
const char *NewStr, unsigned NewLength) {
- RemoveText(OrigOffset, OrigLength);
+ InsertText(OrigOffset, NewStr, NewLength);
return;
unsigned MappedOffs = getMappedOffset(OrigOffset);