From mboxrd@z Thu Jan  1 00:00:00 1970
From: Jonatan Schlag <jonatan.schlag@ipfire.org>
To: network@lists.ipfire.org
Subject: [PATCH 1/2] util: add normalize function
Date: Fri, 18 Aug 2017 13:45:18 +0200
Message-ID: <1503056719-24267-1-git-send-email-jonatan.schlag@ipfire.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============1145134556535944355=="
List-Id: <network.lists.ipfire.org>

--===============1145134556535944355==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

This function remove all non alpha numerical characters from a string
and substitute this characters with one -

So HELLO%%/$&/)%$%(&&HH becomes hello-hh

Signed-off-by: Jonatan Schlag <jonatan.schlag(a)ipfire.org>
---
 src/functions/functions.util | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/functions/functions.util b/src/functions/functions.util
index 24e3e66..8df0d86 100644
--- a/src/functions/functions.util
+++ b/src/functions/functions.util
@@ -845,3 +845,13 @@ copy() {
 		return ${EXIT_ERROR}
 	fi
 }
+
+
+normalize() {
+	assert [ $# -eq 1 ]
+
+	local string="${1}"
+
+	string="${string,,}"
+	tr -sc [:alnum:] "-" < <(printf "%s" "${string}")
+}
-- 
2.6.3


--===============1145134556535944355==--