MDArray_Get fix
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7347 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+27
-20
@@ -3,8 +3,8 @@ persistidents 0
|
||||
|
||||
islists = [
|
||||
bool = 0
|
||||
loop i (listlen $arg1) [
|
||||
if (> (listlen (at $arg1 $i)) 1) [
|
||||
loop il (listlen $arg1) [
|
||||
if (> (listlen (at $arg1 $il)) 1) [
|
||||
bool = 1; break
|
||||
]
|
||||
]
|
||||
@@ -34,8 +34,8 @@ getQuotePosition = [
|
||||
reverseString = [
|
||||
oldstr = $arg1
|
||||
newstr = []
|
||||
loop i (strlen $oldstr) [
|
||||
newstr = (concatword $newstr (substr $oldstr (* (+ $i 1) -1) 1))
|
||||
loop ri (strlen $oldstr) [
|
||||
newstr = (concatword $newstr (substr $oldstr (* (+ $ri 1) -1) 1))
|
||||
]
|
||||
result $newstr
|
||||
]
|
||||
@@ -67,12 +67,14 @@ MDArray_New_Subarray = [
|
||||
]
|
||||
// finds the open and close bracket pair positions of a subarray in an existing mdarray
|
||||
MDArray_Get_Bracket_Positions = [
|
||||
open_bracket_pos = (+ (strpos $arg1 $arg2) (+ (strlen $arg2) 1))
|
||||
targ1 = $arg1
|
||||
targ2 = $arg2
|
||||
open_bracket_pos = (+ (strpos $targ1 $targ2) (+ (strlen $targ2) 1))
|
||||
close_bracket_pos = -1
|
||||
|
||||
loop i (- (strlen $arg1) $open_bracket_pos) [
|
||||
next_char = (+ (+ $open_bracket_pos $i) 1)
|
||||
if (strstr (substr $arg1 $next_char 1) "]") [
|
||||
loop mgp (- (strlen $targ1) $open_bracket_pos) [
|
||||
next_char = (+ (+ $open_bracket_pos $mgp) 1)
|
||||
if (strstr (substr $targ1 $next_char 1) "]") [
|
||||
close_bracket_pos = $next_char
|
||||
break
|
||||
]
|
||||
@@ -80,34 +82,39 @@ MDArray_Get_Bracket_Positions = [
|
||||
]
|
||||
// returns either an entire subarray or a single element from a subarray of an existing mdarray
|
||||
MDArray_Get = [
|
||||
mdarray = (getalias $arg1)
|
||||
target = (findlist $mdarray $arg2)
|
||||
marg1 = $arg1
|
||||
marg2 = $arg2
|
||||
marg3 = $arg3
|
||||
mdarray = (getalias $marg1)
|
||||
target = (findlist $mdarray $marg2)
|
||||
|
||||
if (!= $target -1) [
|
||||
MDArray_Get_Bracket_Positions $mdarray $arg2
|
||||
MDArray_Get_Bracket_Positions $mdarray $marg2
|
||||
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))
|
||||
|
||||
if (<= (countQuotes $subarray) 2) [ // quotes need to be trimmed from single-list subarrays
|
||||
if (countQuotes $subarray) [
|
||||
getQuotePosition $subarray
|
||||
subarray = (substr $subarray (+ $open_q 1))
|
||||
subarray = (substr $subarray 0 (- (strlen $subarray) 1))
|
||||
if (&& (|| (= $open_q 0) (= $open_q 1)) (testchar (substr $subarray -1) 8)) [ // beginning/end quotes need to be trimmed from single-list subarrays
|
||||
subarray = (substr $subarray (+ $open_q 1))
|
||||
subarray = (substr $subarray 0 (- (strlen $subarray) 1))
|
||||
]
|
||||
]
|
||||
|
||||
if (= $arg3 -1) [
|
||||
if (= $marg3 -1) [
|
||||
result $subarray
|
||||
] [ result (at $subarray $arg3) ]
|
||||
] [ result (at $subarray $marg3) ]
|
||||
]
|
||||
] [ echo (red)Error: $arg2 is not a subarray of $arg1 ]
|
||||
] [ echo (red)Error: $marg2 is not a subarray of $marg1 ]
|
||||
]
|
||||
// returns a list of all opening bracket "[" positions in an existing mdarray
|
||||
MDArray_Get_All_Opening_Bracket_Positions = [
|
||||
o_positions = []
|
||||
loop i (strlen $arg1) [
|
||||
if (strcmp (substr $arg1 $i 1) "[") [
|
||||
add2list o_positions $i
|
||||
loop mga (strlen $arg1) [
|
||||
if (strcmp (substr $arg1 $mga 1) "[") [
|
||||
add2list o_positions $mga
|
||||
]
|
||||
]
|
||||
if (listlen $o_positions) [
|
||||
|
||||
Reference in New Issue
Block a user