New functions for strings package
This commit is contained in:
@@ -40,7 +40,7 @@ fun -char !findCharInstance -string &str -char &char -int &instance
|
||||
@return
|
||||
return $idx
|
||||
|
||||
@end
|
||||
@end
|
||||
endfun
|
||||
|
||||
fun -string !mid -string &str -int &idx -int &len
|
||||
@@ -74,7 +74,7 @@ fun -string !inBrackets -string &str -char &left -char &right -int &instance
|
||||
stdlnout $store
|
||||
endfun
|
||||
|
||||
fun -string !matchStart -string &str -string &instr
|
||||
fun -bool !matchStart -string &str -string &instr
|
||||
getstrsize $instr &store
|
||||
pusharg $str
|
||||
pusharg 0
|
||||
@@ -119,4 +119,64 @@ fun -int !findStringInstance -string &str -string &instr -int &instance
|
||||
@end
|
||||
subtract $idx $len &idx
|
||||
return $idx
|
||||
endfun
|
||||
|
||||
fun -string !removeLeft -string &string -int &num
|
||||
getstrsize $string &len
|
||||
set &ans ""
|
||||
@loop
|
||||
equal $num $len &store
|
||||
if $store %end
|
||||
getstrcharat $string $num &store
|
||||
add $ans $store &ans
|
||||
add $num 1 &num
|
||||
jump %loop
|
||||
|
||||
@end
|
||||
return $ans
|
||||
endfun
|
||||
|
||||
fun -string !removeRight -string &string -int &num
|
||||
getstrsize $string &len
|
||||
subtract $len $num &len
|
||||
set &ans ""
|
||||
set &num 0
|
||||
@loop
|
||||
equal $num $len &store
|
||||
if $store %end
|
||||
getstrcharat $string $num &store
|
||||
add $ans $store &ans
|
||||
add $num 1 &num
|
||||
jump %loop
|
||||
|
||||
@end
|
||||
return $ans
|
||||
endfun
|
||||
|
||||
fun -bool !contains -string &str -string &instr
|
||||
getstrsize $str &len
|
||||
getstrsize $instr &inlen
|
||||
subtract $len $inlen &len
|
||||
set &idx 0
|
||||
|
||||
@loop
|
||||
equal $idx $len &store
|
||||
if $store %false
|
||||
|
||||
pusharg $str
|
||||
pusharg $idx
|
||||
pusharg $inlen
|
||||
call !mid &store
|
||||
|
||||
equal $store $instr &store
|
||||
if $store %true
|
||||
|
||||
add $idx 1 &idx
|
||||
jump %loop
|
||||
|
||||
@true
|
||||
return true
|
||||
|
||||
@false
|
||||
return false
|
||||
endfun
|
Reference in New Issue
Block a user