Add --lowercase-keys and --uppercase-keys options.
This commit is contained in:
parent
629a2e2192
commit
73796b633b
1 changed files with 20 additions and 5 deletions
25
parse-ini
25
parse-ini
|
|
@ -71,13 +71,16 @@ parser_getopts() {
|
||||||
-l|-local|--local)
|
-l|-local|--local)
|
||||||
DECLARE_SCOPE="-l"
|
DECLARE_SCOPE="-l"
|
||||||
;;
|
;;
|
||||||
|
-lowercase|--lowercase)
|
||||||
|
CONVERT_CASE="-1"
|
||||||
|
;;
|
||||||
|
-lowercase-keys|--lowercase-keys)
|
||||||
|
CONVERT_KEY_CASE="-1"
|
||||||
|
;;
|
||||||
-merge-delim|--merge-delim)
|
-merge-delim|--merge-delim)
|
||||||
MERGE_DELIM="$2"
|
MERGE_DELIM="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-lowercase|--lowercase)
|
|
||||||
CONVERT_CASE="-1"
|
|
||||||
;;
|
|
||||||
-no-booleans|--no-booleans)
|
-no-booleans|--no-booleans)
|
||||||
USE_BOOLEANS="0"
|
USE_BOOLEANS="0"
|
||||||
;;
|
;;
|
||||||
|
|
@ -115,6 +118,9 @@ parser_getopts() {
|
||||||
-uppercase|--uppercase)
|
-uppercase|--uppercase)
|
||||||
CONVERT_CASE="1"
|
CONVERT_CASE="1"
|
||||||
;;
|
;;
|
||||||
|
-uppercase-keys|--uppercase-keys)
|
||||||
|
CONVERT_KEY_CASE="1"
|
||||||
|
;;
|
||||||
-v|-version|--version)
|
-v|-version|--version)
|
||||||
parser_version
|
parser_version
|
||||||
return 2
|
return 2
|
||||||
|
|
@ -207,6 +213,8 @@ parser_help() {
|
||||||
delimiter and section name is kept as per the INI file. With this option
|
delimiter and section name is kept as per the INI file. With this option
|
||||||
all items are converted to lower case. The case of the properties'
|
all items are converted to lower case. The case of the properties'
|
||||||
keys/values is not affected.
|
keys/values is not affected.
|
||||||
|
--lowercase-keys
|
||||||
|
Convert the key name to lowercase.
|
||||||
--merge-delim
|
--merge-delim
|
||||||
When '--duplicates-merge' is used, this sets the delimiters between each
|
When '--duplicates-merge' is used, this sets the delimiters between each
|
||||||
of the merged values.
|
of the merged values.
|
||||||
|
|
@ -234,6 +242,8 @@ parser_help() {
|
||||||
delimiter and section name is kept as per the INI file. With this option
|
delimiter and section name is kept as per the INI file. With this option
|
||||||
all items are converted to upper case. The case of the properties'
|
all items are converted to upper case. The case of the properties'
|
||||||
keys/values is not affected.
|
keys/values is not affected.
|
||||||
|
--uppercase-keys
|
||||||
|
Convert the key name to uppercase.
|
||||||
Option processing ceases with the first non-option argument, or "--".
|
Option processing ceases with the first non-option argument, or "--".
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
@ -264,8 +274,9 @@ parse_ini() {
|
||||||
local ACCEPTABLE_CHARS="[:blank:][:alnum:]_.+-" # Characters allowed in section and key names. Must be a valid regex bracket expression.
|
local ACCEPTABLE_CHARS="[:blank:][:alnum:]_.+-" # Characters allowed in section and key names. Must be a valid regex bracket expression.
|
||||||
local CHECK_ONLY="0" # Whether the parser is in check or normal mode. 0 = normal mode, 1 = check mode.
|
local CHECK_ONLY="0" # Whether the parser is in check or normal mode. 0 = normal mode, 1 = check mode.
|
||||||
local COMMENT_CHARS="#;" # Characters which indicate the start of a comment line.
|
local COMMENT_CHARS="#;" # Characters which indicate the start of a comment line.
|
||||||
local CONVERT_CASE="0" # Whether to keep or convert section and key names to upper or loweer case. -1 = covert to lowercase, 0 = keep case, 1 = convert to uppercase.
|
local CONVERT_CASE="0" # Whether to keep or convert prefix and section names to upper or loweer case. -1 = covert to lowercase, 0 = keep case, 1 = convert to uppercase.
|
||||||
local CONVERT_CHARS="[:blank:].+-" # Characters from ACCEPTABLE_CHARS in section and key names that should be converted to _. Must be a valid regex bracket expression.
|
local CONVERT_CHARS="[:blank:].+-" # Characters from ACCEPTABLE_CHARS in section and key names that should be converted to _. Must be a valid regex bracket expression.
|
||||||
|
local CONVERT_KEY_CASE="0" # Whether to keep or convert key names to upper or loweer case. -1 = covert to lowercase, 0 = keep case, 1 = convert to uppercase.
|
||||||
local CURRENT_SECTION="global" # Name used for the 'global' section of the INI file.
|
local CURRENT_SECTION="global" # Name used for the 'global' section of the INI file.
|
||||||
local DECLARE_SCOPE="-g" # The scope given in the array definitions. "-g" = global scope, "-l" = local scope, "-x" = export values.
|
local DECLARE_SCOPE="-g" # The scope given in the array definitions. "-g" = global scope, "-l" = local scope, "-x" = export values.
|
||||||
local DUPLICATES_MERGE="0" # Whether to merge latter duplicate key's values with earlier key's values. 0 = don't merge, 1 = do merge.
|
local DUPLICATES_MERGE="0" # Whether to merge latter duplicate key's values with earlier key's values. 0 = don't merge, 1 = do merge.
|
||||||
|
|
@ -274,7 +285,7 @@ parse_ini() {
|
||||||
local SQUASH_SPACES="1" # Whether to squash multiple consecutive blanks into a single space. 0 = don't squash, 1 = do squash.
|
local SQUASH_SPACES="1" # Whether to squash multiple consecutive blanks into a single space. 0 = don't squash, 1 = do squash.
|
||||||
local TEXTUAL_BOOLEANS="0" # Whether to use "false" and "true" for booleans. 0 = use "0" and "1", 1 = use "false" and "true".
|
local TEXTUAL_BOOLEANS="0" # Whether to use "false" and "true" for booleans. 0 = use "0" and "1", 1 = use "false" and "true".
|
||||||
local USE_BOOLEANS="1" # Whether to allow the use of boolean values in the INI file. 0 = don't allow, 1 = do allow.
|
local USE_BOOLEANS="1" # Whether to allow the use of boolean values in the INI file. 0 = don't allow, 1 = do allow.
|
||||||
local VARIABLE_PREFIX="INI" # Prefix for all variables. Note: case is not changed, even with CONVERT_CASE set.
|
local VARIABLE_PREFIX="INI" # Prefix for all variables.
|
||||||
local VARIABLE_DELIM="_" # Delimiter between prefix and section name, unless VARIABLE_PREFIX is empty.
|
local VARIABLE_DELIM="_" # Delimiter between prefix and section name, unless VARIABLE_PREFIX is empty.
|
||||||
|
|
||||||
# Variables.
|
# Variables.
|
||||||
|
|
@ -494,6 +505,10 @@ parse_ini() {
|
||||||
# Escape any 's in the key name.
|
# Escape any 's in the key name.
|
||||||
KEY="${KEY//\'/\'\\\'\'}"
|
KEY="${KEY//\'/\'\\\'\'}"
|
||||||
|
|
||||||
|
# Convert the key to lower or upper case if requested.
|
||||||
|
(( CONVERT_KEY_CASE == -1 )) && KEY="${KEY,,}"
|
||||||
|
(( CONVERT_KEY_CASE == 1 )) && KEY="${KEY^^}"
|
||||||
|
|
||||||
# If the value starts with a " or ' it must end with same.
|
# If the value starts with a " or ' it must end with same.
|
||||||
if [[ "${VALUE:0:1}" =~ [\"\'] ]]; then
|
if [[ "${VALUE:0:1}" =~ [\"\'] ]]; then
|
||||||
if [[ "${VALUE:0:1}" == "${VALUE: -1:1}" ]]; then
|
if [[ "${VALUE:0:1}" == "${VALUE: -1:1}" ]]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue