partial support of KDE syntax: [section][] v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 23 Nov 2020 17:56:55 +0100
branchv_0
changeset 9 be61125d8ed1
parent 8 83b23480d41f
child 10 f689cbfc6b44
partial support of KDE syntax: [section][]
nbproject/configurations.xml
src/lib/INIReader.cpp
--- a/nbproject/configurations.xml	Mon Nov 23 17:23:16 2020 +0100
+++ b/nbproject/configurations.xml	Mon Nov 23 17:56:55 2020 +0100
@@ -98,11 +98,13 @@
           <preBuildFirst>true</preBuildFirst>
         </preBuild>
       </makefileType>
-      <item path="src/INICommand.cpp" ex="false" tool="1" flavor2="0">
+      <item path="src/INICommand.cpp" ex="false" tool="1" flavor2="11">
         <ccTool flags="0">
         </ccTool>
       </item>
       <item path="src/lib/INIReader.cpp" ex="false" tool="1" flavor2="0">
+        <ccTool flags="0">
+        </ccTool>
       </item>
       <item path="src/relpipe-in-ini.cpp" ex="false" tool="1" flavor2="11">
         <ccTool flags="0">
--- a/src/lib/INIReader.cpp	Mon Nov 23 17:23:16 2020 +0100
+++ b/src/lib/INIReader.cpp	Mon Nov 23 17:56:55 2020 +0100
@@ -39,7 +39,7 @@
 
 		std::regex whitespacePattrern("\\s*");
 		std::regex commentPattrern("\\s*(;|#)\\s*(.*)");
-		std::regex sectionPattrern("\\s*\\[\\s*([^\\]]+)\\s*\\]\\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 entryPlainPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(.*)");
@@ -73,7 +73,11 @@
 				event.lineNumber = lineNumber;
 				event.eventNumber = ++eventNumber;
 				event.name = match[1];
-				event.comment = match[4];
+				event.comment = match[6];
+				// event.tag = match[3];
+				// KDE uses some weird INI dialect that allows [section][x] syntax where „x“ is kind of „tag“ that signalizes some properties of given section.
+				// 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)) {
 				INIContentHandler::EntryEvent event;
@@ -96,6 +100,7 @@
 			// TODO: support also quoted or multiline keys?
 			// TODO: support also escaped characters
 			// TODO: support also Java .properties and manifest.mf formats?
+			// TODO: support also quoted sections ["qoted section"] – useful for hierarchy (the path element may contain the separator character)
 			// TODO: support also nested sections – hierarchy
 			// 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 =)