# HG changeset patch # User František Kučera # Date 1607874445 -3600 # Node ID bda9d3c83cb7eab51a3004b89478b87aade92b15 # Parent a823b1aaf1f629bdfc97712bdf37cbd186397768 improved basic escaping diff -r a823b1aaf1f6 -r bda9d3c83cb7 src/BasicEscapingProcessor.h --- a/src/BasicEscapingProcessor.h Sat Dec 12 23:09:50 2020 +0100 +++ b/src/BasicEscapingProcessor.h Sun Dec 13 16:47:25 2020 +0100 @@ -34,14 +34,20 @@ relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override { std::wstringstream result; + bool isKey = textType == TextType::EntryKey || textType == TextType::EntrySubKey; + bool isSection = textType == TextType::SectionName || textType == TextType::SectionTag; + bool isComment = textType == TextType::EntryComment || textType == TextType::SectionComment || textType == TextType::StandaloneComment; + for (auto ch : s) { if (ch == L'\\') result.put(ESC).put(ESC); else if (ch == L'\n') result.put(ESC).put(L'n'); else if (ch == L'\r'); - else if (ch == L'\t') result.put(ESC).put(L't'); + else if (isComment) result.put(ch); else if (ch == L'"' && quotingType != QuotingType::Apostrophes) result.put(ESC).put(ch); else if (ch == L'\'' && quotingType != QuotingType::Quotes) result.put(ESC).put(ch); - else if (ch == L'=' && quotingType == QuotingType::None) result.put(ESC).put(ch); + else if (ch == L'=' && quotingType == QuotingType::None && isKey) result.put(ESC).put(ch); + else if (ch == L'[' && quotingType == QuotingType::None && (isKey || isSection)) result.put(ESC).put(ch); + else if (ch == L']' && quotingType == QuotingType::None && (isKey || isSection)) result.put(ESC).put(ch); else result.put(ch); } diff -r a823b1aaf1f6 -r bda9d3c83cb7 src/INIDispatchHandler.h --- a/src/INIDispatchHandler.h Sat Dec 12 23:09:50 2020 +0100 +++ b/src/INIDispatchHandler.h Sun Dec 13 16:47:25 2020 +0100 @@ -85,6 +85,7 @@ public: INIDispatchHandler(std::ostream& output, Configuration& configuration) : output(output), writer(output), configuration(configuration) { + // TODO: dialects might be moved to configuration (after switching to alt2xml writers) writer.addDialect(std::make_shared(), dialect::JavaProperties, false); writer.addDialect(std::make_shared(), dialect::JavaManifestMF, false); writer.addEscapingProcessor(std::make_shared(), escaping::Basic, true);