java .properties escaping v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 12 Dec 2020 23:09:50 +0100
branchv_0
changeset 6 a823b1aaf1f6
parent 5 bee7acb57330
child 7 bda9d3c83cb7
java .properties escaping
src/JavaPropertiesEscapingProcessor.h
--- a/src/JavaPropertiesEscapingProcessor.h	Sat Dec 12 19:52:38 2020 +0100
+++ b/src/JavaPropertiesEscapingProcessor.h	Sat Dec 12 23:09:50 2020 +0100
@@ -17,6 +17,7 @@
 #pragma once
 
 #include <sstream>
+#include <iomanip>
 
 #include <relpipe/common/type/typedefs.h>
 
@@ -34,10 +35,12 @@
 	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;
+
 		for (auto ch : s) {
 			if (ch == L'\\') result.put(ESC).put(ESC);
 			else if (ch == L'\n') result.put(ESC).put(L'n');
-			// TODO: escape unicode
+			else if (ch >= 127 || ((ch == L'=' || ch == L':') && isKey)) result << L"\\u" << std::hex << std::setfill(L'0') << std::setw(4) << (int) ch;
 			else result.put(ch);
 		}