From e4223ebcabbba82b92f8652e78d0c43db7507355 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 2 Aug 2023 16:08:08 +0530 Subject: dbook: trim function to remove white spaces on string ends --- dbook | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'dbook') diff --git a/dbook b/dbook index e1c082c..3ea4128 100755 --- a/dbook +++ b/dbook @@ -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 -- cgit v1.2.3