diff --git a/config/mdarray.cfg b/config/mdarray.cfg index 8687c241..5741084b 100644 --- a/config/mdarray.cfg +++ b/config/mdarray.cfg @@ -10,23 +10,24 @@ islists = [ result $bool ] -hasQuotePair = [ - bool = 0 - got_open_quote = -1 - got_close_quote = -1 - loop r (strlen $arg1) [ - if (testchar (substr $arg1 $r 1) 8) [ - if (= $got_open_quote -1) [ - got_open_quote = $r - ] [ - got_close_quote = $r - break; - ] +countQuotes = [ + numquotes = 0 + loop q (strlen $arg1) [ + if (testchar (substr $arg1 $q 1) 8) [ + += numquotes 1 + ] + ] + result $numquotes +] + +getQuotePosition = [ + open_q = -1 + loop h (strlen $arg1) [ + if (testchar (substr $arg1 $h 1) 8) [ + open_q = $h + break ] ] - if (&& (!= $got_open_quote -1) (&& (!= $got_close_quote -1) (!= $got_open_quote $got_close_quote))) [ - result 1 - ] [ result 0 ] ] reverseString = [ @@ -66,7 +67,7 @@ MDArray_New_Subarray = [ ] MDArray_Get_Bracket_Positions = [ - open_bracket_pos = (+ (strpos $arg1 $arg2) (strlen $arg2)) + open_bracket_pos = (+ (strpos $arg1 $arg2) (+ (strlen $arg2) 1)) close_bracket_pos = -1 loop i (- (strlen $arg1) $open_bracket_pos) [ @@ -87,18 +88,13 @@ MDArray_Get = [ if (!= $close_bracket_pos -1) [ += open_bracket_pos 1 // skip the bracket itself when extracting the subarray with the line below + -= close_bracket_pos 1 subarray = (substr $mdarray $open_bracket_pos (- $close_bracket_pos $open_bracket_pos)) - subarray = (substr $subarray 2 (- (strlen $subarray) 3)) // trim brackets/whitespace from the subarray - subarray = (substr $subarray 1 (- (strlen $subarray) 1)) // trim first quotation from the subarray - subarray = (substr $subarray 0 (- (strlen $subarray) 1)) // trim last quotation from the subarray - // double check that the first and last chars of the subarray are not quotations - firstchar = (substr $subarray 0 1) - lastchar = (substr $subarray (- (strlen $subarray) 1) 1) - // trim quotations - if (! (hasQuotePair $subarray)) [ // only if its not a multi-word elements array - if (testchar $firstchar 8) [ subarray = (substr $subarray 1 (- (strlen $subarray) 1)) ] - if (testchar $lastchar 8) [ subarray = (substr $subarray 0 (- (strlen $subarray) 1)) ] + if (<= (countQuotes $subarray) 2) [ // quotes need to be trimmed from single-list subarrays + getQuotePosition $subarray + subarray = (substr $subarray (+ $open_q 1)) + subarray = (substr $subarray 0 (- (strlen $subarray) 1)) ] if (= $arg3 -1) [