src/lib/INIReader.cpp
branchv_0
changeset 20 fc8f9aab211d
parent 19 90f2b8ca32bf
child 21 ccd0677746ce
equal deleted inserted replaced
19:90f2b8ca32bf 20:fc8f9aab211d
    37 
    37 
    38 		for (INIContentHandler* handler : handlers) handler->startDocument();
    38 		for (INIContentHandler* handler : handlers) handler->startDocument();
    39 
    39 
    40 		std::regex whitespacePattrern("\\s*");
    40 		std::regex whitespacePattrern("\\s*");
    41 		std::regex commentPattrern("\\s*(;|#)\\s*(.*)");
    41 		std::regex commentPattrern("\\s*(;|#)\\s*(.*)");
    42 		std::regex sectionPattrern("\\s*\\[\\s*([^\\]]+)\\s*\\]\\s*((;|#)\\s*(.*))?");
    42 		std::regex sectionPattrern("\\s*\\[\\s*([^\\]]+)\\s*\\]\\s*(\\[\\s*([^\\]]+)\\s*\\])?\\s*((;|#)\\s*(.*))?");
    43 		std::regex entryQuotesPattrern(/***/"\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*\"([^']+)\"\\s*((;|#)\\s*(.*))?");
    43 		std::regex entryQuotesPattrern(/***/"\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*\"([^']+)\"\\s*((;|#)\\s*(.*))?");
    44 		std::regex entryApostrophesPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*'([^']+)'\\s*((;|#)\\s*(.*))?");
    44 		std::regex entryApostrophesPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*'([^']+)'\\s*((;|#)\\s*(.*))?");
    45 		std::regex entryPlainPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(.*)");
    45 		std::regex entryPlainPattrern("\\s*(([^=\\]]+?[^=\\s\\]]*)(\\[([^\\]]+)\\])?)\\s*=\\s*(.*)");
    46 
    46 
    47 		std::smatch match;
    47 		std::smatch match;
    71 				inSection = true;
    71 				inSection = true;
    72 				INIContentHandler::SectionStartEvent event;
    72 				INIContentHandler::SectionStartEvent event;
    73 				event.lineNumber = lineNumber;
    73 				event.lineNumber = lineNumber;
    74 				event.eventNumber = ++eventNumber;
    74 				event.eventNumber = ++eventNumber;
    75 				event.name = match[1];
    75 				event.name = match[1];
    76 				event.comment = match[4];
    76 				event.comment = match[6];
       
    77 				// event.tag = match[3];
       
    78 				// KDE uses some weird INI dialect that allows [section][x] syntax where „x“ is kind of „tag“ that signalizes some properties of given section.
       
    79 				// see <https://userbase.kde.org/KDE_System_Administration/Configuration_Files>, „[$i]“ means that the section is „locked“
       
    80 				// We may emit this information somehow later, but for now, it is just ignored.
    77 				for (INIContentHandler* handler : handlers) handler->startSection(event);
    81 				for (INIContentHandler* handler : handlers) handler->startSection(event);
    78 			} else if (std::regex_match(line, match, entryQuotesPattrern) || std::regex_match(line, match, entryApostrophesPattrern) || std::regex_match(line, match, entryPlainPattrern)) {
    82 			} else if (std::regex_match(line, match, entryQuotesPattrern) || std::regex_match(line, match, entryApostrophesPattrern) || std::regex_match(line, match, entryPlainPattrern)) {
    79 				INIContentHandler::EntryEvent event;
    83 				INIContentHandler::EntryEvent event;
    80 				event.lineNumber = lineNumber;
    84 				event.lineNumber = lineNumber;
    81 				event.eventNumber = ++eventNumber;
    85 				event.eventNumber = ++eventNumber;
    94 			// TODO: warning/error handler
    98 			// TODO: warning/error handler
    95 			// TODO: support also multiline content (\ + \n)
    99 			// TODO: support also multiline content (\ + \n)
    96 			// TODO: support also quoted or multiline keys?
   100 			// TODO: support also quoted or multiline keys?
    97 			// TODO: support also escaped characters
   101 			// TODO: support also escaped characters
    98 			// TODO: support also Java .properties and manifest.mf formats?
   102 			// TODO: support also Java .properties and manifest.mf formats?
       
   103 			// TODO: support also quoted sections ["qoted section"] – useful for hierarchy (the path element may contain the separator character)
    99 			// TODO: support also nested sections – hierarchy
   104 			// TODO: support also nested sections – hierarchy
   100 			// TODO: support also nested keys e.g. key.sub.subsub.subsubsub=value – translate them to nested sections
   105 			// TODO: support also nested keys e.g. key.sub.subsub.subsubsub=value – translate them to nested sections
   101 			// TODO: support also option for alternative key-value separator (: instead of =)
   106 			// TODO: support also option for alternative key-value separator (: instead of =)
   102 			// TODO: support also other encodings (currently only UTF-8 is supported)
   107 			// TODO: support also other encodings (currently only UTF-8 is supported)
   103 			
   108