Skip to content

Commit

Permalink
string interpolation is only via Send(, not Get(.
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed May 26, 2024
1 parent 1d38027 commit 24ec087
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/TypeHandlers/TH_Tokenized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace tivars

bool isInCustomName = false; // after a "prgm" or ʟ token (
bool isWithinString = false;
bool inEvaluatedString = false;
bool inEvaluatedString = false; // CE OS 5.2 added string interpolation with eval() for TI-Innovator commands
uint16_t lastTokenBytes = 0;

for (size_t strCursorPos = 0; strCursorPos < str_new.length(); strCursorPos++)
Expand All @@ -69,7 +69,7 @@ namespace tivars
isInCustomName = true;
} else if(currChar == "\"") {
isWithinString = !isWithinString;
inEvaluatedString = isWithinString && (lastTokenBytes == 0xE7 || lastTokenBytes == 0xE8); // Send( and Get(
inEvaluatedString = isWithinString && lastTokenBytes == 0xE7; // Send(
} else if(currChar == "\n" || (strCursorPos < str_new.length()-strlen("") && memcmp(&str_new[strCursorPos], "", strlen("")) == 0)) {
isInCustomName = false;
isWithinString = false;
Expand Down
11 changes: 11 additions & 0 deletions tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ int main(int argc, char** argv)
string detok_en = testPrgm.getReadableContent({{"lang", LANG_EN}});
assert(detok_en == R"(Disp "WHITE,ʟWHITE,prgmWHITE",WHITE,ʟWHITE:prgmWHITE:prgmABCDEF)");
assert(detok_fr == R"(Disp "WHITE,ʟWHITE,prgmWHITE",BLANC,ʟWHITE:prgmWHITE:prgmABCDEF)");
// While this is visually fine, the "prgm" inside the token should probably be the token, not p r g m ...
}

{
// Test tokenization exceptions in an interpolated string
TIVarFile testPrgm = TIVarFile::createNew("Program", "FOOBAR");
testPrgm.setContentFromString(R"(Send("SET SOUND eval(A and prgmWHITE) TIME 2)");
string detok_fr = testPrgm.getReadableContent({{"lang", LANG_FR}});
string detok_en = testPrgm.getReadableContent({{"lang", LANG_EN}});
assert(detok_en == R"(Send("SET SOUND eval(A and prgmWHITE) TIME 2)");
assert(detok_fr == R"(Envoi("SET SOUND eval(A et prgmWHITE) TIME 2)");
}

{
Expand Down

0 comments on commit 24ec087

Please sign in to comment.