diff -r d70ea23682aa -r fb717cfbfea1 src/INICommand.cpp --- a/src/INICommand.cpp Sun Nov 22 19:22:25 2020 +0100 +++ b/src/INICommand.cpp Mon Nov 23 16:25:57 2020 +0100 @@ -73,6 +73,7 @@ if (configuration.enableSubKeys) metadata.push_back({L"sub_key", TypeId::STRING}); metadata.push_back({L"value", TypeId::STRING}); if (configuration.enableComments) metadata.push_back({L"comment", TypeId::STRING}); + if (configuration.enableWhitespace) metadata.push_back({L"whitespace", TypeId::STRING}); writer->startRelation(configuration.relation, metadata, true); }; @@ -102,9 +103,47 @@ writer->writeAttribute(convertor.from_bytes(event.value)); if (configuration.enableComments) writer->writeAttribute(convertor.from_bytes(event.comment)); + if (configuration.enableWhitespace) writer->writeAttribute(L""); }; - // TODO: handle also comments and whitespace (to allow lossless transformation from INI and back to INI) + void comment(const CommentEvent& event) override { + if (configuration.enableComments) { + if (configuration.enableLineNumbers) writer->writeAttribute(&event.lineNumber, typeid (event.lineNumber)); + if (configuration.enableEventNumbers) writer->writeAttribute(&event.eventNumber, typeid (event.eventNumber)); + + std::string section = getCurrentSectionFullName(); + std::string key; + + if (configuration.enableSections) writer->writeAttribute(convertor.from_bytes(section)); + else if (section.size()) key = section + "/"; + writer->writeAttribute(convertor.from_bytes(key)); + + if (configuration.enableSubKeys) writer->writeAttribute(L""); + writer->writeAttribute(L""); // value + writer->writeAttribute(convertor.from_bytes(event.comment)); + if (configuration.enableWhitespace) writer->writeAttribute(L""); + } + } + + void whitespace(const WhitespaceEvent& event) override { + if (configuration.enableWhitespace) { + if (configuration.enableLineNumbers) writer->writeAttribute(&event.lineNumber, typeid (event.lineNumber)); + if (configuration.enableEventNumbers) writer->writeAttribute(&event.eventNumber, typeid (event.eventNumber)); + + std::string section = getCurrentSectionFullName(); + std::string key; + + if (configuration.enableSections) writer->writeAttribute(convertor.from_bytes(section)); + else if (section.size()) key = section + "/"; + writer->writeAttribute(convertor.from_bytes(key)); + + if (configuration.enableSubKeys) writer->writeAttribute(L""); + writer->writeAttribute(L""); // value + if (configuration.enableComments) writer->writeAttribute(L""); + writer->writeAttribute(convertor.from_bytes(event.whitespace)); + } + } + // TODO: unify methods, DRY };