multi-line support: quoted and apostrophed v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 23 Nov 2020 21:09:46 +0100
branchv_0
changeset 25 ee70b17950bd
parent 24 dd3c03162e89
child 26 80e129ec3408
multi-line support: quoted and apostrophed
src/lib/INIReader.cpp
--- a/src/lib/INIReader.cpp	Mon Nov 23 19:49:35 2020 +0100
+++ b/src/lib/INIReader.cpp	Mon Nov 23 21:09:46 2020 +0100
@@ -40,7 +40,7 @@
 		std::regex whitespacePattrern("\\s*");
 		std::regex commentPattrern("\\s*(;|#)\\s*(.*)");
 		std::regex sectionPattrern("\\s*\\[\\s*([^\\]]+)\\s*\\]\\s*(\\[\\s*([^\\]]+)\\s*\\])?\\s*((;|#)\\s*(.*))?");
-		std::regex entryQuotedPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(\"|')((?:(?!\\5).)*)(\\5)\\s*((;|#)\\s*(.*))?");
+		std::regex entryQuotedPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(\"|')((?:(?!\\5).)*)(\\5)?\\s*((;|#)\\s*(.*))?");
 		std::regex entryPlainPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(.*?)\\s*");
 
 		std::smatch match;
@@ -87,6 +87,23 @@
 				event.fullKey = match[1];
 				event.value = match[6];
 				event.comment = match[10];
+
+				// the "/' at the end is missing → line continues
+				if (match.length(7) == 0) {
+					std::regex endPattern(std::string("(.*?)") + (match[5] == "'" ? "'" : "\"") + "\\s*((;|#)\\s*(.*))?");
+					while (std::getline(input, line)) {
+						lineNumber++;
+						event.value += "\n";
+						if (std::regex_match(line, match, endPattern)) {
+							event.value += std::string(match[1]);
+							event.comment = match[4];
+							break;
+						} else {
+							event.value += line;
+						}
+					}
+				}
+
 				for (INIContentHandler* handler : handlers) handler->entry(event);
 			} else if (std::regex_match(line, match, entryPlainPattrern)) {
 				INIContentHandler::EntryEvent event;
@@ -97,7 +114,9 @@
 				event.fullKey = match[1];
 				event.value = match[5];
 
+				// the \ at the end → line continues
 				while (line.back() == '\\' && std::getline(input, line)) {
+					lineNumber++;
 					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;