diff options
author | Christian Hesse <mail@eworm.de> | 2021-03-03 10:17:45 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-03-03 14:54:22 +0100 |
commit | 7829a6c33adfc0391a88d05e070d3c30397b4444 (patch) | |
tree | 3e1876d345592d8a9ebb8cfa87b03859e9e2566a | |
parent | a019ff861eae84d3c026861807bbde3d995d41ee (diff) |
global-functions: $UrlEncode: simplify code
-rw-r--r-- | global-functions | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/global-functions b/global-functions index 92d8fea..382722a 100644 --- a/global-functions +++ b/global-functions @@ -1016,24 +1016,25 @@ # url encoding :set UrlEncode do={ :local Input [ :tostr $1 ]; - :local Return ""; - :if ([ :len $Input ] > 0) do={ - :local Chars "\n\r !\"#\$%&'()*+,:;<=>\?@[\\]^`{|}~"; - :local Subs { "%0A"; "%0D"; "%20"; "%21"; "%22"; "%23"; "%24"; "%25"; "%26"; "%27"; - "%28"; "%29"; "%2A"; "%2B"; "%2C"; "%3A"; "%3B"; "%3C"; "%3D"; "%3E"; - "%3F"; "%40"; "%5B"; "%5C"; "%5D"; "%5E"; "%60"; "%7B"; "%7C"; "%7D"; - "%7E" }; + :if ([ :len $Input ] = 0) do={ + :return ""; + } + + :local Return ""; + :local Chars "\n\r !\"#\$%&'()*+,:;<=>\?@[\\]^`{|}~"; + :local Subs { "%0A"; "%0D"; "%20"; "%21"; "%22"; "%23"; "%24"; "%25"; "%26"; "%27"; + "%28"; "%29"; "%2A"; "%2B"; "%2C"; "%3A"; "%3B"; "%3C"; "%3D"; "%3E"; "%3F"; + "%40"; "%5B"; "%5C"; "%5D"; "%5E"; "%60"; "%7B"; "%7C"; "%7D"; "%7E" }; - :for I from=0 to=([ :len $Input ] - 1) do={ - :local Char [ :pick $Input $I ]; - :local Replace [ :find $Chars $Char ]; + :for I from=0 to=([ :len $Input ] - 1) do={ + :local Char [ :pick $Input $I ]; + :local Replace [ :find $Chars $Char ]; - :if ([ :len $Replace ] > 0) do={ - :set Char ($Subs->$Replace); - } - :set Return ($Return . $Char); + :if ([ :typeof $Replace ] = "num") do={ + :set Char ($Subs->$Replace); } + :set Return ($Return . $Char); } :return $Return; |