forked from OSchip/llvm-project
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 llvm-svn: 184304
This commit is contained in:
parent
dac35c24c0
commit
7285207486
|
@ -77,6 +77,7 @@ BreakableToken::Split getStringSplit(StringRef Text,
|
|||
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(StringRef Text,
|
|||
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(StringRef Text,
|
|||
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);
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue