From b176cff89de33a17f3e664b612c8b78882b801e0 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Fri, 1 Mar 2013 13:14:08 +0000 Subject: 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 --- clang/lib/Format/Format.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'clang/lib/Format/Format.cpp') 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() { -- cgit v1.2.3