aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-03-01 13:14:08 +0000
committerManuel Klimek <klimek@google.com>2013-03-01 13:14:08 +0000
commitaf31fd7021e685280da9155e5017f1053b05fdf8 (patch)
tree7c34fe96e124f258328ec7bb35388045fee800e0 /lib/Format/Format.cpp
parent2fbe92cc2464c77825209df9a262d9d13e5ba64c (diff)
Implement fallback split point for string literals.
If we don't find a natural split point (currently space) in a string literal protruding over the line, we just split at the last possible point. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176349 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 4aaae844fc..d2b12f6814 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -720,6 +720,8 @@ private:
while (StartColumn + TailLength > getColumnLimit()) {
StringRef Text = StringRef(Current.FormatTok.Tok.getLiteralData() +
TailOffset, TailLength);
+ if (StartColumn + 1 > getColumnLimit())
+ break;
StringRef::size_type SplitPoint =
getSplitPoint(Text, getColumnLimit() - StartColumn - 1);
if (SplitPoint == StringRef::npos)
@@ -748,8 +750,11 @@ private:
StringRef::size_type
getSplitPoint(StringRef Text, StringRef::size_type Offset) {
- // FIXME: Implement more sophisticated splitting mechanism, and a fallback.
- return Text.rfind(' ', Offset);
+ StringRef::size_type SpaceOffset = Text.rfind(' ', Offset);
+ if (SpaceOffset == StringRef::npos && Offset > 0) {
+ return Offset - 1;
+ }
+ return SpaceOffset;
}
unsigned getColumnLimit() {