@@ -69,16 +69,17 @@ bool isStringLiteral(const(char)[] literal, out char stringCloseChar,
69
69
70
70
if (parseEscapes)
71
71
{
72
- // check if end escapes the quote, making this an invalid string
73
- auto end = literal[0 .. $ - 1 ].lastIndexOfNeither(" \\ " );
74
- if (end != - 1 )
72
+ size_t countBackslashes = 0 ;
73
+ foreach_reverse (dchar c; literal[0 .. $ - 1 ])
75
74
{
76
- // don't need to subtract 1
77
- size_t countBackslashes = literal.length - end;
78
-
79
- if ((countBackslashes % 2 ) != 0 )
80
- return false ; // uneven backslash count -> invalid end
75
+ if (c != ' \\ ' )
76
+ break ;
77
+ countBackslashes++ ;
81
78
}
79
+
80
+ // check if end escapes the quote, making this an invalid string
81
+ if ((countBackslashes % 2 ) != 0 )
82
+ return false ; // uneven backslash count -> invalid end
82
83
}
83
84
84
85
return true ;
@@ -98,6 +99,7 @@ bool isStringLiteral(const(char)[] literal)
98
99
unittest
99
100
{
100
101
assert (isStringLiteral(` "hello"` ));
102
+ assert (isStringLiteral(` "ñ"` ));
101
103
assert (isStringLiteral(` "hello world!"` ));
102
104
assert (isStringLiteral(` r"hello world!"c` ));
103
105
assert (isStringLiteral(` r"hello world!"d` ));
@@ -107,6 +109,8 @@ unittest
107
109
assert (! isStringLiteral(` "\\\"` ));
108
110
assert (isStringLiteral(` "\\\\"` ));
109
111
assert (isStringLiteral(` "a\\\\"` ));
112
+ assert (! isStringLiteral(` "ñ\"` ));
113
+ assert (isStringLiteral(` "ñ\\"` ));
110
114
assert (isStringLiteral(` ""` ));
111
115
assert (isStringLiteral(` q""` ));
112
116
assert (isStringLiteral(` x""` ));
@@ -563,6 +567,7 @@ unittest
563
567
assert (unescapeDoubleQuotedContent(` hello\tworld` ) == " hello\t world" );
564
568
assert (unescapeDoubleQuotedContent(` hello\u200bworld` ) == " hello\u200b world" );
565
569
assert (unescapeDoubleQuotedContent(` hello \"\\ok` ) == " hello \"\\ ok" );
570
+ assert (unescapeDoubleQuotedContent(` こんにちは \"\\ñ` ) == " こんにちは \"\\ ñ" );
566
571
}
567
572
568
573
private string parseHexStringContent (
0 commit comments