author | František Kučera <franta-hg@frantovo.cz> |
Mon, 23 Nov 2020 17:56:16 +0100 | |
branch | v_0 |
changeset 20 | fc8f9aab211d |
parent 19 | 90f2b8ca32bf |
child 21 | ccd0677746ce |
permissions | -rw-r--r-- |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
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 |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#include <vector> |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
#include <regex> |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include "INIReader.h" |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
class INIReaderImpl : public INIReader { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
private: |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
std::istream& input; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
std::vector<INIContentHandler*> handlers; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
public: |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
INIReaderImpl(std::istream& input) : input(input) { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
} |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
void addHandler(INIContentHandler* handler) override { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
handlers.push_back(handler); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
} |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
void process() override { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
for (INIContentHandler* handler : handlers) handler->startDocument(); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
std::regex whitespacePattrern("\\s*"); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
std::regex commentPattrern("\\s*(;|#)\\s*(.*)"); |
20
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
42 |
std::regex sectionPattrern("\\s*\\[\\s*([^\\]]+)\\s*\\]\\s*(\\[\\s*([^\\]]+)\\s*\\])?\\s*((;|#)\\s*(.*))?"); |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
std::regex entryQuotesPattrern(/***/"\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*\"([^']+)\"\\s*((;|#)\\s*(.*))?"); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
std::regex entryApostrophesPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*'([^']+)'\\s*((;|#)\\s*(.*))?"); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
std::regex entryPlainPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(.*)"); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
std::smatch match; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
bool inSection = false; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
std::string line; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
int lineNumber = 0; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
int eventNumber = 0; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
while (std::getline(input, line)) { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
lineNumber++; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
if (std::regex_match(line, match, whitespacePattrern)) { |
19
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
58 |
INIContentHandler::WhitespaceEvent event; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
59 |
event.lineNumber = lineNumber; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
60 |
event.eventNumber = ++eventNumber; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
61 |
event.whitespace = match[0]; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
62 |
for (INIContentHandler* handler : handlers) handler->whitespace(event); |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
} else if (std::regex_match(line, match, commentPattrern)) { |
19
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
64 |
INIContentHandler::CommentEvent event; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
65 |
event.lineNumber = lineNumber; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
66 |
event.eventNumber = ++eventNumber; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
67 |
event.comment = match[2]; |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
68 |
for (INIContentHandler* handler : handlers) handler->comment(event); |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
} else if (std::regex_match(line, match, sectionPattrern)) { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
if (inSection) for (INIContentHandler* handler : handlers) handler->endSection(); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
inSection = true; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
INIContentHandler::SectionStartEvent event; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
event.lineNumber = lineNumber; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
event.eventNumber = ++eventNumber; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
event.name = match[1]; |
20
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
76 |
event.comment = match[6]; |
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
77 |
// event.tag = match[3]; |
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
78 |
// KDE uses some weird INI dialect that allows [section][x] syntax where „x“ is kind of „tag“ that signalizes some properties of given section. |
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
79 |
// see <https://userbase.kde.org/KDE_System_Administration/Configuration_Files>, „[$i]“ means that the section is „locked“ |
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
80 |
// We may emit this information somehow later, but for now, it is just ignored. |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
for (INIContentHandler* handler : handlers) handler->startSection(event); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
} else if (std::regex_match(line, match, entryQuotesPattrern) || std::regex_match(line, match, entryApostrophesPattrern) || std::regex_match(line, match, entryPlainPattrern)) { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
INIContentHandler::EntryEvent event; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
event.lineNumber = lineNumber; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
event.eventNumber = ++eventNumber; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
event.key = match[2]; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
event.subKey = match[4]; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
event.fullKey = match[1]; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
event.value = match[5]; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
if (match.size() == 9) event.comment = match[8]; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
91 |
for (INIContentHandler* handler : handlers) handler->entry(event); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
92 |
} else { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
93 |
// TODO: warning, error, or support unknown content |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
94 |
} |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
95 |
|
19
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
96 |
// General feautres: |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
97 |
// TODO: probably switch to state-machine approach instead of regular expressions or use an existing library |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
98 |
// TODO: warning/error handler |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
99 |
// TODO: support also multiline content (\ + \n) |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
100 |
// TODO: support also quoted or multiline keys? |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
101 |
// TODO: support also escaped characters |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
102 |
// TODO: support also Java .properties and manifest.mf formats? |
20
fc8f9aab211d
partial support of KDE syntax: [section][]
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
103 |
// TODO: support also quoted sections ["qoted section"] – useful for hierarchy (the path element may contain the separator character) |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
104 |
// TODO: support also nested sections – hierarchy |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
105 |
// TODO: support also nested keys e.g. key.sub.subsub.subsubsub=value – translate them to nested sections |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
106 |
// TODO: support also option for alternative key-value separator (: instead of =) |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
107 |
// TODO: support also other encodings (currently only UTF-8 is supported) |
19
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
108 |
|
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
109 |
// Lossless conversions: |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
110 |
// TODO: emit also the quote style ('/"/) |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
111 |
// TODO: emit also the comment style (;/#) ? |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
112 |
// TODO: emit also the whitespace before key name, around =, after "values"/'values', around [sections] ? |
90f2b8ca32bf
improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
113 |
// TODO: emit also the line-end type (LF/CRLF) ? |
16
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
114 |
} |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
115 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
116 |
if (inSection) for (INIContentHandler* handler : handlers) handler->endSection(); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
117 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
118 |
for (INIContentHandler* handler : handlers) handler->endDocument(); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
119 |
} |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
120 |
}; |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
121 |
|
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
122 |
INIReader* INIReader::create(std::istream& input) { |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
123 |
return new INIReaderImpl(input); |
b9a3c806468a
temporary copy INIReader.h, INIReader.cpp, INIContentHandler.h from relpipe-in-ini + XMLNameCodec.h from relpipe-in-yamltable (will be moved to alt2xml and shared)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
124 |
} |