# HG changeset patch # User František Kučera # Date 1606491775 -3600 # Node ID 07e0a2edf3bc711b9bea418e3886a3d826b191a8 # Parent b497140b0b633aabd4b55fa073f8634c6d16fcd1 add --parser-option allow-sections (Java .properties have no sections) diff -r b497140b0b63 -r 07e0a2edf3bc bash-completion.sh --- a/bash-completion.sh Fri Nov 27 16:29:12 2020 +0100 +++ b/bash-completion.sh Fri Nov 27 16:42:55 2020 +0100 @@ -29,6 +29,7 @@ PARSER_OPTIONS=( "trim-continuing-lines" + "allow-sections" "allow-section-tags" "allow-sub-keys" "comment-separators" @@ -51,6 +52,7 @@ elif [[ "$w1" == "--enable-event-numbers" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w1" == "--parser-option" ]]; then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0")) elif [[ "$w2" == "--parser-option" && "$w1" == "trim-continuing-lines" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) + elif [[ "$w2" == "--parser-option" && "$w1" == "allow-sections" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w2" == "--parser-option" && "$w1" == "allow-section-tags" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w2" == "--parser-option" && "$w1" == "allow-sub-keys" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w2" == "--parser-option" && "$w1" == "dialect" ]]; then COMPREPLY=($(compgen -W "${DIALECTS[*]}" -- "$w0")) diff -r b497140b0b63 -r 07e0a2edf3bc src/lib/INIReader.cpp --- a/src/lib/INIReader.cpp Fri Nov 27 16:29:12 2020 +0100 +++ b/src/lib/INIReader.cpp Fri Nov 27 16:42:55 2020 +0100 @@ -42,6 +42,14 @@ */ bool trimLeadingSpacesOnContinuingLines = true; + + /** + * Some dialects or configuration files in general does not support sections. + * Then a line, that looks like an INI section, should be interpreted as a key + * (or error, if does not have a proper key-value separator). + */ + bool allowSections = true; + /** * KDE uses some weird INI dialect that allows [section][x] syntax where „x“ is kind of „tag“ that signalizes some properties of given section. * Line „[section_1][$i]“ means that the „section_1“ is „locked“. @@ -239,12 +247,12 @@ // already set } else if (name == "java-properties") { trimLeadingSpacesOnContinuingLines = true; + allowSections = false; allowSectionTags = false; allowSubKeys = false; commentSeparators = "#"; keyValueSeparators = "=:"; quotes = ""; - // TODO: allowSections = false; // TODO: enable unicode unescaping } else { throw std::invalid_argument(std::string("Unsupported INI dialect: ") + name); @@ -258,7 +266,7 @@ void setOption(const std::string& uri, const std::string& value) override { if (uri == "trim-continuing-lines") trimLeadingSpacesOnContinuingLines = parseBoolean(value); // TODO: continuing lines modes (enum), not just boolean - // TODO: else if (uri == "allow-sections") allowSections = parseBoolean(value); + else if (uri == "allow-sections") allowSections = parseBoolean(value); else if (uri == "allow-section-tags") allowSectionTags = parseBoolean(value); else if (uri == "allow-sub-keys") allowSubKeys = parseBoolean(value); else if (uri == "comment-separators") commentSeparators = value; @@ -296,7 +304,7 @@ if (ch == std::istream::traits_type::eof()) { break; - } else if (ch == '[') { + } else if (ch == '[' && allowSections) { if (inSection) for (INIContentHandler* handler : handlers) handler->endSection(); inSection = true; INIContentHandler::SectionStartEvent event; @@ -305,6 +313,7 @@ get(); readAllWhitespace(); event.name = readTokenAndEatTerminator(']', "e, &found); + // TODO: if (!quote) event.name = trim(event.name); readSpacesAndTabs(); if (allowSectionTags && peek() == '[') {