src/BasicEscapingProcessor.h
branchv_0
changeset 7 bda9d3c83cb7
parent 4 372b161669e4
equal deleted inserted replaced
6:a823b1aaf1f6 7:bda9d3c83cb7
    32 public:
    32 public:
    33 
    33 
    34 	relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override {
    34 	relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override {
    35 		std::wstringstream result;
    35 		std::wstringstream result;
    36 
    36 
       
    37 		bool isKey = textType == TextType::EntryKey || textType == TextType::EntrySubKey;
       
    38 		bool isSection = textType == TextType::SectionName || textType == TextType::SectionTag;
       
    39 		bool isComment = textType == TextType::EntryComment || textType == TextType::SectionComment || textType == TextType::StandaloneComment;
       
    40 
    37 		for (auto ch : s) {
    41 		for (auto ch : s) {
    38 			if (ch == L'\\') result.put(ESC).put(ESC);
    42 			if (ch == L'\\') result.put(ESC).put(ESC);
    39 			else if (ch == L'\n') result.put(ESC).put(L'n');
    43 			else if (ch == L'\n') result.put(ESC).put(L'n');
    40 			else if (ch == L'\r');
    44 			else if (ch == L'\r');
    41 			else if (ch == L'\t') result.put(ESC).put(L't');
    45 			else if (isComment) result.put(ch);
    42 			else if (ch == L'"' && quotingType != QuotingType::Apostrophes) result.put(ESC).put(ch);
    46 			else if (ch == L'"' && quotingType != QuotingType::Apostrophes) result.put(ESC).put(ch);
    43 			else if (ch == L'\'' && quotingType != QuotingType::Quotes) result.put(ESC).put(ch);
    47 			else if (ch == L'\'' && quotingType != QuotingType::Quotes) result.put(ESC).put(ch);
    44 			else if (ch == L'=' && quotingType == QuotingType::None) result.put(ESC).put(ch);
    48 			else if (ch == L'=' && quotingType == QuotingType::None && isKey) result.put(ESC).put(ch);
       
    49 			else if (ch == L'[' && quotingType == QuotingType::None && (isKey || isSection)) result.put(ESC).put(ch);
       
    50 			else if (ch == L']' && quotingType == QuotingType::None && (isKey || isSection)) result.put(ESC).put(ch);
    45 			else result.put(ch);
    51 			else result.put(ch);
    46 		}
    52 		}
    47 
    53 
    48 		return result.str();
    54 		return result.str();
    49 	}
    55 	}