src/JavaPropertiesEscapingProcessor.h
branchv_0
changeset 6 a823b1aaf1f6
parent 3 ae8775e0bc7a
equal deleted inserted replaced
5:bee7acb57330 6:a823b1aaf1f6
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    16  */
    17 #pragma once
    17 #pragma once
    18 
    18 
    19 #include <sstream>
    19 #include <sstream>
       
    20 #include <iomanip>
    20 
    21 
    21 #include <relpipe/common/type/typedefs.h>
    22 #include <relpipe/common/type/typedefs.h>
    22 
    23 
    23 #include "EscapingProcessor.h"
    24 #include "EscapingProcessor.h"
    24 
    25 
    32 public:
    33 public:
    33 
    34 
    34 	relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override {
    35 	relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override {
    35 		std::wstringstream result;
    36 		std::wstringstream result;
    36 
    37 
       
    38 		bool isKey = textType == TextType::EntryKey || textType == TextType::EntrySubKey;
       
    39 
    37 		for (auto ch : s) {
    40 		for (auto ch : s) {
    38 			if (ch == L'\\') result.put(ESC).put(ESC);
    41 			if (ch == L'\\') result.put(ESC).put(ESC);
    39 			else if (ch == L'\n') result.put(ESC).put(L'n');
    42 			else if (ch == L'\n') result.put(ESC).put(L'n');
    40 			// TODO: escape unicode
    43 			else if (ch >= 127 || ((ch == L'=' || ch == L':') && isKey)) result << L"\\u" << std::hex << std::setfill(L'0') << std::setw(4) << (int) ch;
    41 			else result.put(ch);
    44 			else result.put(ch);
    42 		}
    45 		}
    43 
    46 
    44 		return result.str();
    47 		return result.str();
    45 	}
    48 	}