New functions for strings package
This commit is contained in:
@@ -22,10 +22,22 @@ Finds $len characters of $str, starting at $idx (no prerequisites).
|
|||||||
|
|
||||||
Finds the content of the `$instance`th instance of brackets, with the left bracket being the $left char and the right bracket of $right char (requires !findCharInstance).
|
Finds the content of the `$instance`th instance of brackets, with the left bracket being the $left char and the right bracket of $right char (requires !findCharInstance).
|
||||||
|
|
||||||
### fun -string !matchStart -string &str -string &instr
|
### fun -bool !matchStart -string &str -string &instr
|
||||||
|
|
||||||
Checks if the start of $str matches $instr (requires !mid).
|
Checks if the start of $str matches $instr (requires !mid).
|
||||||
|
|
||||||
### fun -int !findStringInstance -string &str -string &instr -int &instance
|
### fun -int !findStringInstance -string &str -string &instr -int &instance
|
||||||
|
|
||||||
The same as !findCharInstance, but allows a string to be parsed to be searched for (no prerequisites).
|
The same as !findCharInstance, but allows a string to be parsed to be searched for (no prerequisites).
|
||||||
|
|
||||||
|
### fun -string !removeLeft -string &string -int &num
|
||||||
|
|
||||||
|
Removes the first $num characters from a string (no prerequisites).
|
||||||
|
|
||||||
|
### fun -string !removeRight -string &string -int &num
|
||||||
|
|
||||||
|
You'll never guess what this does (it removes the last $num characters from a string) (no prerequisites).
|
||||||
|
|
||||||
|
### fun -bool !contains -string &str -string &instr
|
||||||
|
|
||||||
|
Checks if $str contains $instr (requires !mid).
|
@@ -74,7 +74,7 @@ fun -string !inBrackets -string &str -char &left -char &right -int &instance
|
|||||||
stdlnout $store
|
stdlnout $store
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
fun -string !matchStart -string &str -string &instr
|
fun -bool !matchStart -string &str -string &instr
|
||||||
getstrsize $instr &store
|
getstrsize $instr &store
|
||||||
pusharg $str
|
pusharg $str
|
||||||
pusharg 0
|
pusharg 0
|
||||||
@@ -120,3 +120,63 @@ fun -int !findStringInstance -string &str -string &instr -int &instance
|
|||||||
subtract $idx $len &idx
|
subtract $idx $len &idx
|
||||||
return $idx
|
return $idx
|
||||||
endfun
|
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