mirror of
https://github.com/mariiaan/minipp.git
synced 2026-05-14 10:11:17 +02:00
Allow nested section names in SetSubSection
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -801,17 +802,33 @@ 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())
|
||||
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);
|
||||
}
|
||||
|
||||
if (rest.empty())
|
||||
{
|
||||
if (m_subSections.find(thisName) != m_subSections.end())
|
||||
if (!allowOverwrite)
|
||||
return EResult::SectionAlreadyPresent;
|
||||
else
|
||||
delete m_subSections[name];
|
||||
|
||||
m_subSections[name] = value.release();
|
||||
delete m_subSections[thisName];
|
||||
|
||||
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
|
||||
{
|
||||
if (section->m_values.size() > 0)
|
||||
|
||||
Reference in New Issue
Block a user