aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-09-15 22:50:32 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-09-18 07:55:05 +0200
commit4ddc6be5859210e6a4c47699884f3fb67c3ed777 (patch)
treeaa29aabb858da2f970c26d30354e9858fe2cd5a4 /global-functions.rsc
parent557823c5c1c364d2d662069d4690640654fa1267 (diff)
global-functions: split off $FormatMultiLines ...
... to format multiple lines from an array.
Diffstat (limited to 'global-functions.rsc')
-rw-r--r--global-functions.rsc28
1 files changed, 21 insertions, 7 deletions
diff --git a/global-functions.rsc b/global-functions.rsc
index 3d35a8d..8c96c72 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -31,6 +31,7 @@
:global EitherOr;
:global EscapeForRegEx;
:global FormatLine;
+:global FormatMultiLines;
:global GetMacVendor;
:global GetRandom20CharAlNum;
:global GetRandom20CharHex;
@@ -339,25 +340,38 @@
# format a line for output
:set FormatLine do={
- :local Key [ :tostr $1 ];
- :local Values [ :toarray $2 ];
- :local Indent [ :tonum $3 ];
+ :local Key [ :tostr $1 ];
+ :local Value [ :tostr $2 ];
+ :local Indent [ :tonum $3 ];
:local Spaces " ";
:local Return "";
:global EitherOr;
- :global FormatLine;
:set Indent [ $EitherOr $Indent 16 ];
:if ([ :len $Key ] > 0) do={ :set Return ($Key . ":"); }
:if ([ :len $Key ] > ($Indent - 2)) do={
- :set Return ($Return . "\n" . [ :pick $Spaces 0 $Indent ] . ($Values->0));
+ :set Return ($Return . "\n" . [ :pick $Spaces 0 $Indent ] . $Value);
} else={
- :set Return ($Return . [ :pick $Spaces 0 ($Indent - [ :len $Return ]) ] . ($Values->0));
+ :set Return ($Return . [ :pick $Spaces 0 ($Indent - [ :len $Return ]) ] . $Value);
}
+
+ :return $Return;
+}
+
+# format multiple lines for output
+:set FormatMultiLines do={
+ :local Key [ :tostr $1 ];
+ :local Values [ :toarray $2 ];
+ :local Indent [ :tonum $3 ];
+ :local Return;
+
+ :global FormatLine;
+
+ :set Return [ $FormatLine $Key ($Values->0) $Indent ];
:foreach Value in=[ :pick $Values 1 [ :len $Values ] ] do={
- :set Return ($Return . "\n" . [ $FormatLine "" ({$Value}) $Indent ]);
+ :set Return ($Return . "\n" . [ $FormatLine "" $Value $Indent ]);
}
:return $Return;