more MDArray fixes/cleanup
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7348 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+28
-28
@@ -13,9 +13,9 @@ islists = [
|
||||
|
||||
countQuotes = [
|
||||
numquotes = 0
|
||||
loop q (strlen $arg1) [
|
||||
if (testchar (substr $arg1 $q 1) 8) [
|
||||
+= numquotes 1
|
||||
loop cq (strlen $arg1) [
|
||||
if (testchar (substr $arg1 $cq 1) 8) [
|
||||
++ numquotes
|
||||
]
|
||||
]
|
||||
result $numquotes
|
||||
@@ -23,9 +23,9 @@ countQuotes = [
|
||||
|
||||
getQuotePosition = [
|
||||
open_q = -1
|
||||
loop h (strlen $arg1) [
|
||||
if (testchar (substr $arg1 $h 1) 8) [
|
||||
open_q = $h
|
||||
loop gqp (strlen $arg1) [
|
||||
if (testchar (substr $arg1 $gqp 1) 8) [
|
||||
open_q = $gqp
|
||||
break
|
||||
]
|
||||
]
|
||||
@@ -44,8 +44,8 @@ extractSubarrayName = [
|
||||
open_bracket_pos = $arg2
|
||||
subarray_name = []
|
||||
|
||||
loop d (strlen $arg1) [
|
||||
tmpchar = (substr $arg1 (- $open_bracket_pos (+ $d 2)) 1)
|
||||
loop esn (strlen $arg1) [
|
||||
tmpchar = (substr $arg1 (- $open_bracket_pos (+ $esn 2)) 1)
|
||||
if (testchar $tmpchar 7) break [
|
||||
if (&& (! (strcmp $tmpchar "[")) (! (strcmp $tmpchar "]"))) [
|
||||
subarray_name = (concatword $subarray_name $tmpchar)
|
||||
@@ -91,13 +91,13 @@ MDArray_Get = [
|
||||
if (!= $target -1) [
|
||||
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
|
||||
++ open_bracket_pos // skip the bracket itself when extracting the subarray with the line below
|
||||
-- close_bracket_pos
|
||||
subarray = (substr $mdarray $open_bracket_pos (- $close_bracket_pos $open_bracket_pos))
|
||||
|
||||
if (countQuotes $subarray) [
|
||||
if (= (countQuotes $subarray) 2) [
|
||||
getQuotePosition $subarray
|
||||
if (&& (|| (= $open_q 0) (= $open_q 1)) (testchar (substr $subarray -1) 8)) [ // beginning/end quotes need to be trimmed from single-list subarrays
|
||||
if (&& (checkrange $open_q 0 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))
|
||||
]
|
||||
@@ -130,8 +130,8 @@ MDArray_Get_All_Subarray_Names = [
|
||||
opening_brackets = (MDArray_Get_All_Opening_Bracket_Positions (getalias $arg1))
|
||||
subarray_names = []
|
||||
|
||||
loop r (listlen $opening_brackets) [
|
||||
add2list subarray_names (extractSubarrayName (getalias $arg1) (at $opening_brackets $r))
|
||||
loop mgn (listlen $opening_brackets) [
|
||||
add2list subarray_names (extractSubarrayName (getalias $arg1) (at $opening_brackets $mgn))
|
||||
]
|
||||
result $subarray_names
|
||||
]
|
||||
@@ -143,11 +143,11 @@ MDArray_Search = [
|
||||
subarrays = (MDArray_Get_All_Subarray_Names $arg1)
|
||||
search_results = []
|
||||
|
||||
loop u (listlen $subarrays) [
|
||||
curarray = (MDArray_Get $arg1 (at $subarrays $u) -1)
|
||||
loop ms (listlen $subarrays) [
|
||||
curarray = (MDArray_Get $arg1 (at $subarrays $ms) -1)
|
||||
if (strstr $curarray $token) [
|
||||
if (! (strstr $search_results (at $subarrays $u))) [
|
||||
add2list search_results (at $subarrays $u)
|
||||
if (! (strstr $search_results (at $subarrays $ms))) [
|
||||
add2list search_results (at $subarrays $ms)
|
||||
]
|
||||
]
|
||||
]
|
||||
@@ -162,9 +162,9 @@ MDArray_Delete_Subarray = [
|
||||
delstr = []
|
||||
|
||||
if (!= $target_pos -1) [
|
||||
loop h (strlen $orig_array) [
|
||||
if (< $h $target_pos) continue [
|
||||
if (strcmp (substr $orig_array $h 1) "]") [ gotclose = $h; break ]
|
||||
loop mds (strlen $orig_array) [
|
||||
if (< $mds $target_pos) continue [
|
||||
if (strcmp (substr $orig_array $mds 1) "]") [ gotclose = $mds; break ]
|
||||
]
|
||||
]
|
||||
delstr = (substr $orig_array $target_pos (- (+ $gotclose 1) $target_pos))
|
||||
@@ -179,12 +179,12 @@ MDArray_Modify_Subarray = [
|
||||
new_elem = $arg4
|
||||
new_subarray = []
|
||||
|
||||
if (<= (countQuotes $original_subarray) 2) [
|
||||
if (! (countQuotes $original_subarray)) [
|
||||
original_subarray = (addpunct $original_subarray)
|
||||
]
|
||||
loop j (listlen $original_subarray) [
|
||||
next_elem = (at $original_subarray $j)
|
||||
if (= $j $target_elem) [
|
||||
loop mms (listlen $original_subarray) [
|
||||
next_elem = (at $original_subarray $mms)
|
||||
if (= $mms $target_elem) [
|
||||
if (> (listlen $new_elem) 1) [
|
||||
add2list new_subarray (addpunct $new_elem)
|
||||
] [ add2list new_subarray $new_elem ]
|
||||
@@ -203,14 +203,14 @@ MDArray_Add_To_Subarray = [
|
||||
to_add = $arg3
|
||||
if (!= (findlist $mdarray $arg2) -1) [
|
||||
subarray = (MDArray_Get $arg1 $arg2 -1)
|
||||
if (<= (countQuotes $subarray) 2) [ subarray = (addpunct $subarray) ]
|
||||
if (<= (countQuotes $to_add) 2) [ to_add = (addpunct $to_add) ]
|
||||
if (! (countQuotes $subarray)) [ subarray = (addpunct $subarray) ]
|
||||
if (! (countQuotes $to_add)) [ to_add = (addpunct $to_add) ]
|
||||
MDArray_Delete_Subarray $arg1 $arg2
|
||||
MDArray_New_Subarray $arg1 $arg2 (format [%1 %2] $subarray $to_add)
|
||||
]
|
||||
]
|
||||
|
||||
// some of these aliases can cause issues if they get stored in saved.cfg (missing bracket errors/etc.)
|
||||
addListOnQuit [bool MDArray_New_Subarray MDArray_Get_Bracket_Positions MDArray_Get reverseString MDArray_Get_All_Opening_Bracket_Positions MDArray_Get_Subarray_Count MDArray_Get_All_Subarray_Names extractSubarrayName MDArray_Search MDArray_Delete_Subarray MDArray_Modify_Subarray original_subarray target_elem new_elem new_subarray j next_elem islists hasQuotePair got_open_quote got_close_quote r i d mdarray subarray firstchar lastchar oldstr newstr subarray_names subarray_name tmpchar token subarrays search_results curarray orig_array target_subarray target_pos gotclose delstr h next_char]
|
||||
addListOnQuit [bool MDArray_New_Subarray MDArray_Get_Bracket_Positions MDArray_Get reverseString MDArray_Get_All_Opening_Bracket_Positions MDArray_Get_Subarray_Count MDArray_Get_All_Subarray_Names extractSubarrayName MDArray_Search MDArray_Delete_Subarray MDArray_Modify_Subarray original_subarray target_elem new_elem new_subarray next_elem islists hasQuotePair got_open_quote got_close_quote mdarray subarray firstchar lastchar oldstr newstr subarray_names subarray_name tmpchar token subarrays search_results curarray orig_array target_subarray target_pos gotclose delstr next_char]
|
||||
|
||||
persistidents 1
|
||||
|
||||
Reference in New Issue
Block a user