Added findStringInstance function to strings package
This commit is contained in:
@@ -82,4 +82,41 @@ fun -string !matchStart -string &str -string &instr
|
||||
call !mid &store
|
||||
equal $store $instr &store
|
||||
return $store
|
||||
endfun
|
||||
|
||||
fun -int !findStringInstance -string &str -string &instr -int &instance
|
||||
getstrsize $instr &len
|
||||
subtract $len 1 &len
|
||||
set &idx $len
|
||||
|
||||
@loop
|
||||
set &tempstr ""
|
||||
subtract $idx $len &tempidx
|
||||
subtract $tempidx 1 &tempidx
|
||||
@subloop
|
||||
equal $tempidx $idx &store
|
||||
if $store %continue
|
||||
add $tempidx 1 &tempidx
|
||||
|
||||
getstrcharat $str $tempidx &store
|
||||
add $tempstr $store &tempstr
|
||||
jump %subloop
|
||||
|
||||
|
||||
@continue
|
||||
equal $tempstr $instr &store
|
||||
if $store %decrement
|
||||
add $idx 1 &idx
|
||||
jump %loop
|
||||
|
||||
@decrement
|
||||
equal $instance 0 &store
|
||||
if $store %end
|
||||
subtract $instance 1 &instance
|
||||
add $idx 1 &idx
|
||||
jump %loop
|
||||
|
||||
@end
|
||||
subtract $idx $len &idx
|
||||
return $idx
|
||||
endfun
|
Reference in New Issue
Block a user