diff --git a/lib/Format/Encoding.h b/lib/Format/Encoding.h index 766d29274ce66b64199fb91b6934a838c3ad31e0..592d7201a8ac64e2e204918058129e3353bdb864 100644 --- a/lib/Format/Encoding.h +++ b/lib/Format/Encoding.h @@ -135,7 +135,7 @@ inline unsigned getEscapeSequenceLength(StringRef Text) { ++I; return I; } - return 2; + return 1 + getNumBytesForUTF8(Text[1]); } } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b2c5307341d89d71de691dbd3abed65593a98da0..252ae4db3f82e73607f41226bcc447683163971c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -9555,6 +9555,11 @@ TEST_F(FormatTest, SplitsUTF8Strings) { "\"å…«ä¹å\tqq\"", format("\"一\t二 \t三 å›› 五\tå… \t七 å…«ä¹å\tqq\"", getLLVMStyleWithColumns(11))); + + // UTF8 character in an escape sequence. + EXPECT_EQ("\"aaaaaa\"\n" + "\"\\\xC2\x8D\"", + format("\"aaaaaa\\\xC2\x8D\"", getLLVMStyleWithColumns(10))); } TEST_F(FormatTest, HandlesDoubleWidthCharsInMultiLineStrings) {