--- a/src/lib/INIReader.cpp Mon Nov 23 18:13:03 2020 +0100
+++ b/src/lib/INIReader.cpp Mon Nov 23 19:14:48 2020 +0100
@@ -79,7 +79,7 @@
// see <https://userbase.kde.org/KDE_System_Administration/Configuration_Files>, „[$i]“ means that the section is „locked“
// We may emit this information somehow later, but for now, it is just ignored.
for (INIContentHandler* handler : handlers) handler->startSection(event);
- } else if (std::regex_match(line, match, entryQuotesPattrern) || std::regex_match(line, match, entryApostrophesPattrern) || std::regex_match(line, match, entryPlainPattrern)) {
+ } else if (std::regex_match(line, match, entryQuotesPattrern) || std::regex_match(line, match, entryApostrophesPattrern)) {
INIContentHandler::EntryEvent event;
event.lineNumber = lineNumber;
event.eventNumber = ++eventNumber;
@@ -89,6 +89,22 @@
event.value = match[5];
if (match.size() == 9) event.comment = match[8];
for (INIContentHandler* handler : handlers) handler->entry(event);
+ } else if (std::regex_match(line, match, entryPlainPattrern)) {
+ INIContentHandler::EntryEvent event;
+ event.lineNumber = lineNumber;
+ event.eventNumber = ++eventNumber;
+ event.key = match[2];
+ event.subKey = match[4];
+ event.fullKey = match[1];
+ event.value = match[5];
+
+ while (line.back() == '\\' && std::getline(input, line)) {
+ line = std::regex_replace(line, std::regex("^\\s+|\\s+$"), ""); // trim the spaces: continuing lines might be aligned to the first line (desired spaces – if any – should be at the line end before the \ character)
+ event.value = event.value.substr(0, event.value.size() - 1); // cut the trailing \ backslash
+ event.value = event.value + line;
+ }
+
+ for (INIContentHandler* handler : handlers) handler->entry(event);
} else {
// TODO: warning, error, or support unknown content
}
@@ -96,7 +112,6 @@
// General feautres:
// TODO: probably switch to state-machine approach instead of regular expressions or use an existing library
// TODO: warning/error handler
- // TODO: support also multiline content (\ + \n)
// TODO: support also quoted or multiline keys?
// TODO: support also escaped characters
// TODO: support also Java .properties and manifest.mf formats?
@@ -105,7 +120,7 @@
// TODO: support also nested keys e.g. key.sub.subsub.subsubsub=value – translate them to nested sections
// TODO: support also option for alternative key-value separator (: instead of =)
// TODO: support also other encodings (currently only UTF-8 is supported)
-
+
// Lossless conversions:
// TODO: emit also the quote style ('/"/)
// TODO: emit also the comment style (;/#) ?