<commit_before># shini - compatible INI library for sh
#
# This code is released freely under the MIT license - see the shipped LICENSE document.
# For the latest version etc, please see https://github.com/wallyhall/shini
#

# Solely for the purpose of portable performance, this script breaks good practice to
# avoid forking subshells.  One such good practice is avoiding global variables.
# This variable is used to carry non-numeric results from functions to the caller.
# Alternatively an echo and "$(...)" approach could be used, but is significantly slower.

shini_setup()
{
    if [ -n "$ZSH_VERSION" ]; then
        RESTORE_OPTS=$(set +o)
        # Enable BASH_REMATCH for zsh
        setopt KSH_ARRAYS BASH_REMATCH
    fi
}

shini_teardown()
{
    [ -n "$ZSH_VERSION" ] && eval "$RESTORE_OPTS"
}

shini_function_exists()
{
    type "$1" > /dev/null 2>&1
    return $?
}

shini_regex_match()
{
    # $KSH_VERSION (I'm told) only exists on ksh 93 and above, which supports regex matching.
    if [ "${BASH_VERSINFO}" -ge 3 ] || [ -n "$ZSH_VERSION" ] || [ -n "$KSH_VERSION" ]; then
        [[ "$1" =~ $2 ]] && return 0 || return 1
    fi

    printf '%s' "$1" | grep -qe "$2"
    return $?
}

shini_regex_replace()
{
    if [ "${BASH_VERSINFO}" -ge 3 ] || [ -n "$ZSH_VERSION" ]; then
        [[ "$1" =~ $2 ]] && shini_retval=${BASH_REMATCH[1]} || shini_retval="$1"
        return 0
    fi

    shini_retval="$(printf '%s' "$1" | sed -E "s/$2/\1/")"  # If you have isses on older systems,
    # it may be the non-newer POSIX compliant sed.
    # -E should be enabling extended regex mode portably.
}

# @param inifile Filename of INI file to parse
# @param postfix Function postfix for callbacks (optional)
# @param extra Extra argument for callbacks (optional)
shini_parse()
{
    shini_parse_section "$1" '' "$2" "$3" "$4" "$5"
}

# @param inifile Filename of INI file to parse
# @param section Section to parse (or empty string for entire file)
# @param postfix Function postfix for callbacks (optional)
# @param extra Extra argument for callbacks (optional)
shini_parse_section()
{
    shini_setup
    # ********<commit_msg>Bugfix for -eq sensitive shells (like ash).<commit_after># shini - compatible INI library for sh
#
# This code is released freely under the MIT license - see the shipped LICENSE document.
# For the latest version etc, please see https://github.com/wallyhall/shini
#

# Solely for the purpose of portable performance, this script breaks good practice to
# avoid forking subshells.  One such good practice is avoiding global variables.
# This variable is used to carry non-numeric results from functions to the caller.
# Alternatively an echo and "$(...)" approach could be used, but is significantly slower.

shini_setup()
{
    if [ -n "$ZSH_VERSION" ]; then
        RESTORE_OPTS=$(set +o)
        # Enable BASH_REMATCH for zsh
        setopt KSH_ARRAYS BASH_REMATCH
    fi
}

shini_teardown()
{
    [ -n "$ZSH_VERSION" ] && eval "$RESTORE_OPTS"
}

shini_function_exists()
{
    type "$1" > /dev/null 2>&1
    return $?
}

shini_regex_match()
{
    # $KSH_VERSION (I'm told) only exists on ksh 93 and above, which supports regex matching.
    if [ -n "$BASH_VERSINFO" ] && $[ "$BASH_VERSINFO" -ge 3 ] || \
       [ -n "$ZSH_VERSION" ] || \
       [ -n "$KSH_VERSION" ]; then
        [[ "$1" =~ $2 ]] && return 0 || return 1
    fi

    printf '%s' "$1" | grep -qe "$2"
    return $?
}

shini_regex_replace()
{
#    if [ "${BASH_VERSINFO}" -ge 3 ] || [ -n "$ZSH_VERSION" ]; then
#        [[ "$1" =~ $2 ]] && shini_retval=${BASH_REMATCH[1]} || shini_retval="$1"
#        return 0
#    fi

    shini_retval="$(printf '%s' "$1" | sed -E "s/$2/\1/")"  # If you have isses on older systems,
    # it may be the non-newer POSIX compliant sed.
    # -E should be enabling extended regex mode portably.
}

# @param inifile Filename of INI file to parse
# @param postfix Function postfix for callbacks (optional)
# @param extra Extra argument for callbacks (optional)
shini_parse()
{
    shini_parse_section "$1" '' "$2" "$3" "$4" "$5"
}

# @param inifile Filename of INI file to parse
# @param section Section to parse (or empty string for entire file)
# @param postfix Function postfix for callbacks (optional)
# @param extra Extra argument for callbacks (optional)
shini_parse_section()
{
    shini_setup
    # ********
{'fraction_non_alphanumeric': 0.13138518177634606, 'fraction_numerical': 0.011965025310630465, 'mean_word_length': 3.2997032640949553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1126712', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1430, 'n_words': 508}