Skip to content

Commit

Permalink
Leave \ escapes in char literals in string interpolations
Browse files Browse the repository at this point in the history
Closes #861

But " must still be escaped as \" inside a string interpolation expression. Removing that one need to escape inside a string interpolation would likely require switching to prefix $ -- see the #861 comment thread
  • Loading branch information
hsutter committed Dec 18, 2023
1 parent 759c3b3 commit dc7e10c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion regression-tests/test-results/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cppfront compiler v0.3.0 Build 8C17:1632
cppfront compiler v0.3.0 Build 8C18:0609
Copyright(c) Herb Sutter All rights reserved

SPDX-License-Identifier: CC-BY-NC-ND-4.0
Expand Down
2 changes: 1 addition & 1 deletion source/build.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"8C17:1632"
"8C18:0609"
15 changes: 10 additions & 5 deletions source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,16 @@ auto expand_string_literal(

// Then put interpolated chunk into ret
auto chunk = std::string{text.substr(open, pos - open)};
{ // unescape chunk string
auto last_it = std::remove_if(std::begin(chunk), std::end(chunk), [escape = false](const auto& e) mutable {
escape = !escape && e == '\\';
return escape;
});
{ // unescape chunk string
auto last_it = std::remove_if(
std::begin(chunk),
std::end(chunk),
[escape = false, prev = ' '](const auto& e) mutable {
escape = !escape && prev != '\'' && e == '\\';
prev = e;
return escape;
}
);
chunk.erase(last_it, std::end(chunk));
}

Expand Down

0 comments on commit dc7e10c

Please sign in to comment.