simplify/unify the quoted and apostrophed values v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 23 Nov 2020 19:49:35 +0100
branchv_0
changeset 24 dd3c03162e89
parent 23 dd72e4ea4399
child 25 ee70b17950bd
simplify/unify the quoted and apostrophed values
src/lib/INIReader.cpp
--- a/src/lib/INIReader.cpp	Mon Nov 23 19:41:06 2020 +0100
+++ b/src/lib/INIReader.cpp	Mon Nov 23 19:49:35 2020 +0100
@@ -40,8 +40,7 @@
 		std::regex whitespacePattrern("\\s*");
 		std::regex commentPattrern("\\s*(;|#)\\s*(.*)");
 		std::regex sectionPattrern("\\s*\\[\\s*([^\\]]+)\\s*\\]\\s*(\\[\\s*([^\\]]+)\\s*\\])?\\s*((;|#)\\s*(.*))?");
-		std::regex entryQuotesPattrern(/***/"\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*\"([^']+)\"\\s*((;|#)\\s*(.*))?");
-		std::regex entryApostrophesPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*'([^']+)'\\s*((;|#)\\s*(.*))?");
+		std::regex entryQuotedPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(\"|')((?:(?!\\5).)*)(\\5)\\s*((;|#)\\s*(.*))?");
 		std::regex entryPlainPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(.*?)\\s*");
 
 		std::smatch match;
@@ -79,15 +78,15 @@
 				// 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)) {
+			} else if (std::regex_match(line, match, entryQuotedPattrern)) {
 				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];
-				if (match.size() == 9) event.comment = match[8];
+				event.value = match[6];
+				event.comment = match[10];
 				for (INIContentHandler* handler : handlers) handler->entry(event);
 			} else if (std::regex_match(line, match, entryPlainPattrern)) {
 				INIContentHandler::EntryEvent event;