# HG changeset patch # User František Kučera # Date 1606387315 -3600 # Node ID a8c1381ef103ccce6424f63e9155a3a39cc102b1 # Parent 4b1612d20cb2f76b73e497a9892a17e8e6442ee3 unescape also Java .properties encoding (\uXXXX): unescape also comments diff -r 4b1612d20cb2 -r a8c1381ef103 src/lib/JavaPropertiesUnescapingINIHandler.h --- a/src/lib/JavaPropertiesUnescapingINIHandler.h Thu Nov 26 00:38:44 2020 +0100 +++ b/src/lib/JavaPropertiesUnescapingINIHandler.h Thu Nov 26 11:41:55 2020 +0100 @@ -94,7 +94,7 @@ public: - JavaPropertiesUnescapingINIContentHandler(INIContentHandler& output, bool lastEscaphingPhase) : UnescapingINIContentHandler(output, lastEscaphingPhase) { + JavaPropertiesUnescapingINIContentHandler(INIContentHandler& output, bool lastEscaphingPhase) : UnescapingINIContentHandler(output, lastEscaphingPhase, true) { } }; diff -r 4b1612d20cb2 -r a8c1381ef103 src/lib/UnescapingINIHandler.h --- a/src/lib/UnescapingINIHandler.h Thu Nov 26 00:38:44 2020 +0100 +++ b/src/lib/UnescapingINIHandler.h Thu Nov 26 11:41:55 2020 +0100 @@ -31,6 +31,7 @@ class UnescapingINIContentHandler : public INIContentHandler { private: INIContentHandler& output; + bool unescapeComments; protected: const char ESC = '\\'; @@ -53,7 +54,7 @@ * in the last phase, all remaining sequences (including \\) must be recognized and unescaped * (otherwise the input is considered invalid and an exception is thrown) */ - UnescapingINIContentHandler(INIContentHandler& output, bool lastEscaphingPhase) : output(output), lastEscaphingPhase(lastEscaphingPhase) { + UnescapingINIContentHandler(INIContentHandler& output, bool lastEscaphingPhase, bool unescapeComments = false) : output(output), lastEscaphingPhase(lastEscaphingPhase), unescapeComments(unescapeComments) { } void startDocument() override { @@ -67,6 +68,7 @@ void startSection(const SectionStartEvent& event) override { SectionStartEvent e = event; e.name = unescape(e.name); + if (unescapeComments) e.comment = unescape(e.comment); output.startSection(e); } @@ -80,12 +82,18 @@ e.fullKey = unescape(e.fullKey); e.subKey = unescape(e.subKey); e.value = unescape(e.value); + if (unescapeComments) e.comment = unescape(e.comment); output.entry(e); } void comment(const CommentEvent& event) override { - // TODO: optionally unescape also comments (e.g. Java .properties) - output.comment(event); + if (unescapeComments) { + CommentEvent e = event; + e.comment = unescape(e.comment); + output.comment(e); + } else { + output.comment(event); + } } void whitespace(const WhitespaceEvent& event) override {