diff -r 3876a9c56a66 -r f031a4dc7c52 src/INICommand.cpp --- a/src/INICommand.cpp Sat Nov 21 20:09:18 2020 +0100 +++ b/src/INICommand.cpp Sun Nov 22 00:44:00 2020 +0100 @@ -66,10 +66,13 @@ void startDocument() override { vector metadata; - metadata.push_back({L"section", TypeId::STRING}); + if (configuration.enableLineNumbers) metadata.push_back({L"line", TypeId::INTEGER}); + if (configuration.enableEventNumbers) metadata.push_back({L"event", TypeId::INTEGER}); + if (configuration.enableSections) metadata.push_back({L"section", TypeId::STRING}); metadata.push_back({L"key", TypeId::STRING}); - metadata.push_back({L"subkey", TypeId::STRING}); + if (configuration.enableSubkeys) metadata.push_back({L"subkey", TypeId::STRING}); metadata.push_back({L"value", TypeId::STRING}); + if (configuration.enableComments) metadata.push_back({L"comment", TypeId::STRING}); writer->startRelation(configuration.relation, metadata, true); }; @@ -77,23 +80,31 @@ currentSection.clear(); }; - void startSection(const std::string& name) override { - currentSection.push_back(name); + void startSection(const SectionStartEvent& event) override { + currentSection.push_back(event.name); }; void endSection() override { currentSection.pop_back(); }; - void entry(const std::string& key, const std::string& subkey, const std::string& value) override { - writer->writeAttribute(convertor.from_bytes(getCurrentSectionFullName())); + void entry(const EntryEvent& event) override { + 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 = configuration.enableSubkeys ? event.key : event.fullKey; + + if (configuration.enableSections) writer->writeAttribute(convertor.from_bytes(section)); + else if (section.size()) key = section + "/" + key; writer->writeAttribute(convertor.from_bytes(key)); - writer->writeAttribute(convertor.from_bytes(subkey)); - writer->writeAttribute(convertor.from_bytes(value)); + if (configuration.enableSubkeys) writer->writeAttribute(convertor.from_bytes(event.subKey)); + + writer->writeAttribute(convertor.from_bytes(event.value)); + if (configuration.enableComments) writer->writeAttribute(convertor.from_bytes(event.comment)); }; // TODO: handle also comments and whitespace (to allow lossless transformation from INI and back to INI) - // TODO: make subkeys (in [] brackets in the key) optional/configurable };