File tree 1 file changed +19
-2
lines changed
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -379,13 +379,15 @@ auto expand_string_literal(
379
379
" \" " , // end sequence
380
380
string_parts::on_both_ends}; // add opening and closing sequence to generated string
381
381
382
+ bool escape = false ;
382
383
// Now we're on the first character of the string itself
383
384
for (
384
385
;
385
- pos < length && (text[pos] != ' " ' || (text[pos- 1 ] == ' \\ ' && pos>= 2 && text[pos- 2 ] != ' \\ ' ) );
386
+ pos < length && !(!escape && text[pos] == ' " ' );
386
387
++pos
387
388
)
388
389
{
390
+ escape = (text[pos] == ' \\ ' && !escape);
389
391
// Find the next )$
390
392
if (
391
393
text[pos] == ' $'
@@ -426,7 +428,22 @@ auto expand_string_literal(
426
428
427
429
// Then put interpolated chunk into ret
428
430
auto chunk = std::string{text.substr (open , pos - open )};
429
- replace_all (chunk, " \\\" " , " \" " );
431
+ { // unescape chunk string
432
+ auto escape = false ;
433
+ auto from = chunk.begin ();
434
+ auto to = chunk.begin ();
435
+ auto end = chunk.end ();
436
+ for (; from != end && to != end; ++from) {
437
+ if (!escape && *from == ' \\ ' ) {
438
+ escape = true ;
439
+ continue ;
440
+ }
441
+ escape = false ;
442
+ *to = *from;
443
+ ++to;
444
+ }
445
+ chunk.erase (to, end);
446
+ }
430
447
parts.add_code (" cpp2::to_string" + chunk);
431
448
432
449
current_start = pos+1 ;
You can’t perform that action at this time.
0 commit comments