aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/SourceMgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/SourceMgr.cpp')
-rw-r--r--llvm/lib/Support/SourceMgr.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp
index d8fde7f..e17e5ab 100644
--- a/llvm/lib/Support/SourceMgr.cpp
+++ b/llvm/lib/Support/SourceMgr.cpp
@@ -345,12 +345,18 @@ static void buildFixItLine(std::string &CaretLine, std::string &FixItLine,
static void printSourceLine(raw_ostream &S, StringRef LineContents) {
// Print out the source line one character at a time, so we can expand tabs.
for (unsigned i = 0, e = LineContents.size(), OutCol = 0; i != e; ++i) {
- if (LineContents[i] != '\t') {
- S << LineContents[i];
- ++OutCol;
- continue;
+ size_t NextTab = LineContents.find('\t', i);
+ // If there were no tabs left, print the rest, we are done.
+ if (NextTab == StringRef::npos) {
+ S << LineContents.drop_front(i);
+ break;
}
+ // Otherwise, print from i to NextTab.
+ S << LineContents.slice(i, NextTab);
+ OutCol += NextTab - i;
+ i = NextTab;
+
// If we have a tab, emit at least one space, then round up to 8 columns.
do {
S << ' ';