Skip to content

Commit 9691076

Browse files
committed
Response to rintaro's review
1 parent 4209b72 commit 9691076

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/Parse/Lexer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,14 +1707,15 @@ static void validateMultilineIndents(const Token &Str,
17071707
/// lexStringLiteral:
17081708
/// string_literal ::= ["]([^"\\\n\r]|character_escape)*["]
17091709
/// string_literal ::= ["]["]["].*["]["]["] - approximately
1710+
/// string_literal ::= (#+)("")?".*"(\2\1) - "raw" strings
17101711
void Lexer::lexStringLiteral(unsigned DelimiterLength) {
17111712
const char *TokStart = CurPtr-1;
17121713
assert((*TokStart == '"' || *TokStart == '\'') && "Unexpected start");
17131714
// NOTE: We only allow single-quote string literals so we can emit useful
17141715
// diagnostics about changing them to double quotes.
17151716

17161717
bool wasErroneous = false, MultilineString = false;
1717-
std::string ExtraTermination;
1718+
SmallString<8> ExtraTermination;
17181719

17191720
// Is this the start of a multiline string literal?
17201721
if (*TokStart == '"' && *CurPtr == '"' && *(CurPtr + 1) == '"') {
@@ -1723,9 +1724,9 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
17231724
if (*CurPtr != '\n' && *CurPtr != '\r')
17241725
diagnose(CurPtr, diag::lex_illegal_multiline_string_start)
17251726
.fixItInsert(Lexer::getSourceLoc(CurPtr), "\n");
1726-
ExtraTermination.insert(ExtraTermination.size(), 2, *TokStart);
1727+
ExtraTermination.append(2, *TokStart);
17271728
}
1728-
ExtraTermination.insert(ExtraTermination.size(), DelimiterLength, '#');
1729+
ExtraTermination.append(DelimiterLength, '#');
17291730

17301731
while (true) {
17311732
const char *TmpPtr = CurPtr + 1;
@@ -1750,6 +1751,7 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
17501751
// String literals cannot have \n or \r in them (unless multiline).
17511752
if (((*CurPtr == '\r' || *CurPtr == '\n') && !MultilineString)
17521753
|| CurPtr == BufferEnd) {
1754+
TokStart -= DelimiterLength;
17531755
diagnose(TokStart, diag::lex_unterminated_string);
17541756
return formToken(tok::unknown, TokStart);
17551757
}
@@ -1798,9 +1800,9 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
17981800
}
17991801

18001802
// Is this the end of multiline/delimited string literal?
1801-
if (StringRef(CurPtr, ExtraTermination.length()) == ExtraTermination) {
1803+
if (StringRef(CurPtr, BufferEnd - CurPtr).startswith(ExtraTermination)) {
18021804
TokStart -= DelimiterLength;
1803-
CurPtr += ExtraTermination.length();
1805+
CurPtr += ExtraTermination.size();
18041806
if (wasErroneous)
18051807
return formToken(tok::unknown, TokStart);
18061808

0 commit comments

Comments
 (0)