File tree Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Original file line number Diff line number Diff line change @@ -698,29 +698,16 @@ void FormatTokenLexer::tryParseJavaTextBlock() {
698
698
if (FormatTok->TokenText != " \"\" " )
699
699
return ;
700
700
701
- const auto *Str = Lex->getBufferLocation ();
701
+ const auto *S = Lex->getBufferLocation ();
702
702
const auto *End = Lex->getBuffer ().end ();
703
703
704
- if (Str == End || *Str != ' \" ' )
704
+ if (S == End || *S != ' \" ' )
705
705
return ;
706
706
707
- // Skip the `"""` that begins a text block.
708
- const auto *S = Str + 1 ;
709
-
710
- // From docs.oracle.com/en/java/javase/15/text-blocks/#text-block-syntax:
711
- // A text block begins with three double-quote characters followed by a line
712
- // terminator.
713
- while (S < End && *S != ' \n ' ) {
714
- if (!isblank (*S))
715
- return ;
716
- ++S;
717
- }
707
+ ++S; // Skip the `"""` that begins a text block.
718
708
719
709
// Find the `"""` that ends the text block.
720
- for (int Count = 0 ; Count < 3 ; ++S) {
721
- if (S == End)
722
- return ;
723
-
710
+ for (int Count = 0 ; Count < 3 && S < End; ++S) {
724
711
switch (*S) {
725
712
case ' \\ ' :
726
713
Count = -1 ;
@@ -733,7 +720,7 @@ void FormatTokenLexer::tryParseJavaTextBlock() {
733
720
}
734
721
}
735
722
736
- // Skip the text block.
723
+ // Ignore the possibly invalid text block.
737
724
resetLexer (SourceMgr.getFileOffset (Lex->getSourceLocation (S)));
738
725
}
739
726
Original file line number Diff line number Diff line change @@ -836,11 +836,16 @@ TEST_F(FormatTestJava, TextBlock) {
836
836
" }\n "
837
837
" }" );
838
838
839
- verifyNoChange (" String name = \"\"\"\n "
839
+ verifyNoChange (" String name = \"\"\"\r\ n "
840
840
" red\n "
841
841
" green\n "
842
842
" blue\\\n "
843
843
" \"\"\" ;" );
844
+
845
+ verifyFormat (" String name = \"\"\" Pat Q. Smith\"\"\" ;" );
846
+
847
+ verifyNoChange (" String name = \"\"\"\n "
848
+ " Pat Q. Smith" );
844
849
}
845
850
846
851
} // namespace
You can’t perform that action at this time.
0 commit comments