# HG changeset patch # User František Kučera # Date 1606150576 -3600 # Node ID fc8f9aab211df1f21d65ad6cc45dabb16ec9b480 # Parent 90f2b8ca32bfa651a52f486cf784d4deec4dce52 partial support of KDE syntax: [section][] diff -r 90f2b8ca32bf -r fc8f9aab211d src/lib/INIReader.cpp --- a/src/lib/INIReader.cpp Mon Nov 23 16:25:39 2020 +0100 +++ b/src/lib/INIReader.cpp Mon Nov 23 17:56:16 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 , „[$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 =)