From 4b7a78100d740347f70597f2bac909972e8b8617 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 2 Dec 2021 22:19:48 +0100 Subject: [PATCH] Make defines stream proxy able to accept comma within parameter values that are in parenthesis --- src/Parser/Parsing/Impl/DefinesStreamProxy.cpp | 16 ++++++++++++---- .../Parsing/Impl/DefinesStreamProxyTests.cpp | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp b/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp index 3bbcabc1..8b2e51e3 100644 --- a/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp +++ b/src/Parser/Parsing/Impl/DefinesStreamProxy.cpp @@ -514,10 +514,18 @@ void DefinesStreamProxy::ExtractParametersFromDefineUsage(const ParserLine& line if (c == ',') { - parameterValues.emplace_back(currentValue.str()); - currentValue.clear(); - currentValue.str(std::string()); - valueHasStarted = false; + if (parenthesisDepth > 0) + { + valueHasStarted = true; + currentValue << c; + } + else + { + parameterValues.emplace_back(currentValue.str()); + currentValue.clear(); + currentValue.str(std::string()); + valueHasStarted = false; + } } else if(c == '(') { diff --git a/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp b/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp index ff016c6b..f3d1a968 100644 --- a/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp +++ b/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp @@ -705,6 +705,23 @@ namespace test::parsing::impl::defines_stream_proxy REQUIRE(proxy.Eof()); } + TEST_CASE("DefinesStreamProxy: Ensure can use comma in parenthesis in parameters values", "[parsing][parsingstream]") + { + const std::vector lines + { + "#define someStuff(param1) Hello param1 World", + "someStuff(A sentence with (parenthesis and a , character) and stuff)" + }; + + MockParserLineStream mockStream(lines); + DefinesStreamProxy proxy(&mockStream); + + ExpectLine(&proxy, 1, ""); + ExpectLine(&proxy, 2, "Hello A sentence with (parenthesis and a , character) and stuff World"); + + REQUIRE(proxy.Eof()); + } + TEST_CASE("DefinesStreamProxy: Ensure defines can go over multiple lines", "[parsing][parsingstream]") { const std::vector lines