From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1486333-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 819CE158010
	for <garchives@archives.gentoo.org>; Mon, 13 Feb 2023 21:37:29 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id C1EE1E07EE;
	Mon, 13 Feb 2023 21:37:28 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id A3AE5E07EA
	for <gentoo-commits@lists.gentoo.org>; Mon, 13 Feb 2023 21:37:28 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id B53F4340B0B
	for <gentoo-commits@lists.gentoo.org>; Mon, 13 Feb 2023 21:37:27 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id A3D1C8B1
	for <gentoo-commits@lists.gentoo.org>; Mon, 13 Feb 2023 21:37:24 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" <sam@gentoo.org>
Message-ID: <1676324140.17a4c845a6b36a48327051eb1f3662b3704bb820.sam@gentoo>
Subject: [gentoo-commits] proj/gentoo-functions:master commit in: /
X-VCS-Repository: proj/gentoo-functions
X-VCS-Files: functions.sh
X-VCS-Directories: /
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: 17a4c845a6b36a48327051eb1f3662b3704bb820
X-VCS-Branch: master
Date: Mon, 13 Feb 2023 21:37:24 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: ba33376a-cecd-4014-9ccb-a6251e420bc3
X-Archives-Hash: a21b21b5c370dff9f8c7a43d185373a5

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 ))"
 }
 
 #