r184304 - Split long strings on word boundaries.
Alexander Kornienko
alexfh at google.com
Wed Jun 19 07:22:48 PDT 2013
Author: alexfh
Date: Wed Jun 19 09:22:47 2013
New Revision: 184304
URL: http://llvm.org/viewvc/llvm-project?rev=184304&view=rev
Log:
Split long strings on word boundaries.
Summary: Split strings at word boundaries, when there are no spaces and slashes.
Reviewers: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1003
Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=184304&r1=184303&r2=184304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Wed Jun 19 09:22:47 2013
@@ -77,6 +77,7 @@ BreakableToken::Split getStringSplit(Str
encoding::getCodePointCount(Text, Encoding) - 1);
StringRef::size_type SpaceOffset = 0;
StringRef::size_type SlashOffset = 0;
+ StringRef::size_type WordStartOffset = 0;
StringRef::size_type SplitPoint = 0;
for (unsigned Chars = 0;;) {
unsigned Advance;
@@ -95,6 +96,8 @@ BreakableToken::Split getStringSplit(Str
SpaceOffset = SplitPoint;
if (Text[0] == '/')
SlashOffset = SplitPoint;
+ if (Text[0] != '\\' && !isAlphanumeric(Text[0]))
+ WordStartOffset = SplitPoint;
SplitPoint += Advance;
Text = Text.substr(Advance);
@@ -104,6 +107,8 @@ BreakableToken::Split getStringSplit(Str
return BreakableToken::Split(SpaceOffset + 1, 0);
if (SlashOffset != 0)
return BreakableToken::Split(SlashOffset + 1, 0);
+ if (WordStartOffset != 0)
+ return BreakableToken::Split(WordStartOffset + 1, 0);
if (SplitPoint != 0)
return BreakableToken::Split(SplitPoint, 0);
return BreakableToken::Split(StringRef::npos, 0);
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=184304&r1=184303&r2=184304&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jun 19 09:22:47 2013
@@ -4636,6 +4636,26 @@ TEST_F(FormatTest, BreakStringLiterals)
"\"slashes\"",
format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ(
+ "\"split/\"\n"
+ "\"pathat/\"\n"
+ "\"slashes\"",
+ format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ("\"split at \"\n"
+ "\"spaces/at/\"\n"
+ "\"slashes.at.any$\"\n"
+ "\"non-alphanumeric%\"\n"
+ "\"1111111111characte\"\n"
+ "\"rs\"",
+ format("\"split at "
+ "spaces/at/"
+ "slashes.at."
+ "any$non-"
+ "alphanumeric%"
+ "1111111111characte"
+ "rs\"",
+ getLLVMStyleWithColumns(20)));
+
FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
AlignLeft.AlignEscapedNewlinesLeft = true;
EXPECT_EQ(
More information about the cfe-commits
mailing list