r176447 - Make sure to not split string literals at the first character.
Manuel Klimek
klimek at google.com
Mon Mar 4 12:03:38 PST 2013
Author: klimek
Date: Mon Mar 4 14:03:38 2013
New Revision: 176447
URL: http://llvm.org/viewvc/llvm-project?rev=176447&view=rev
Log:
Make sure to not split string literals at the first character.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=176447&r1=176446&r2=176447&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Mar 4 14:03:38 2013
@@ -769,10 +769,10 @@ private:
StringRef::size_type
getSplitPoint(StringRef Text, StringRef::size_type Offset) {
StringRef::size_type SpaceOffset = Text.rfind(' ', Offset);
- if (SpaceOffset != StringRef::npos)
+ if (SpaceOffset != StringRef::npos && SpaceOffset != 0)
return SpaceOffset;
StringRef::size_type SlashOffset = Text.rfind('/', Offset);
- if (SlashOffset != StringRef::npos)
+ if (SlashOffset != StringRef::npos && SlashOffset != 0)
return SlashOffset;
if (Offset > 1)
// Do not split at 0.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=176447&r1=176446&r2=176447&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Mar 4 14:03:38 2013
@@ -3043,6 +3043,14 @@ TEST_F(FormatTest, BreakStringLiterals)
EXPECT_EQ("\"some\"\n"
"\" text\"",
format("\"some text\"", getLLVMStyleWithColumns(6)));
+ EXPECT_EQ("\"some\"\n"
+ "\" tex\"\n"
+ "\" and\"",
+ format("\"some tex and\"", getLLVMStyleWithColumns(6)));
+ EXPECT_EQ("\"some\"\n"
+ "\"/tex\"\n"
+ "\"/and\"",
+ format("\"some/tex/and\"", getLLVMStyleWithColumns(6)));
EXPECT_EQ("variable =\n"
" \"long string \"\n"
More information about the cfe-commits
mailing list