From a518dcac54a2432c2ffd80a676996c2ef2a1425f Mon Sep 17 00:00:00 2001 From: "Marian W." Date: Thu, 6 Feb 2025 04:51:20 +0100 Subject: [PATCH] Fixed issue where ParseValue does not return the result code --- minipp/minipp.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/minipp/minipp.hpp b/minipp/minipp.hpp index 2d6510d..9443501 100644 --- a/minipp/minipp.hpp +++ b/minipp/minipp.hpp @@ -58,6 +58,7 @@ namespace minipp KeyValuePairNotInSection = -23, ExpectedKeyValuePair = -24, KeyEmpty = -25, + MissingQuote = -26, /* OK Codes */ Success = +1, @@ -335,19 +336,21 @@ namespace minipp std::unique_ptr minipp::MiniPPFile::Value::ParseValue(std::string value, EResult* result) { +#define RETURN_NULLPTR_WITH_RESULT(r) { if (result != nullptr) *result = r; return nullptr; } + char valueFirstChar = value.front(); char valueLastChar = value.back(); if (valueFirstChar == '"') { if (valueLastChar != '"') - return nullptr; + RETURN_NULLPTR_WITH_RESULT(EResult::MissingQuote); // is string value = value.substr(1, value.size() - 2); auto strValue = std::make_unique(); auto parseResult = strValue->Parse(value); if (!IsResultOk(parseResult)) - return nullptr; + RETURN_NULLPTR_WITH_RESULT(parseResult); return strValue; } @@ -356,7 +359,7 @@ std::unique_ptr minipp::MiniPPFile::Value::ParseValue auto boolValue = std::make_unique(); auto parseResult = boolValue->Parse(value); if (!IsResultOk(parseResult)) - return nullptr; + RETURN_NULLPTR_WITH_RESULT(parseResult); return boolValue; } @@ -365,7 +368,7 @@ std::unique_ptr minipp::MiniPPFile::Value::ParseValue auto floatValue = std::make_unique(); auto parseResult = floatValue->Parse(value); if (!IsResultOk(parseResult)) - return nullptr; + RETURN_NULLPTR_WITH_RESULT(parseResult); return floatValue; } @@ -374,7 +377,7 @@ std::unique_ptr minipp::MiniPPFile::Value::ParseValue auto arrayValue = std::make_unique(); auto parseResult = arrayValue->Parse(value); if (!IsResultOk(parseResult)) - return nullptr; + RETURN_NULLPTR_WITH_RESULT(parseResult); return arrayValue; } @@ -383,7 +386,7 @@ std::unique_ptr minipp::MiniPPFile::Value::ParseValue auto intValue = std::make_unique(); auto parseResult = intValue->Parse(value); if (!IsResultOk(parseResult)) - return nullptr; + RETURN_NULLPTR_WITH_RESULT(parseResult); return intValue; }