Fix bug in section writing

This commit is contained in:
2025-02-01 09:40:45 +01:00
parent a51974d8b0
commit b0e398a6e6
2 changed files with 11 additions and 8 deletions

View File

@@ -197,7 +197,7 @@ namespace minipp
private: private:
static std::unique_ptr<Value> ParseValue(std::string value); static std::unique_ptr<Value> ParseValue(std::string value);
static minipp::EResult WriteSection(const Section* section, std::ofstream& ofs) noexcept; static minipp::EResult WriteSection(const Section* section, std::ofstream& ofs, const std::string& partTreeName) noexcept;
public: public:
EResult Parse(const std::string& path) noexcept; EResult Parse(const std::string& path) noexcept;
@@ -695,7 +695,7 @@ std::unique_ptr<minipp::MiniPPFile::Value> minipp::MiniPPFile::ParseValue(std::s
} }
} }
minipp::EResult minipp::MiniPPFile::WriteSection(const Section* section, std::ofstream& ofs) noexcept minipp::EResult minipp::MiniPPFile::WriteSection(const Section* section, std::ofstream& ofs, const std::string& partTreeName) noexcept
{ {
if (section->m_values.size() > 0) if (section->m_values.size() > 0)
{ {
@@ -731,8 +731,11 @@ minipp::EResult minipp::MiniPPFile::WriteSection(const Section* section, std::of
for (const auto& comment : pair.second->m_comments) for (const auto& comment : pair.second->m_comments)
ofs << comment << std::endl; ofs << comment << std::endl;
ofs << "[" << pair.first << "]" << std::endl; ofs << "[";
auto result = WriteSection(pair.second, ofs); if (!partTreeName.empty())
ofs << partTreeName << ".";
ofs << pair.first << "]" << std::endl;
auto result = WriteSection(pair.second, ofs, (partTreeName.empty() ? "" : (partTreeName + ".")) + pair.first);
if (!IsResultOk(result)) if (!IsResultOk(result))
return result; return result;
} }
@@ -858,7 +861,7 @@ void minipp::MiniPPFile::Write(const std::string& path) const noexcept
if (!ofs.is_open()) if (!ofs.is_open())
return; return;
WriteSection(&m_rootSection, ofs); WriteSection(&m_rootSection, ofs, "");
} }
bool minipp::MiniPPFile::IsResultOk(EResult result) noexcept bool minipp::MiniPPFile::IsResultOk(EResult result) noexcept

View File

@@ -8,12 +8,12 @@ is_completed = false
# This section is about # This section is about
# the settings of a game window # the settings of a game window
[window] [game.window]
dimensions = [1280, 720] dimensions = [1280, 720]
close_flags = 101011b close_flags = 101011b
hex_test = deadbeefh hex_test = deadbeefh
[platform] [game.window.platform]
targets = ["win32", "macOS", "linux"] targets = ["win32", "macOS", "linux"]
points = [[0, 0], [1, 0], [1, 1], [0, 1]] points = [[0, 0], [1, 0], [1, 1], [0, 1]]