[PATCH] Add BreakSingleLineRawStrings option.
Alexander Kornienko
alexfh at google.com
Fri Dec 12 03:42:54 PST 2014
Updated the patch to not break single-line raw string literals.
http://reviews.llvm.org/D6636
Files:
lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -946,24 +946,6 @@
return 0;
}
-static bool getRawStringLiteralPrefixPostfix(StringRef Text, StringRef &Prefix,
- StringRef &Postfix) {
- if (Text.startswith(Prefix = "R\"") || Text.startswith(Prefix = "uR\"") ||
- Text.startswith(Prefix = "UR\"") || Text.startswith(Prefix = "u8R\"") ||
- Text.startswith(Prefix = "LR\"")) {
- size_t ParenPos = Text.find('(');
- if (ParenPos != StringRef::npos) {
- StringRef Delimiter =
- Text.substr(Prefix.size(), ParenPos - Prefix.size());
- Prefix = Text.substr(0, ParenPos + 1);
- Postfix = Text.substr(Text.size() - 2 - Delimiter.size());
- return Postfix.front() == ')' && Postfix.back() == '"' &&
- Postfix.substr(1).startswith(Delimiter);
- }
- }
- return false;
-}
-
unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
LineState &State,
bool DryRun) {
@@ -1015,8 +997,7 @@
Text.startswith(Prefix = "u\"") || Text.startswith(Prefix = "U\"") ||
Text.startswith(Prefix = "u8\"") ||
Text.startswith(Prefix = "L\""))) ||
- (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")")) ||
- getRawStringLiteralPrefixPostfix(Text, Prefix, Postfix)) {
+ (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")"))) {
Token.reset(new BreakableStringLiteral(
Current, State.Line->Level, StartColumn, Prefix, Postfix,
State.Line->InPPDirective, Encoding, Style));
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7386,22 +7386,14 @@
format("@\"NSString literal\";", getGoogleStyleWithColumns(19)));
}
-TEST_F(FormatTest, BreaksRawStringLiterals) {
- EXPECT_EQ("R\"x(raw )x\"\n"
- "R\"x(literal)x\";",
- format("R\"x(raw literal)x\";", getGoogleStyleWithColumns(15)));
- EXPECT_EQ("uR\"x(raw )x\"\n"
- "uR\"x(literal)x\";",
- format("uR\"x(raw literal)x\";", getGoogleStyleWithColumns(16)));
- EXPECT_EQ("u8R\"x(raw )x\"\n"
- "u8R\"x(literal)x\";",
- format("u8R\"x(raw literal)x\";", getGoogleStyleWithColumns(17)));
- EXPECT_EQ("LR\"x(raw )x\"\n"
- "LR\"x(literal)x\";",
- format("LR\"x(raw literal)x\";", getGoogleStyleWithColumns(16)));
- EXPECT_EQ("UR\"x(raw )x\"\n"
- "UR\"x(literal)x\";",
- format("UR\"x(raw literal)x\";", getGoogleStyleWithColumns(16)));
+TEST_F(FormatTest, DoesNotBreakRawStringLiterals) {
+ FormatStyle Style = getGoogleStyleWithColumns(15);
+ EXPECT_EQ("R\"x(raw literal)x\";", format("R\"x(raw literal)x\";", Style));
+ EXPECT_EQ("uR\"x(raw literal)x\";", format("uR\"x(raw literal)x\";", Style));
+ EXPECT_EQ("LR\"x(raw literal)x\";", format("LR\"x(raw literal)x\";", Style));
+ EXPECT_EQ("UR\"x(raw literal)x\";", format("UR\"x(raw literal)x\";", Style));
+ EXPECT_EQ("u8R\"x(raw literal)x\";",
+ format("u8R\"x(raw literal)x\";", Style));
}
TEST_F(FormatTest, BreaksStringLiteralsWithin_TMacro) {
@@ -7590,11 +7582,6 @@
"\"00000000\"\n"
"\"1\"",
format("\"test\\000000000001\"", getLLVMStyleWithColumns(10)));
- // FIXME: We probably don't need to care about escape sequences in raw
- // literals.
- EXPECT_EQ("R\"(\\x)\"\n"
- "R\"(\\x00)\"\n",
- format("R\"(\\x\\x00)\"\n", getGoogleStyleWithColumns(7)));
}
TEST_F(FormatTest, DoNotCreateUnreasonableUnwrappedLines) {
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6636.17223.patch
Type: text/x-patch
Size: 3932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141212/ff27bc80/attachment.bin>
More information about the cfe-commits
mailing list