summaryrefslogtreecommitdiffstats
path: root/clang/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
commitb176cff89de33a17f3e664b612c8b78882b801e0 (patch)
tree60299e02caba32d9f929c2a1c695737bf8bc5d00 /clang/lib/Format/Format.cpp
parent70dd0caa4610ec3f2ae9324be8cac909e7edac2b (diff)
downloadbcm5719-llvm-b176cff89de33a17f3e664b612c8b78882b801e0.tar.gz
bcm5719-llvm-b176cff89de33a17f3e664b612c8b78882b801e0.zip
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. llvm-svn: 176349
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4aaae844fca..d2b12f68148 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/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() {
OpenPOWER on IntegriCloud