# HG changeset patch # User František Kučera # Date 1631206657 -7200 # Node ID 7c85dc9a310bd88c6f368ad5b70c99b74f9c0c60 # Parent bda9d3c83cb7eab51a3004b89478b87aade92b15 implement --writer-option skip-empty and skip-null (omit entries with missing values) diff -r bda9d3c83cb7 -r 7c85dc9a310b bash-completion.sh --- a/bash-completion.sh Sun Dec 13 16:47:25 2020 +0100 +++ b/bash-completion.sh Thu Sep 09 18:57:37 2021 +0200 @@ -61,6 +61,8 @@ "quotes-pattern-for-sections" "quotes-pattern-for-keys" "quotes-pattern-for-values" + "skip-empty" + "skip-null" "allow-sections" "hierarchy-separator" ); @@ -80,6 +82,8 @@ elif [[ "$w2" == "--writer-option" && "$w1" == "quotes-type-for-sections" ]]; then COMPREPLY=($(compgen -W "${QUOTING_TYPES[*]}" -- "$w0")) elif [[ "$w2" == "--writer-option" && "$w1" == "quotes-type-for-keys" ]]; then COMPREPLY=($(compgen -W "${QUOTING_TYPES[*]}" -- "$w0")) elif [[ "$w2" == "--writer-option" && "$w1" == "quotes-type-for-values" ]]; then COMPREPLY=($(compgen -W "${QUOTING_TYPES[*]}" -- "$w0")) + elif [[ "$w2" == "--writer-option" && "$w1" == "skip-empty" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) + elif [[ "$w2" == "--writer-option" && "$w1" == "skip-null" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w2" == "--writer-option" && "$w1" == "allow-sections" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w2" == "--writer-option" && "$w1" == "hierarchy-separator" ]]; then COMPREPLY=("'/'") elif [[ "$w2" == "--writer-option" && "x$w0" == "x" ]]; then COMPREPLY=("''") diff -r bda9d3c83cb7 -r 7c85dc9a310b src/INIWriter.h --- a/src/INIWriter.h Sun Dec 13 16:47:25 2020 +0100 +++ b/src/INIWriter.h Thu Sep 09 18:57:37 2021 +0200 @@ -43,6 +43,9 @@ relpipe::common::type::StringX hierarchySeparator = L"/"; bool allowSections = true; + + bool skipEmpty = false; + bool skipNull = false; bool hasContent = false; @@ -196,6 +199,8 @@ else if (uri == option::KeyValueSeparator) keyValueSeparator = convertor.to_bytes(value); else if (uri == option::HierarchySeparator) hierarchySeparator = value; else if (uri == option::AllowSections) allowSections = parseBoolean(value); + else if (uri == option::SkipEmpty) skipEmpty = parseBoolean(value); + else if (uri == option::SkipNull) skipNull = parseBoolean(value); else if (uri == option::QuotesTypeForSections) quotingForSections.type = parseQuotingType(value); else if (uri == option::QuotesTypeForKeys) quotingForKeys.type = parseQuotingType(value); else if (uri == option::QuotesTypeForValues) quotingForValues.type = parseQuotingType(value); @@ -243,6 +248,8 @@ } void entry(const EntryEvent& event) { + if (skipEmpty && event.value.empty()) return; + if (skipNull && event.value.empty()) return; // TODO: distinguish null and empty (when supported in the relpipe format) // TODO: escape/quote parts separately + configurable quoting of parts or whole + the same for sub keys if (!allowSections && currentSection.size()) output << escape(getCurrentSectionFullName(), EscapingProcessor::TextType::EntryKey) << convertor.to_bytes(hierarchySeparator); output << escape(event.key, EscapingProcessor::TextType::EntryKey); diff -r bda9d3c83cb7 -r 7c85dc9a310b src/uri.h --- a/src/uri.h Sun Dec 13 16:47:25 2020 +0100 +++ b/src/uri.h Thu Sep 09 18:57:37 2021 +0200 @@ -40,6 +40,8 @@ static const wchar_t* QuotesPatternForKeys = L"quotes-pattern-for-keys"; static const wchar_t* QuotesPatternForValues = L"quotes-pattern-for-values"; static const wchar_t* Dialect = L"dialect"; +static const wchar_t* SkipEmpty = L"skip-empty"; +static const wchar_t* SkipNull = L"skip-null"; } /** names of dynamically registered escaping processors; they are also options */