diff options
author | sinanmohd <sinan@firemail.cc> | 2023-08-02 16:08:08 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-08-02 16:35:34 +0530 |
commit | e4223ebcabbba82b92f8652e78d0c43db7507355 (patch) | |
tree | 026071859e4966458af0d5e29872240bb3713f48 /dbook | |
parent | 8b8db40fa51fd314e42363574bbae52870fc2bac (diff) |
dbook: trim function to remove white spaces on string ends
Diffstat (limited to 'dbook')
-rwxr-xr-x | dbook | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -68,6 +68,16 @@ dep_check() unset dep } +trim() +{ + : "${1:?}" + + _trimstr="${1#"${1%%[![:space:]]*}"}" + _trimstr="${_trimstr%"${_trimstr##*[![:space:]]}"}" + + echo "$_trimstr" +} + load_icon() { case "$(file --brief --dereference --mime-type "$1")" in @@ -100,12 +110,8 @@ parse_data() _key="${line%%|*}" _value="${line##*|}" - - # trim leading and trailing white spaces - _key="${_key#"${_key%%[![:space:]]*}"}" - _key="${_key%"${_key##*[![:space:]]}"}" - _value="${_value#"${_value%%[![:space:]]*}"}" - _value="${_value%"${_value##*[![:space:]]}"}" + _key="$(trim "$_key")" + _value="$(trim "$_value")" case "$_key" in #*) continue @@ -140,17 +146,10 @@ rm_data() do cl="$line\n" - key="${cl%%|*}" - # trim leading and trailing white spaces - key=${key#"${key%%[![:space:]]*}"} - key=${key%"${key##*[![:space:]]}"} - + key="$(trim "${cl%%|*}")" # catch match if [ "$key" = "$1" ]; then - value="${cl##*|}" - # trim leading and trailing white spaces - value="${value#"${value%%[![:space:]]*}"}" - value="${value%"${value##*[![:space:]]}"}" + value="$(trim "${cl##*|}")" # delete if saved case "$value" in |