From 6895d44cec92feb472b6009411e8d9c9534df93d Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Fri, 25 Sep 2020 04:08:57 +0200 Subject: [PATCH] parser: make opcode values stop at the '<' character --- src/sfizz/parser/Parser.cpp | 18 ++++++++++-------- tests/ParsingT.cpp | 7 ++++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sfizz/parser/Parser.cpp b/src/sfizz/parser/Parser.cpp index 071bc1e2..9ed460c2 100644 --- a/src/sfizz/parser/Parser.cpp +++ b/src/sfizz/parser/Parser.cpp @@ -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 @@ -319,11 +321,11 @@ void Parser::processOpcode() if (i < valueSize && valueRaw[i] == '=') stop = true; } - - if (stop) - break; } + if (stop) + break; + endPosition = i; } diff --git a/tests/ParsingT.cpp b/tests/ParsingT.cpp index a1e12266..1224b46c 100644 --- a/tests/ParsingT.cpp +++ b/tests/ParsingT.cpp @@ -673,14 +673,15 @@ TEST_CASE("[Parsing] Opcode value special character") R"( sample=Alto-Flute-sus-C#4-PB-loop.wav -sample=foo=bar)"); std::vector> expectedMembers = { {{"sample", "Alto-Flute-sus-C#4-PB-loop.wav"}}, - {{"sample", "foo=bar expectedHeaders = { - "region", "region" + "region", "region", "group" }; std::vector expectedOpcodes;