mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
String escape
This commit is contained in:
parent
7d7ad6ba46
commit
5a6912fe75
2 changed files with 14 additions and 4 deletions
|
@ -1480,14 +1480,24 @@ struct Compiler
|
|||
|
||||
void compileExprInterpString(AstExprInterpString* expr, uint8_t target, bool targetTemp)
|
||||
{
|
||||
// INTERP TODO: percent sign escape
|
||||
std::string formatString;
|
||||
|
||||
unsigned int stringsLeft = expr->strings.size;
|
||||
|
||||
for (AstArray<char> const& string : expr->strings)
|
||||
{
|
||||
formatString += string.data;
|
||||
std::string stringEscaped(string.data);
|
||||
|
||||
for (size_t characterIndex = 0; characterIndex < stringEscaped.size(); ++characterIndex)
|
||||
{
|
||||
if (stringEscaped[characterIndex] == '%')
|
||||
{
|
||||
stringEscaped.insert(characterIndex, 1, '%');
|
||||
characterIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
formatString += stringEscaped;
|
||||
|
||||
stringsLeft--;
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ assertEq(`Hello {`from inside {"a nested string"}`}`, "Hello from inside a neste
|
|||
|
||||
assertEq(`1 {`2 {`3 {4}`}`}`, "1 2 3 4")
|
||||
|
||||
-- local health = 50
|
||||
-- assert(`You have {health}% health` == "You have 50% health")
|
||||
local health = 50
|
||||
assert(`You have {health}% health` == "You have 50% health")
|
||||
|
||||
-- INTERP TODO: Test with shadowing `string` (both as a string and not)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue