From e97b3945363c8f322b7ff7f4bf65f13d887d373b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:17:45 +0200 Subject: global-functions: introduce $EitherOr --- global-functions | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/global-functions b/global-functions index aa0ea07..48b58a6 100644 --- a/global-functions +++ b/global-functions @@ -24,6 +24,7 @@ :global DeviceInfo; :global DNSIsResolving; :global DownloadPackage; +:global EitherOr; :global EscapeForRegEx; :global FlushEmailQueue; :global FlushTelegramQueue; @@ -293,6 +294,16 @@ :return false; } +# return either first (if "true") or second +:set EitherOr do={ + :global IfThenElse; + + :if ([ :typeof $1 ] = "num") do={ + :return [ $IfThenElse ($1 != 0) $1 $2 ]; + } + :return [ $IfThenElse ([ :len [ :tostr $1 ] ] > 0) $1 $2 ]; +} + # escape for regular expression :set EscapeForRegEx do={ :local Input [ :tostr $1 ]; -- cgit v1.2.3-54-g00ecf