Merge pull request #439 from jpcima/parser-update

parser: make opcode values stop at the '<' character
This commit is contained in:
JP Cimalando 2020-09-25 13:00:25 +02:00 committed by GitHub
commit 0910ae8ebb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View file

@ -297,18 +297,20 @@ void Parser::processOpcode()
for (size_t valueSize = valueRaw.size(); endPosition < valueSize;) { for (size_t valueSize = valueRaw.size(); endPosition < valueSize;) {
size_t i = endPosition + 1; size_t i = endPosition + 1;
if (isSpaceChar(valueRaw[endPosition])) { bool stop = false;
// check if the rest of the string is to consume or not
bool stop = false;
// if a "<" character is next, a header follows
if (valueRaw[endPosition] == '<')
stop = true;
// if space, check if the rest of the string is to consume or not
else if (isSpaceChar(valueRaw[endPosition])) {
// consume space characters following // consume space characters following
while (i < valueSize && isSpaceChar(valueRaw[i])) while (i < valueSize && isSpaceChar(valueRaw[i]))
++i; ++i;
// if there aren't non-space characters following, do not extract // if there aren't non-space characters following, do not extract
if (i == valueSize) if (i == valueSize)
stop = true; stop = true;
// if a "=" or "<" character is next, a header or a directive follows // if a "<" or "#" character is next, a header or a directive follows
else if (valueRaw[i] == '<' || valueRaw[i] == '#') else if (valueRaw[i] == '<' || valueRaw[i] == '#')
stop = true; stop = true;
// if sequence of identifier chars and then "=", an opcode follows // if sequence of identifier chars and then "=", an opcode follows
@ -319,11 +321,11 @@ void Parser::processOpcode()
if (i < valueSize && valueRaw[i] == '=') if (i < valueSize && valueRaw[i] == '=')
stop = true; stop = true;
} }
if (stop)
break;
} }
if (stop)
break;
endPosition = i; endPosition = i;
} }

View file

@ -673,14 +673,15 @@ TEST_CASE("[Parsing] Opcode value special character")
R"(<region> R"(<region>
sample=Alto-Flute-sus-C#4-PB-loop.wav sample=Alto-Flute-sus-C#4-PB-loop.wav
<region> <region>
sample=foo=bar<quux.wav)"); sample=foo=bar<group>)");
std::vector<std::vector<sfz::Opcode>> expectedMembers = { std::vector<std::vector<sfz::Opcode>> expectedMembers = {
{{"sample", "Alto-Flute-sus-C#4-PB-loop.wav"}}, {{"sample", "Alto-Flute-sus-C#4-PB-loop.wav"}},
{{"sample", "foo=bar<quux.wav"}}, {{"sample", "foo=bar"}},
{},
}; };
std::vector<std::string> expectedHeaders = { std::vector<std::string> expectedHeaders = {
"region", "region" "region", "region", "group"
}; };
std::vector<sfz::Opcode> expectedOpcodes; std::vector<sfz::Opcode> expectedOpcodes;