mirror of
https://github.com/mariiaan/minipp.git
synced 2026-05-14 10:11:17 +02:00
Fixed issue where ParseValue does not return the result code
This commit is contained in:
@@ -58,6 +58,7 @@ namespace minipp
|
|||||||
KeyValuePairNotInSection = -23,
|
KeyValuePairNotInSection = -23,
|
||||||
ExpectedKeyValuePair = -24,
|
ExpectedKeyValuePair = -24,
|
||||||
KeyEmpty = -25,
|
KeyEmpty = -25,
|
||||||
|
MissingQuote = -26,
|
||||||
|
|
||||||
/* OK Codes */
|
/* OK Codes */
|
||||||
Success = +1,
|
Success = +1,
|
||||||
@@ -335,19 +336,21 @@ namespace minipp
|
|||||||
|
|
||||||
std::unique_ptr<minipp::MiniPPFile::Value> minipp::MiniPPFile::Value::ParseValue(std::string value, EResult* result)
|
std::unique_ptr<minipp::MiniPPFile::Value> 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 valueFirstChar = value.front();
|
||||||
char valueLastChar = value.back();
|
char valueLastChar = value.back();
|
||||||
if (valueFirstChar == '"')
|
if (valueFirstChar == '"')
|
||||||
{
|
{
|
||||||
if (valueLastChar != '"')
|
if (valueLastChar != '"')
|
||||||
return nullptr;
|
RETURN_NULLPTR_WITH_RESULT(EResult::MissingQuote);
|
||||||
|
|
||||||
// is string
|
// is string
|
||||||
value = value.substr(1, value.size() - 2);
|
value = value.substr(1, value.size() - 2);
|
||||||
auto strValue = std::make_unique<Values::StringValue>();
|
auto strValue = std::make_unique<Values::StringValue>();
|
||||||
auto parseResult = strValue->Parse(value);
|
auto parseResult = strValue->Parse(value);
|
||||||
if (!IsResultOk(parseResult))
|
if (!IsResultOk(parseResult))
|
||||||
return nullptr;
|
RETURN_NULLPTR_WITH_RESULT(parseResult);
|
||||||
|
|
||||||
return strValue;
|
return strValue;
|
||||||
}
|
}
|
||||||
@@ -356,7 +359,7 @@ std::unique_ptr<minipp::MiniPPFile::Value> minipp::MiniPPFile::Value::ParseValue
|
|||||||
auto boolValue = std::make_unique<Values::BooleanValue>();
|
auto boolValue = std::make_unique<Values::BooleanValue>();
|
||||||
auto parseResult = boolValue->Parse(value);
|
auto parseResult = boolValue->Parse(value);
|
||||||
if (!IsResultOk(parseResult))
|
if (!IsResultOk(parseResult))
|
||||||
return nullptr;
|
RETURN_NULLPTR_WITH_RESULT(parseResult);
|
||||||
|
|
||||||
return boolValue;
|
return boolValue;
|
||||||
}
|
}
|
||||||
@@ -365,7 +368,7 @@ std::unique_ptr<minipp::MiniPPFile::Value> minipp::MiniPPFile::Value::ParseValue
|
|||||||
auto floatValue = std::make_unique<Values::FloatValue>();
|
auto floatValue = std::make_unique<Values::FloatValue>();
|
||||||
auto parseResult = floatValue->Parse(value);
|
auto parseResult = floatValue->Parse(value);
|
||||||
if (!IsResultOk(parseResult))
|
if (!IsResultOk(parseResult))
|
||||||
return nullptr;
|
RETURN_NULLPTR_WITH_RESULT(parseResult);
|
||||||
|
|
||||||
return floatValue;
|
return floatValue;
|
||||||
}
|
}
|
||||||
@@ -374,7 +377,7 @@ std::unique_ptr<minipp::MiniPPFile::Value> minipp::MiniPPFile::Value::ParseValue
|
|||||||
auto arrayValue = std::make_unique<Values::ArrayValue>();
|
auto arrayValue = std::make_unique<Values::ArrayValue>();
|
||||||
auto parseResult = arrayValue->Parse(value);
|
auto parseResult = arrayValue->Parse(value);
|
||||||
if (!IsResultOk(parseResult))
|
if (!IsResultOk(parseResult))
|
||||||
return nullptr;
|
RETURN_NULLPTR_WITH_RESULT(parseResult);
|
||||||
|
|
||||||
return arrayValue;
|
return arrayValue;
|
||||||
}
|
}
|
||||||
@@ -383,7 +386,7 @@ std::unique_ptr<minipp::MiniPPFile::Value> minipp::MiniPPFile::Value::ParseValue
|
|||||||
auto intValue = std::make_unique<Values::IntValue>();
|
auto intValue = std::make_unique<Values::IntValue>();
|
||||||
auto parseResult = intValue->Parse(value);
|
auto parseResult = intValue->Parse(value);
|
||||||
if (!IsResultOk(parseResult))
|
if (!IsResultOk(parseResult))
|
||||||
return nullptr;
|
RETURN_NULLPTR_WITH_RESULT(parseResult);
|
||||||
|
|
||||||
return intValue;
|
return intValue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user