equal
deleted
inserted
replaced
|
1 /** |
|
2 * Relational pipes |
|
3 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, version 3 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #pragma once |
|
18 |
|
19 #include <sstream> |
|
20 |
|
21 #include <relpipe/common/type/typedefs.h> |
|
22 |
|
23 #include "EscapingProcessor.h" |
|
24 |
|
25 |
|
26 namespace relpipe { |
|
27 namespace out { |
|
28 namespace ini { |
|
29 |
|
30 class BasicEscapingProcessor : public EscapingProcessor { |
|
31 private: |
|
32 public: |
|
33 |
|
34 relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override { |
|
35 std::wstringstream result; |
|
36 |
|
37 for (auto ch : s) { |
|
38 if (ch == L'\\') result.put(ESC).put(ESC); |
|
39 else if (ch == L'\n') result.put(ESC).put(L'n'); |
|
40 else if (ch == L'\r'); |
|
41 else if (ch == L'\t') result.put(ESC).put(L't'); |
|
42 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); |
|
44 else result.put(ch); |
|
45 } |
|
46 |
|
47 return result.str(); |
|
48 } |
|
49 |
|
50 }; |
|
51 |
|
52 } |
|
53 } |
|
54 } |