@@ -1707,14 +1707,15 @@ static void validateMultilineIndents(const Token &Str,
1707
1707
// / lexStringLiteral:
1708
1708
// / string_literal ::= ["]([^"\\\n\r]|character_escape)*["]
1709
1709
// / string_literal ::= ["]["]["].*["]["]["] - approximately
1710
+ // / string_literal ::= (#+)("")?".*"(\2\1) - "raw" strings
1710
1711
void Lexer::lexStringLiteral (unsigned DelimiterLength) {
1711
1712
const char *TokStart = CurPtr-1 ;
1712
1713
assert ((*TokStart == ' "' || *TokStart == ' \' ' ) && " Unexpected start" );
1713
1714
// NOTE: We only allow single-quote string literals so we can emit useful
1714
1715
// diagnostics about changing them to double quotes.
1715
1716
1716
1717
bool wasErroneous = false , MultilineString = false ;
1717
- std::string ExtraTermination;
1718
+ SmallString< 8 > ExtraTermination;
1718
1719
1719
1720
// Is this the start of a multiline string literal?
1720
1721
if (*TokStart == ' "' && *CurPtr == ' "' && *(CurPtr + 1 ) == ' "' ) {
@@ -1723,9 +1724,9 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
1723
1724
if (*CurPtr != ' \n ' && *CurPtr != ' \r ' )
1724
1725
diagnose (CurPtr, diag::lex_illegal_multiline_string_start)
1725
1726
.fixItInsert (Lexer::getSourceLoc (CurPtr), " \n " );
1726
- ExtraTermination.insert (ExtraTermination. size (), 2 , *TokStart);
1727
+ ExtraTermination.append ( 2 , *TokStart);
1727
1728
}
1728
- ExtraTermination.insert (ExtraTermination. size (), DelimiterLength, ' #' );
1729
+ ExtraTermination.append ( DelimiterLength, ' #' );
1729
1730
1730
1731
while (true ) {
1731
1732
const char *TmpPtr = CurPtr + 1 ;
@@ -1750,6 +1751,7 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
1750
1751
// String literals cannot have \n or \r in them (unless multiline).
1751
1752
if (((*CurPtr == ' \r ' || *CurPtr == ' \n ' ) && !MultilineString)
1752
1753
|| CurPtr == BufferEnd) {
1754
+ TokStart -= DelimiterLength;
1753
1755
diagnose (TokStart, diag::lex_unterminated_string);
1754
1756
return formToken (tok::unknown, TokStart);
1755
1757
}
@@ -1798,9 +1800,9 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
1798
1800
}
1799
1801
1800
1802
// Is this the end of multiline/delimited string literal?
1801
- if (StringRef (CurPtr, ExtraTermination. length ()) == ExtraTermination) {
1803
+ if (StringRef (CurPtr, BufferEnd - CurPtr). startswith ( ExtraTermination) ) {
1802
1804
TokStart -= DelimiterLength;
1803
- CurPtr += ExtraTermination.length ();
1805
+ CurPtr += ExtraTermination.size ();
1804
1806
if (wasErroneous)
1805
1807
return formToken (tok::unknown, TokStart);
1806
1808
0 commit comments