summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-05-29 22:06:18 +0000
committerManuel Klimek <klimek@google.com>2013-05-29 22:06:18 +0000
commitae1fbfb740547961dd072aed679993b96d4ab5fc (patch)
tree5db11c5969d13811c7f8c6df8f59155d7f4db450 /clang/lib/Format/BreakableToken.cpp
parentad6d08ac6fee10978588be3966920a1ce4faf200 (diff)
downloadbcm5719-llvm-ae1fbfb740547961dd072aed679993b96d4ab5fc.tar.gz
bcm5719-llvm-ae1fbfb740547961dd072aed679993b96d4ab5fc.zip
Fixes error when splitting block comments.
When trying to fall back to search from the end onwards, we would still find leading whitespace if the leading whitespace went on after the end of the line. llvm-svn: 182886
Diffstat (limited to 'clang/lib/Format/BreakableToken.cpp')
-rw-r--r--clang/lib/Format/BreakableToken.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index c102f8b1b29..5c3ad9cee2b 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -87,8 +87,16 @@ BreakableToken::Split getCommentSplit(StringRef Text,
StringRef::size_type SpaceOffset = Text.rfind(' ', MaxSplit);
if (SpaceOffset == StringRef::npos ||
// Don't break at leading whitespace.
- Text.find_last_not_of(' ', SpaceOffset) == StringRef::npos)
- SpaceOffset = Text.find(' ', MaxSplit);
+ Text.find_last_not_of(' ', SpaceOffset) == StringRef::npos) {
+ // Make sure that we don't break at leading whitespace that
+ // reaches past MaxSplit.
+ StringRef::size_type FirstNonWhitespace = Text.find_first_not_of(" ");
+ if (FirstNonWhitespace == StringRef::npos)
+ // If the comment is only whitespace, we cannot split.
+ return BreakableToken::Split(StringRef::npos, 0);
+ SpaceOffset =
+ Text.find(' ', std::max<unsigned>(MaxSplit, FirstNonWhitespace));
+ }
if (SpaceOffset != StringRef::npos && SpaceOffset != 0) {
StringRef BeforeCut = Text.substr(0, SpaceOffset).rtrim();
StringRef AfterCut = Text.substr(SpaceOffset).ltrim();
OpenPOWER on IntegriCloud