From 9138c17f8c3bbd415a0defe6ada431075a7c8f04 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 18 Oct 2023 18:25:33 +0200 Subject: [PATCH] =?UTF-8?q?global-functions:=20$ParseJson:=20return=20arra?= =?UTF-8?q?y=20as=20...=20array=20=F0=9F=98=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to assemble the string here, just to split it again later. --- global-functions.rsc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 878e95e..443771d 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -719,26 +719,33 @@ :local Val1 ($Input->($I + 1)); :local Val2 ($Input->($I + 2)); :if ($Val1 = ":") do={ - :set ($Return->$Key) $Val2; :set Skip 2; + :set ($Return->$Key) $Val2; :set Done true; } :if ($Done = false && $Val1 = ":[") do={ - :local Tmp ""; - :local End; + :local Last false; :set Skip 1; + :set ($Return->$Key) ({}); :do { :set Skip ($Skip + 1); :local ValX ($Input->($I + $Skip)); - :set End [ :pick $ValX ([ :len $ValX ] - 1) ]; - :set Tmp ($Tmp . "},{" . $ValX); - } while=($End != "]"); - :set ($Return->$Key) ("{" . [ :pick $Tmp 0 ([ :len $Tmp ] - 1) ] . "}"); + :if ([ :pick $ValX ([ :len $ValX ] - 1) ] = "]") do={ + :set Last true; + :set ValX [ :pick $ValX 0 ([ :len $ValX ] - 1) ]; + } + :set ($Return->$Key) (($Return->$Key), $ValX); + } while=($Last = false); + :set Done true; + } + :if ($Done = false && $Val1 = ":[]") do={ + :set Skip 1; + :set ($Return->$Key) ({}); :set Done true; } :if ($Done = false) do={ - :set ($Return->$Key) [ :pick $Val1 1 [ :len $Val1 ] ]; :set Skip 1; + :set ($Return->$Key) [ :pick $Val1 1 [ :len $Val1 ] ]; } } }