summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-04-11 09:55:00 +0000
committerAlexander Kornienko <alexfh@google.com>2017-04-11 09:55:00 +0000
commitd4fa2e634876672a680a300442ed917761a8c3ff (patch)
tree7f4503b025bc11c7af8ebd4d3097fe07420945e4 /clang/lib/Format/BreakableToken.cpp
parent4fc5f3c02e57136c7c4055bd2f83a56bb79d37e5 (diff)
downloadbcm5719-llvm-d4fa2e634876672a680a300442ed917761a8c3ff.tar.gz
bcm5719-llvm-d4fa2e634876672a680a300442ed917761a8c3ff.zip
[clang-format] Handle NSString literals by merging tokens.
Summary: This fixes a few outstanding bugs: * incorrect breaking of NSString literals containing double-width characters; * inconsistent formatting of ObjC dictionary literals containing NSString literals; * AlwaysBreakBeforeMultilineStrings ignoring implicitly-concatenated NSString literals. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D31706 llvm-svn: 299927
Diffstat (limited to 'clang/lib/Format/BreakableToken.cpp')
-rw-r--r--clang/lib/Format/BreakableToken.cpp11
1 files changed, 2 insertions, 9 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index b42e4aee505..c97486e4e4a 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -186,7 +186,7 @@ BreakableSingleLineToken::BreakableSingleLineToken(
const FormatStyle &Style)
: BreakableToken(Tok, InPPDirective, Encoding, Style),
StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix) {
- assert(Tok.TokenText.endswith(Postfix));
+ assert(Tok.TokenText.startswith(Prefix) && Tok.TokenText.endswith(Postfix));
Line = Tok.TokenText.substr(
Prefix.size(), Tok.TokenText.size() - Prefix.size() - Postfix.size());
}
@@ -210,16 +210,9 @@ BreakableStringLiteral::getSplit(unsigned LineIndex, unsigned TailOffset,
void BreakableStringLiteral::insertBreak(unsigned LineIndex,
unsigned TailOffset, Split Split,
WhitespaceManager &Whitespaces) {
- unsigned LeadingSpaces = StartColumn;
- // The '@' of an ObjC string literal (@"Test") does not become part of the
- // string token.
- // FIXME: It might be a cleaner solution to merge the tokens as a
- // precomputation step.
- if (Prefix.startswith("@"))
- --LeadingSpaces;
Whitespaces.replaceWhitespaceInToken(
Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix,
- Prefix, InPPDirective, 1, LeadingSpaces);
+ Prefix, InPPDirective, 1, StartColumn);
}
BreakableComment::BreakableComment(const FormatToken &Token,
OpenPOWER on IntegriCloud