From abf6e03bc1aa8f3f1c464cd1ce841222260504ab Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Mon, 4 Mar 2013 20:03:38 +0000 Subject: [PATCH] Make sure to not split string literals at the first character. llvm-svn: 176447 --- clang/lib/Format/Format.cpp | 4 ++-- clang/unittests/Format/FormatTest.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f7702cb..2b82410 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 46eb1bc..eafc4c8 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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" -- 2.7.4