author | František Kučera <franta-hg@frantovo.cz> |
Sat, 28 Nov 2020 00:46:40 +0100 | |
branch | v_0 |
changeset 26 | b1f6fa3a6555 |
parent 25 | b9067d2812e5 |
child 27 | e9aad9dd823a |
permissions | -rw-r--r-- |
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#include <vector> |
1
3876a9c56a66
simple INI parser based on regular expressions
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
19 |
#include <regex> |
16 | 20 |
#include <sstream> |
21 |
#include <stdexcept> |
|
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include "INIReader.h" |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
|
16 | 25 |
namespace relpipe { |
26 |
namespace in { |
|
27 |
namespace ini { |
|
28 |
namespace lib { |
|
29 |
||
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
class INIReaderImpl : public INIReader { |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
private: |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
std::istream& input; |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
std::vector<INIContentHandler*> handlers; |
16 | 34 |
|
35 |
/** |
|
36 |
* By default, we ignore all leading whitespace on continuing lines. |
|
37 |
* If there should be some spaces or tabs, they should be placed on the previous line before the „\“. |
|
38 |
* If a line break is desired, it should be written as \n (escaped) or the value should be quoted in " or '. |
|
39 |
* |
|
26 | 40 |
* TODO: several options: |
41 |
* - enabled, disabled |
|
42 |
* - if disabled, then: keep backslash, trim backslash, escape backslash |
|
43 |
* (keep requires support in some further unescaping phase, or it will cause an error) |
|
44 |
* - keep or trim the line end |
|
45 |
* - keep or trim the leading spaces |
|
46 |
* - allow comments interleaved with continuing lines (the freaky systemd syntax) |
|
47 |
* |
|
16 | 48 |
* Related specifications: |
49 |
* - https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Properties.html |
|
26 | 50 |
* - https://www.freedesktop.org/software/systemd/man/systemd.syntax.html |
16 | 51 |
*/ |
23
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
52 |
bool trimLeadingSpacesOnContinuingLines = true; |
16 | 53 |
|
24
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
54 |
|
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
55 |
/** |
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
56 |
* Some dialects or configuration files in general does not support sections. |
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
57 |
* Then a line, that looks like an INI section, should be interpreted as a key |
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
58 |
* (or error, if does not have a proper key-value separator). |
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
59 |
*/ |
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
60 |
bool allowSections = true; |
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
61 |
|
16 | 62 |
/** |
63 |
* KDE uses some weird INI dialect that allows [section][x] syntax where „x“ is kind of „tag“ that signalizes some properties of given section. |
|
64 |
* Line „[section_1][$i]“ means that the „section_1“ is „locked“. |
|
65 |
* We may emit this information somehow later, but for now, it is just ignored. |
|
66 |
* |
|
67 |
* TODO: Is „section tag“ right name? |
|
68 |
* |
|
69 |
* Related specifications: |
|
70 |
* - https://userbase.kde.org/KDE_System_Administration/Configuration_Files#Lock_Down |
|
71 |
*/ |
|
72 |
bool allowSectionTags = true; |
|
73 |
||
74 |
/** |
|
75 |
* If whole key is „aaa[bbb]“ then „aaa“ is considered to be the key and „bbb“ the sub-key. |
|
76 |
* No \[ escaping is currently supported, so the key might not contain the bracket character. |
|
77 |
* |
|
78 |
* Related specifications: |
|
79 |
* - https://userbase.kde.org/KDE_System_Administration/Configuration_Files#Shell_Expansion |
|
80 |
* - https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s05.html |
|
81 |
*/ |
|
82 |
bool allowSubKeys = true; |
|
83 |
||
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
84 |
/** |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
85 |
* Classic INI uses „key=value“ syntax. |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
86 |
* But some other formats/dialects might use key:value. |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
87 |
* |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
88 |
* Only single character separators are supported. |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
89 |
* If multiple separators should be recognized (e.g. both „=“ and „:“), this string will contain all of them, |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
90 |
* i.e. „:=“ does not mean that the „key:=value“ syntax, but „key=value“ or „key:value“. |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
91 |
*/ |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
92 |
std::string keyValueSeparators = "="; |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
93 |
|
21
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
94 |
/** |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
95 |
* Classic INI uses „; comment“ syntax. |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
96 |
* But many existing files contain „# comment“ lines. |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
97 |
* |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
98 |
* Only single character separators are supported (works same as keyValueSeparators). |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
99 |
*/ |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
100 |
std::string commentSeparators = ";#"; |
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
101 |
|
22
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
102 |
/** |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
103 |
* INI often support both "quotes" and 'apostrophes' styles. |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
104 |
* But some dialects may support only one of them or not support quoting at all. |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
105 |
* |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
106 |
* In such case e.g. „key="some value"“ would mean that the value is „"value"“ (including the quotes). |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
107 |
* Thus it is important to allow disabling quote recognizing (which is done by setting this parameter to empty string). |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
108 |
* |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
109 |
* Only single character quotes are supported (works same as keyValueSeparators). |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
110 |
*/ |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
111 |
std::string quotes = "\"'"; |
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
112 |
|
16 | 113 |
int lineNumber = 1; |
114 |
int eventNumber = 0; |
|
115 |
||
116 |
/** |
|
117 |
* Should be always used instead of input.peek(). |
|
118 |
* Skips \r. |
|
119 |
*/ |
|
120 |
char peek() { |
|
121 |
// In 2020 there is no need to manually return the carriage. However some legacy systems still do it. |
|
122 |
char ch = input.peek(); |
|
123 |
if (ch == '\r') { |
|
124 |
input.get(); |
|
125 |
ch = input.peek(); |
|
126 |
} |
|
127 |
return ch; |
|
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* Should be always used instead of input.get(). |
|
132 |
* Counts the lines and skips \r. |
|
133 |
*/ |
|
134 |
char get() { |
|
135 |
char ch = input.get(); |
|
136 |
if (ch == '\n') lineNumber++; |
|
137 |
else if (ch == '\r') ch = get(); |
|
138 |
return ch; |
|
139 |
} |
|
140 |
||
141 |
std::string readSpacesAndTabs() { |
|
142 |
std::stringstream result; |
|
143 |
for (char ch = peek(); input.good() && (ch == ' ' || ch == '\t'); ch = peek()) result.put(get()); |
|
144 |
return result.str(); |
|
145 |
} |
|
146 |
||
147 |
std::string readAllWhitespace() { |
|
148 |
std::stringstream result; |
|
149 |
for (char ch = peek(); input.good() && (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); ch = peek()) result.put(get()); |
|
150 |
return result.str(); |
|
151 |
} |
|
152 |
||
153 |
void processContinuingLine(std::stringstream& result) { |
|
23
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
154 |
if (trimLeadingSpacesOnContinuingLines) readSpacesAndTabs(); |
16 | 155 |
else result.put('\n'); |
156 |
} |
|
157 |
||
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
158 |
std::string readUntil(const char until, bool* found = nullptr) { |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
159 |
return readUntil(std::string(1, until), found); |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
160 |
} |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
161 |
|
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
162 |
std::string readUntil(const std::string& until, bool* found = nullptr) { |
16 | 163 |
std::stringstream result; |
164 |
||
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
165 |
for (char ch = peek(); input.good() && !oneOf(ch, until); ch = peek()) { |
16 | 166 |
if (ch == '\\') { |
167 |
get(); |
|
168 |
ch = get(); |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
169 |
if (oneOf(ch, until) && ch == '\n') processContinuingLine(result); |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
170 |
else if (oneOf(ch, until)) result.put(ch); |
16 | 171 |
else if (ch == std::istream::traits_type::eof()) break; |
172 |
else result.put('\\').put(ch); |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
173 |
// unescaping is done in two phases: |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
174 |
// here we unescape just the \n (LF) |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
175 |
// other escape sequences are leaved untouched and will be processed in later phases, see see UnescapingINIHandler |
16 | 176 |
} else { |
177 |
ch = get(); |
|
178 |
result.put(ch); |
|
179 |
} |
|
180 |
} |
|
181 |
||
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
182 |
if (oneOf(peek(), until)) { |
16 | 183 |
get(); |
184 |
if (found) *found = true; |
|
185 |
} else { |
|
186 |
if (found) *found = false; |
|
187 |
} |
|
188 |
||
189 |
return result.str(); |
|
190 |
} |
|
191 |
||
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
192 |
std::string readToken(const char until, char* quote = nullptr, bool* found = nullptr) { |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
193 |
return readToken(std::string(1, until), quote, found); |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
194 |
} |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
195 |
|
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
196 |
std::string readToken(const std::string& until, char* quote = nullptr, bool* found = nullptr) { |
16 | 197 |
std::string result; |
198 |
||
199 |
char ch = peek(); |
|
200 |
if (isQuote(ch)) { |
|
201 |
if (quote) *quote = ch; |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
202 |
result = readUntil(std::string(1, get()), found); |
16 | 203 |
} else { |
204 |
if (quote) *quote = 0; |
|
205 |
result = readUntil(until, found); |
|
206 |
} |
|
207 |
||
208 |
return result; |
|
209 |
} |
|
210 |
||
211 |
std::string readTokenAndEatTerminator(char until, char* quote = nullptr, bool* found = nullptr) { |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
212 |
return readTokenAndEatTerminator(std::string(1, until), quote, found); |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
213 |
} |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
214 |
|
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
215 |
std::string readTokenAndEatTerminator(const std::string& until, char* quote = nullptr, bool* found = nullptr) { |
16 | 216 |
std::string result = readToken(until, quote, found); |
217 |
if (*quote) { |
|
218 |
readAllWhitespace(); |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
219 |
if (!oneOf(get(), until)) throw std::logic_error(std::string("missing „") + until + "“ after quoted section name"); |
16 | 220 |
} |
221 |
return result; |
|
222 |
} |
|
223 |
||
224 |
bool isComment(char ch) { |
|
21
b35baebf5005
prepare for multiple and configurable comment separators (e.g. „; comment“ and „# comment“)
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
225 |
return oneOf(ch, commentSeparators); |
16 | 226 |
} |
227 |
||
228 |
bool isQuote(char ch) { |
|
22
29d673a54ecf
prepare for multiple and configurable quotes (e.g. „key="value"“ and „key='value'“ or disabling quote support at all)
František Kučera <franta-hg@frantovo.cz>
parents:
21
diff
changeset
|
229 |
return oneOf(ch, quotes); |
16 | 230 |
} |
231 |
||
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
232 |
/** |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
233 |
* @param ch character to be evaluated |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
234 |
* @param options list of options (characters) |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
235 |
* @return whether ch is one of options |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
236 |
*/ |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
237 |
bool oneOf(char ch, const std::string& options) { |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
238 |
return options.find(ch) != std::string::npos; |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
239 |
} |
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
240 |
|
16 | 241 |
std::string trim(std::string s) { |
242 |
return std::regex_replace(s, std::regex("^\\s+|\\s+$"), ""); |
|
243 |
} |
|
244 |
||
23
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
245 |
/** |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
246 |
* TODO: use a common method |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
247 |
*/ |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
248 |
bool parseBoolean(const std::string& value) { |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
249 |
if (value == "true") return true; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
250 |
else if (value == "false") return false; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
251 |
else throw std::invalid_argument(std::string("Unable to parse boolean value: ") + value + " (expecting true or false)"); |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
252 |
} |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
253 |
|
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
254 |
void setDialect(const std::string& name) { |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
255 |
if (name == "default-ini") { |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
256 |
// already set |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
257 |
} else if (name == "java-properties") { |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
258 |
trimLeadingSpacesOnContinuingLines = true; |
24
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
259 |
allowSections = false; |
23
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
260 |
allowSectionTags = false; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
261 |
allowSubKeys = false; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
262 |
commentSeparators = "#"; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
263 |
keyValueSeparators = "=:"; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
264 |
quotes = ""; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
265 |
// TODO: enable unicode unescaping |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
266 |
} else { |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
267 |
throw std::invalid_argument(std::string("Unsupported INI dialect: ") + name); |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
268 |
} |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
269 |
} |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
270 |
|
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
271 |
public: |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
272 |
|
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
273 |
INIReaderImpl(std::istream& input) : input(input) { |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
274 |
} |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
275 |
|
23
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
276 |
void setOption(const std::string& uri, const std::string& value) override { |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
277 |
if (uri == "trim-continuing-lines") trimLeadingSpacesOnContinuingLines = parseBoolean(value); // TODO: continuing lines modes (enum), not just boolean |
24
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
278 |
else if (uri == "allow-sections") allowSections = parseBoolean(value); |
23
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
279 |
else if (uri == "allow-section-tags") allowSectionTags = parseBoolean(value); |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
280 |
else if (uri == "allow-sub-keys") allowSubKeys = parseBoolean(value); |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
281 |
else if (uri == "comment-separators") commentSeparators = value; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
282 |
else if (uri == "key-value-separators") keyValueSeparators = value; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
283 |
else if (uri == "quotes") quotes = value; |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
284 |
else if (uri == "dialect") setDialect(value); |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
285 |
else throw std::invalid_argument(std::string("Invalid parser option: „") + uri + "“ with value: „" + value + "“"); |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
286 |
} |
b497140b0b63
enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
287 |
|
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
288 |
void addHandler(INIContentHandler* handler) override { |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
289 |
handlers.push_back(handler); |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
290 |
} |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
291 |
|
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
292 |
void process() override { |
1
3876a9c56a66
simple INI parser based on regular expressions
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
293 |
for (INIContentHandler* handler : handlers) handler->startDocument(); |
3876a9c56a66
simple INI parser based on regular expressions
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
294 |
|
16 | 295 |
bool inSection = false; |
296 |
||
297 |
while (input.good()) { // TODO: condition |
|
298 |
{ |
|
19
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
299 |
INIContentHandler::WhitespaceEvent event; |
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
300 |
event.lineNumber = lineNumber; |
16 | 301 |
std::string whitespace = readAllWhitespace(); |
302 |
if (whitespace.size()) { |
|
303 |
event.eventNumber = ++eventNumber; |
|
304 |
event.whitespace = whitespace; |
|
305 |
for (INIContentHandler* handler : handlers) handler->whitespace(event); |
|
306 |
} |
|
307 |
} |
|
1
3876a9c56a66
simple INI parser based on regular expressions
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
308 |
|
16 | 309 |
bool found; |
310 |
char quote; |
|
311 |
||
312 |
char ch = peek(); |
|
2
f031a4dc7c52
add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
313 |
|
16 | 314 |
if (ch == std::istream::traits_type::eof()) { |
315 |
break; |
|
24
07e0a2edf3bc
add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
316 |
} else if (ch == '[' && allowSections) { |
16 | 317 |
if (inSection) for (INIContentHandler* handler : handlers) handler->endSection(); |
318 |
inSection = true; |
|
319 |
INIContentHandler::SectionStartEvent event; |
|
6
fb717cfbfea1
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
320 |
event.lineNumber = lineNumber; |
fb717cfbfea1
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
321 |
event.eventNumber = ++eventNumber; |
19
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
322 |
get(); |
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
323 |
readAllWhitespace(); |
16 | 324 |
event.name = readTokenAndEatTerminator(']', "e, &found); |
25
b9067d2812e5
trim section names if not in quotes
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
325 |
if (!quote) event.name = trim(event.name); |
16 | 326 |
|
327 |
readSpacesAndTabs(); |
|
328 |
if (allowSectionTags && peek() == '[') { |
|
329 |
get(); |
|
330 |
event.tag = readTokenAndEatTerminator(']', "e, &found); |
|
331 |
} |
|
332 |
||
333 |
readSpacesAndTabs(); |
|
334 |
ch = peek(); |
|
335 |
if (isComment(ch)) { |
|
336 |
get(); |
|
337 |
readSpacesAndTabs(); |
|
338 |
event.comment = readUntil('\n', &found); |
|
339 |
} else if (ch == '\n') { |
|
340 |
get(); |
|
341 |
} else { |
|
342 |
throw std::logic_error(std::string("unexpected content after the section: '") + event.name + "'"); |
|
343 |
} |
|
344 |
||
345 |
for (INIContentHandler* handler : handlers) handler->startSection(event); |
|
346 |
} else if (isComment(ch)) { |
|
6
fb717cfbfea1
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
347 |
INIContentHandler::CommentEvent event; |
fb717cfbfea1
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
348 |
event.lineNumber = lineNumber; |
fb717cfbfea1
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
349 |
event.eventNumber = ++eventNumber; |
19
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
350 |
get(); |
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
351 |
readSpacesAndTabs(); |
16 | 352 |
event.comment = readUntil('\n', &found); |
6
fb717cfbfea1
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
353 |
for (INIContentHandler* handler : handlers) handler->comment(event); |
16 | 354 |
} else { |
19
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
355 |
INIContentHandler::EntryEvent event; |
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
356 |
event.lineNumber = lineNumber; |
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
357 |
event.eventNumber = ++eventNumber; |
967f73af64a4
start event numbers with 1
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
358 |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
359 |
std::string fullKey = readToken(keyValueSeparators, "e, &found); |
16 | 360 |
if (!found) throw std::logic_error(std::string("missing = after key: '") + fullKey + "'"); |
361 |
if (!quote) fullKey = trim(fullKey); |
|
362 |
readSpacesAndTabs(); |
|
363 |
||
364 |
if (quote) { |
|
365 |
ch = get(); |
|
20
9187f0439ca9
prepare for multiple and configurable key-value separators (e.g. key=value and key:value)
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
366 |
if (oneOf(ch, keyValueSeparators)) readSpacesAndTabs(); |
16 | 367 |
else throw std::logic_error(std::string("missing = after quoted key: '") + fullKey + "'"); |
368 |
} |
|
369 |
||
370 |
std::string value = readToken('\n', "e, &found); |
|
371 |
if (!quote) value = trim(value); |
|
372 |
||
373 |
event.key = fullKey; |
|
374 |
event.fullKey = fullKey; |
|
375 |
event.value = value; |
|
14
ea431c469403
multi-line support: quoted and apostrophed
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
376 |
|
16 | 377 |
if (allowSubKeys) { |
378 |
std::smatch match; |
|
379 |
if (std::regex_match(fullKey, match, std::regex("([^\\[]+)\\[([^\\[]+)\\]"))) { |
|
380 |
event.key = match[1]; |
|
381 |
event.subKey = match[2]; |
|
382 |
event.fullKey = fullKey; |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
if (quote) { |
|
387 |
readSpacesAndTabs(); |
|
388 |
ch = peek(); |
|
389 |
if (isComment(ch)) { |
|
390 |
get(); |
|
391 |
readSpacesAndTabs(); |
|
392 |
event.comment = readUntil('\n', &found); |
|
393 |
} else if (ch == '\n') { |
|
394 |
get(); |
|
395 |
} else { |
|
26 | 396 |
// TODO: optional support for multiple tokens in a single entry? |
397 |
// modes: array, concatenate |
|
398 |
// some-array-1 = "item 1" "item 2" 'item 3' item 4 |
|
399 |
// some-array-2 = "item 1" "item 2" 'item 3' item_4 item_5 |
|
400 |
// some-bash-style-string-value = "this "will' be' concatenated → this will be concatenated |
|
16 | 401 |
throw std::logic_error(std::string("unexpected content after the quoted value: key='") + fullKey + "' value='" + event.value + "'"); |
14
ea431c469403
multi-line support: quoted and apostrophed
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
402 |
} |
ea431c469403
multi-line support: quoted and apostrophed
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
403 |
} |
ea431c469403
multi-line support: quoted and apostrophed
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
404 |
|
2
f031a4dc7c52
add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
405 |
for (INIContentHandler* handler : handlers) handler->entry(event); |
1
3876a9c56a66
simple INI parser based on regular expressions
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
406 |
} |
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
407 |
} |
16 | 408 |
// TODO: error at the end, catch premature/unexpected EOF |
409 |
// TODO: unescape + trim values + ignore \r |
|
410 |
// TODO: count lines |
|
2
f031a4dc7c52
add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
411 |
if (inSection) for (INIContentHandler* handler : handlers) handler->endSection(); |
1
3876a9c56a66
simple INI parser based on regular expressions
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
412 |
for (INIContentHandler* handler : handlers) handler->endDocument(); |
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
413 |
} |
16 | 414 |
|
415 |
// General feautres: |
|
416 |
// TODO: warning/error handler |
|
417 |
// TODO: support also escaped characters |
|
418 |
// TODO: support also Java .properties and manifest.mf formats? |
|
419 |
// TODO: support also nested sections – hierarchy |
|
420 |
// TODO: support also nested keys e.g. key.sub.subsub.subsubsub=value – translate them to nested sections |
|
421 |
// TODO: support also option for alternative key-value separator (: instead of =) |
|
422 |
// TODO: support also other encodings (currently only UTF-8 is supported) |
|
423 |
// TODO: better exceptions |
|
424 |
||
425 |
// Lossless conversions: |
|
426 |
// TODO: emit also the quote style ('/"/) |
|
427 |
// TODO: emit also the comment style (;/#) ? |
|
428 |
// TODO: emit also the whitespace before key name, around =, after "values"/'values', around [sections] ? |
|
429 |
// TODO: emit also the line-end type (LF/CRLF) ? |
|
430 |
||
0
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
431 |
}; |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
432 |
|
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
433 |
INIReader* INIReader::create(std::istream& input) { |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
434 |
return new INIReaderImpl(input); |
16c7fa9b7c49
project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
435 |
} |
16 | 436 |
|
437 |
} |
|
438 |
} |
|
439 |
} |
|
440 |
} |