mirror of
https://github.com/mariiaan/minipp.git
synced 2026-05-14 10:11:17 +02:00
Improve error handling
This commit is contained in:
@@ -851,9 +851,9 @@ minipp::EResult minipp::MiniPPFile::Parse(const std::string& path) noexcept
|
||||
PP_COUT_SYNTAX_ERROR(lineCounter, "Expected ']' at the end of the line.");
|
||||
return EResult::FormatError;
|
||||
}
|
||||
std::string sectionName = currentLine.substr(1, currentLine.size() - 2);
|
||||
Tools::StringTrim(sectionName);
|
||||
if (sectionName.empty())
|
||||
std::string sectionPathStr = currentLine.substr(1, currentLine.size() - 2);
|
||||
Tools::StringTrim(sectionPathStr);
|
||||
if (sectionPathStr.empty())
|
||||
{
|
||||
PP_COUT_SYNTAX_ERROR(lineCounter, "Expected section path. Found empty section begin notation.");
|
||||
return EResult::FormatError;
|
||||
@@ -861,7 +861,7 @@ minipp::EResult minipp::MiniPPFile::Parse(const std::string& path) noexcept
|
||||
// Create section tree
|
||||
Section* ubSection = &m_rootSection;
|
||||
|
||||
std::vector<std::string> sectionPath = Tools::SplitByDelimiter(sectionName, '.');
|
||||
std::vector<std::string> sectionPath = Tools::SplitByDelimiter(sectionPathStr, '.');
|
||||
EResult result;
|
||||
for (size_t i = 0; i < sectionPath.size(); ++i)
|
||||
{
|
||||
@@ -907,6 +907,12 @@ minipp::EResult minipp::MiniPPFile::Parse(const std::string& path) noexcept
|
||||
PP_COUT_SYNTAX_ERROR(lineCounter, "Expected key in line.");
|
||||
return EResult::FormatError;
|
||||
}
|
||||
if (!Tools::IsNameValid(keyValuePair.first))
|
||||
{
|
||||
PP_COUT_SYNTAX_ERROR(lineCounter, "Invalid key name. (\"" << keyValuePair.first << "\") May only contain [a - z][A - Z][0 - 9] and _.");
|
||||
return EResult::FormatError;
|
||||
}
|
||||
|
||||
if (keyValuePair.second.empty())
|
||||
{
|
||||
PP_COUT_SYNTAX_ERROR(lineCounter, "Empty keys are not allowed");
|
||||
@@ -921,7 +927,12 @@ minipp::EResult minipp::MiniPPFile::Parse(const std::string& path) noexcept
|
||||
parsedValue->m_comments = commentBuffer;
|
||||
commentBuffer.clear();
|
||||
|
||||
currentSection->SetValue(keyValuePair.first, std::move(parsedValue), false);
|
||||
auto valueSetResult = currentSection->SetValue(keyValuePair.first, std::move(parsedValue), false);
|
||||
if (valueSetResult != EResult::Success)
|
||||
{
|
||||
PP_COUT_SYNTAX_ERROR(lineCounter, "Key already present: " << keyValuePair.first);
|
||||
return valueSetResult;
|
||||
}
|
||||
}
|
||||
|
||||
return EResult::Success;
|
||||
@@ -993,6 +1004,7 @@ bool minipp::MiniPPFile::Tools::IsNameValid(const std::string& name) noexcept
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ year = 2025
|
||||
completionPercentage = 50.0f
|
||||
# Should only be true if completionPercentage is 100
|
||||
is_completed = false
|
||||
testargs = ["this is a \"test\"", "this is\n the next line"]
|
||||
testargs = ["this is a \\\"test\"", "this is\n the next line"]
|
||||
testTestArg = [["yeah", "new\nline"], ["hallo\ttest\n\\\\"]]
|
||||
|
||||
# This section is about
|
||||
# the settings of a game window
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
[game]
|
||||
name = "Test Game\nNext Line"
|
||||
testTestArg = [["yeah", "new\nline"], ["hallo\ttest\n\\\\"]]
|
||||
completionPercentage = 50.000000
|
||||
version = "1.0.0"
|
||||
testargs = ["this is a \"test\"", "this is\n the next line"]
|
||||
testargs = ["this is a \\\"test\"", "this is\n the next line"]
|
||||
year = 2025
|
||||
# Should only be true if completionPercentage is 100
|
||||
is_completed = false
|
||||
|
||||
Reference in New Issue
Block a user