Slightly improve formatting of longer pipe statements.
The stronger binding of a string ending in :/= does not really make
sense if it is the only character.
Before:
llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa
<< "=" << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
After:
llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << "="
<< bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177075 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index e878a96..8267a25 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -934,10 +934,11 @@
if (Right.is(tok::lessless)) {
if (Left.is(tok::string_literal)) {
- char LastChar =
- StringRef(Left.FormatTok.Tok.getLiteralData(),
- Left.FormatTok.TokenLength).drop_back(1).rtrim().back();
- if (LastChar == ':' || LastChar == '=')
+ StringRef Content = StringRef(Left.FormatTok.Tok.getLiteralData(),
+ Left.FormatTok.TokenLength);
+ Content = Content.drop_back(1).drop_front(1).trim();
+ if (Content.size() > 1 &&
+ (Content.back() == ':' || Content.back() == '='))
return 100;
}
return prec::Shift;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index af580dd..3044c69 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1628,6 +1628,8 @@
" << \"ccccccccccccccccc = \" << ccccccccccccccccc\n"
" << \"ddddddddddddddddd = \" << ddddddddddddddddd\n"
" << \"eeeeeeeeeeeeeeeee = \" << eeeeeeeeeeeeeeeee;");
+ verifyFormat("llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << \"=\"\n"
+ " << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
}
TEST_F(FormatTest, UnderstandsEquals) {