mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 07:42:54 +00:00
Do not expand macros in strings
This commit is contained in:
parent
2af58e5cac
commit
d3519c2f62
@ -559,29 +559,49 @@ bool DefinesStreamProxy::FindNextMacro(const std::string& input, unsigned& input
|
||||
auto wordStart = 0u;
|
||||
auto lastWordEnd = 0u;
|
||||
auto inWord = false;
|
||||
auto inString = false;
|
||||
auto stringEscape = false;
|
||||
|
||||
for (; inputPos < inputSize; inputPos++)
|
||||
{
|
||||
const auto c = input[inputPos];
|
||||
if (!inWord)
|
||||
if (inString)
|
||||
{
|
||||
if (isalpha(c) || c == '_')
|
||||
if (!stringEscape)
|
||||
{
|
||||
wordStart = inputPos;
|
||||
inWord = true;
|
||||
if (c == '"')
|
||||
inString = false;
|
||||
else if (c == '\\')
|
||||
stringEscape = true;
|
||||
}
|
||||
else
|
||||
stringEscape = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isalnum(c) && c != '_')
|
||||
{
|
||||
if (FindMacroForIdentifier(input, wordStart, inputPos, define))
|
||||
{
|
||||
defineStart = wordStart;
|
||||
return true;
|
||||
}
|
||||
if (c == '"')
|
||||
inString = true;
|
||||
|
||||
inWord = false;
|
||||
if (!inWord)
|
||||
{
|
||||
if (isalpha(c) || c == '_')
|
||||
{
|
||||
wordStart = inputPos;
|
||||
inWord = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isalnum(c) && c != '_')
|
||||
{
|
||||
if (FindMacroForIdentifier(input, wordStart, inputPos, define))
|
||||
{
|
||||
defineStart = wordStart;
|
||||
return true;
|
||||
}
|
||||
|
||||
inWord = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,6 +467,22 @@ namespace test::parsing::impl::defines_stream_proxy
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Ensure does not expand macros in strings", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
"#define TEST Wrong",
|
||||
"System.out.println(\"TEST\")",
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
DefinesStreamProxy proxy(&mockStream);
|
||||
|
||||
ExpectLine(&proxy, 1, "");
|
||||
ExpectLine(&proxy, 2, "System.out.println(\"TEST\")");
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Ensure simple if is working with truthy value", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
@ -911,7 +927,7 @@ namespace test::parsing::impl::defines_stream_proxy
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Can use strinizing operator inside sample code", "[parsing][parsingstream]")
|
||||
TEST_CASE("DefinesStreamProxy: Can use stringizing operator inside sample code", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
"#define testMacro(a) System.out.println(#a)",
|
||||
|
Loading…
x
Reference in New Issue
Block a user