aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/TokenAnnotator.cpp9
-rw-r--r--unittests/Format/FormatTest.cpp2
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index e878a9690c..8267a25d03 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -934,10 +934,11 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
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 af580ddce7..3044c69cd0 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1628,6 +1628,8 @@ TEST_F(FormatTest, AlignsPipes) {
" << \"ccccccccccccccccc = \" << ccccccccccccccccc\n"
" << \"ddddddddddddddddd = \" << ddddddddddddddddd\n"
" << \"eeeeeeeeeeeeeeeee = \" << eeeeeeeeeeeeeeeee;");
+ verifyFormat("llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << \"=\"\n"
+ " << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
}
TEST_F(FormatTest, UnderstandsEquals) {