Skip to content

Commit

Permalink
Merge pull request #439 from jpcima/parser-update
Browse files Browse the repository at this point in the history
parser: make opcode values stop at the '<' character
  • Loading branch information
jpcima authored Sep 25, 2020
2 parents 296080b + 6895d44 commit 0910ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/sfizz/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,20 @@ void Parser::processOpcode()
for (size_t valueSize = valueRaw.size(); endPosition < valueSize;) {
size_t i = endPosition + 1;

if (isSpaceChar(valueRaw[endPosition])) {
// check if the rest of the string is to consume or not
bool stop = false;
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
while (i < valueSize && isSpaceChar(valueRaw[i]))
++i;

// if there aren't non-space characters following, do not extract
if (i == valueSize)
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] == '#')
stop = true;
// if sequence of identifier chars and then "=", an opcode follows
Expand All @@ -319,11 +321,11 @@ void Parser::processOpcode()
if (i < valueSize && valueRaw[i] == '=')
stop = true;
}

if (stop)
break;
}

if (stop)
break;

endPosition = i;
}

Expand Down
7 changes: 4 additions & 3 deletions tests/ParsingT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,15 @@ TEST_CASE("[Parsing] Opcode value special character")
R"(<region>
sample=Alto-Flute-sus-C#4-PB-loop.wav
<region>
sample=foo=bar<quux.wav)");
sample=foo=bar<group>)");

std::vector<std::vector<sfz::Opcode>> expectedMembers = {
{{"sample", "Alto-Flute-sus-C#4-PB-loop.wav"}},
{{"sample", "foo=bar<quux.wav"}},
{{"sample", "foo=bar"}},
{},
};
std::vector<std::string> expectedHeaders = {
"region", "region"
"region", "region", "group"
};
std::vector<sfz::Opcode> expectedOpcodes;

Expand Down

0 comments on commit 0910ae8

Please sign in to comment.