commit: 17a4c845a6b36a48327051eb1f3662b3704bb820
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Feb 13 04:17:44 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Feb 13 21:35:40 2023 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=17a4c845
Improve the _esetdent(), eindent() and eoutdent() functions
Eliminate the useless use of the (non-standard) local builtin.
Use is_int() to validate that the first argument is an integer.
Use if, as opposed to the somewhat contorted combinations of the && and
|| control operators.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
functions.sh | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/functions.sh b/functions.sh
index 4747b0e..38c49fd 100644
--- a/functions.sh
+++ b/functions.sh
@@ -17,9 +17,10 @@ RC_GOT_FUNCTIONS="yes"
#
_esetdent()
{
- local i="$1"
- [ -z "$i" ] || [ "$i" -lt 0 ] && i=0
- RC_INDENTATION=$(printf "%${i}s" '')
+ if ! is_int "$1" || [ "$1" -lt 0 ]; then
+ set -- 0
+ fi
+ RC_INDENTATION=$(printf "%${1}s" '')
}
#
@@ -27,9 +28,10 @@ _esetdent()
#
eindent()
{
- local i="$1"
- [ -n "$i" ] && [ "$i" -gt 0 ] || i=${RC_DEFAULT_INDENT}
- _esetdent $(( ${#RC_INDENTATION} + i ))
+ if ! is_int "$1" || [ "$1" -le 0 ]; then
+ set -- "${RC_DEFAULT_INDENT}"
+ fi
+ _esetdent "$(( ${#RC_INDENTATION} + $1 ))"
}
#
@@ -37,9 +39,10 @@ eindent()
#
eoutdent()
{
- local i="$1"
- [ -n "$i" ] && [ "$i" -gt 0 ] || i=${RC_DEFAULT_INDENT}
- _esetdent $(( ${#RC_INDENTATION} - i ))
+ if ! is_int "$1" || [ "$1" -le 0 ]; then
+ set -- "${RC_DEFAULT_INDENT}"
+ fi
+ _esetdent "$(( ${#RC_INDENTATION} - $1 ))"
}
#