diff --git a/minipp/minipp.hpp b/minipp/minipp.hpp index b4bf535..94f7e8e 100644 --- a/minipp/minipp.hpp +++ b/minipp/minipp.hpp @@ -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
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