[PATCH] Split long strings on word boundaries.
Alexander Kornienko
alexfh at google.com
Tue Jun 18 10:52:33 PDT 2013
Hi klimek,
Split strings at word boundaries, when there are no spaces and slashes.
http://llvm-reviews.chandlerc.com/D1003
Files:
lib/Format/BreakableToken.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/BreakableToken.cpp
===================================================================
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -77,6 +77,7 @@
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 @@
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 @@
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);
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -4636,6 +4636,26 @@
"\"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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1003.1.patch
Type: text/x-patch
Size: 2184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130618/8d149eda/attachment.bin>
More information about the cfe-commits
mailing list