# HG changeset patch # User František Kučera # Date 1606162186 -3600 # Node ID ee70b17950bdad7b845f26c07becad0d99a6954e # Parent dd3c03162e89a852b87af3a434f4e5381a9ade0c multi-line support: quoted and apostrophed diff -r dd3c03162e89 -r ee70b17950bd 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;