aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-01-31 15:27:13 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-01-31 23:10:15 +0100
commit09988d9892dd3c5894f13b3e9dd3cd63b107c5eb (patch)
tree4e4960d7833bf8e0e803053768b36aafb5e391ac
parentb548ffee5943d077ec3db352f7a08f075850ce26 (diff)
global-functions: introduce $CleanName
-rw-r--r--global-functions.rsc19
1 files changed, 19 insertions, 0 deletions
diff --git a/global-functions.rsc b/global-functions.rsc
index 452b9d1..3c3e2e1 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -27,6 +27,7 @@
:global CharacterMultiply;
:global CharacterReplace;
:global CleanFilePath;
+:global CleanName;
:global DeviceInfo;
:global Dos2Unix;
:global DownloadPackage;
@@ -222,6 +223,24 @@
:return $Path;
}
+# clean name for DNS, file and more
+:set CleanName do={
+ :local Input [ :tostr $1 ];
+
+ :local Return "";
+
+ :for I from=0 to=([ :len $Input ] - 1) do={
+ :local Char [ :pick $Input $I ];
+ :if ([ :typeof [ find "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-" $Char ] ] = "nil") do={
+ :set Char "-";
+ }
+ :if ($Char != "-" || [ :pick $Return ([ :len $Return ] - 1) ] != "-") do={
+ :set Return ($Return . $Char);
+ }
+ }
+ :return $Return;
+}
+
# get readable device info
:set DeviceInfo do={
:global ExpectedConfigVersion;