Allow nested section names in SetSubSection

This commit is contained in:
2025-11-19 01:23:40 +01:00
parent 302b2b9a94
commit 2c2c567616

View File

@@ -675,6 +675,7 @@ minipp::EResult minipp::MiniPPFile::Values::ArrayValue::Parse(const std::string&
{
if (c == '[')
{
// TODO: This would not be allowed by standard. Add EXT_ALLOW_MULTIDIMENSIONAL_ARRAY
if (++bracketCounter > 1)
currentElement += c;
}
@@ -712,7 +713,7 @@ minipp::EResult minipp::MiniPPFile::Values::ArrayValue::Parse(const std::string&
EResult result;
for (auto& elem : elements)
{
{
auto parsed = ParseValue(elem, &result);
if (parsed == nullptr)
return result;
@@ -801,15 +802,31 @@ minipp::EResult minipp::MiniPPFile::Section::GetSubSection(const std::string& ke
minipp::EResult minipp::MiniPPFile::Section::SetSubSection(const std::string& name, std::unique_ptr<Section> value, bool allowOverwrite) noexcept
{
if (m_subSections.find(name) != m_subSections.end())
if (!allowOverwrite)
return EResult::SectionAlreadyPresent;
else
delete m_subSections[name];
auto pathIndex = name.find('.');
std::string thisName = name;
std::string rest{};
if (pathIndex != std::string::npos)
{
thisName = name.substr(0, pathIndex);
rest = name.substr(pathIndex + 1);
}
m_subSections[name] = value.release();
if (rest.empty())
{
if (m_subSections.find(thisName) != m_subSections.end())
if (!allowOverwrite)
return EResult::SectionAlreadyPresent;
else
delete m_subSections[thisName];
return EResult::Success;
m_subSections[thisName] = value.release();
return EResult::Success;
}
if (m_subSections.find(thisName) == m_subSections.end())
m_subSections[thisName] = new Section();
return m_subSections[thisName]->SetSubSection(rest, std::move(value), allowOverwrite);
}
minipp::EResult minipp::MiniPPFile::WriteSection(const Section* section, std::ofstream& ofs, std::string partTreeName) noexcept