--- a/src/XMLDocumentConstructor.h Sun Nov 22 19:25:42 2020 +0100
+++ b/src/XMLDocumentConstructor.h Mon Nov 23 16:25:39 2020 +0100
@@ -67,15 +67,33 @@
entry->set_attribute("key", event.key);
entry->set_attribute("full-key", event.fullKey);
if (event.subKey.size()) entry->set_attribute("sub-key", event.subKey);
- if (event.comment.size()) currentSection->set_attribute("comment", event.comment);
- if (event.lineNumber >= 0) currentSection->set_attribute("line-number", std::to_string(event.lineNumber));
- if (event.eventNumber >= 0) currentSection->set_attribute("event-number", std::to_string(event.eventNumber));
+ if (event.comment.size()) entry->set_attribute("comment", event.comment);
+ if (event.lineNumber >= 0) entry->set_attribute("line-number", std::to_string(event.lineNumber));
+ if (event.eventNumber >= 0) entry->set_attribute("event-number", std::to_string(event.eventNumber));
entry->add_child_text(event.value);
};
+ void comment(const CommentEvent& event) override {
+ xmlpp::Element* comment = currentSection->add_child("comment");
+ comment->set_attribute("type", "comment");
+ if (event.lineNumber >= 0) comment->set_attribute("line-number", std::to_string(event.lineNumber));
+ if (event.eventNumber >= 0) comment->set_attribute("event-number", std::to_string(event.eventNumber));
+ comment->add_child_text(event.comment);
+ }
+
+ void whitespace(const WhitespaceEvent& event) override {
+ xmlpp::Element* comment = currentSection->add_child("whitespace");
+ comment->set_attribute("type", "whitespace");
+ if (event.lineNumber >= 0) comment->set_attribute("line-number", std::to_string(event.lineNumber));
+ if (event.eventNumber >= 0) comment->set_attribute("event-number", std::to_string(event.eventNumber));
+ comment->add_child_text(event.whitespace);
+ }
+
};
// TODO: support also other styles/mappings e.g. <section/> and <entry/> with INI names only in the XML attributes (and thus without @type="section|entry")
+// or map INI comments and whitespace to native XML comments and text nodes (but there will be no metadata like line/event numbers)
+// TODO: optional namespaces (xmlns)
class XMLDocumentConstructor {
private: