mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2024-11-21 14:18:57 -07:00
Add llReplaceSubString calculation + tests
This commit is contained in:
parent
e4c9627772
commit
5f1062d378
3 changed files with 83 additions and 0 deletions
|
@ -1818,6 +1818,31 @@ def llPow(base, exp):
|
||||||
except ValueError: # should happen only with negative base and noninteger exponent
|
except ValueError: # should happen only with negative base and noninteger exponent
|
||||||
return Indet
|
return Indet
|
||||||
|
|
||||||
|
def llReplaceSubString(source, search, replace, count):
|
||||||
|
source = fs(source)
|
||||||
|
search = fs(search)
|
||||||
|
replace = fs(replace)
|
||||||
|
count = fi(count)
|
||||||
|
|
||||||
|
if not search:
|
||||||
|
return source
|
||||||
|
if count == 0:
|
||||||
|
return source.replace(search, replace)
|
||||||
|
if count > 0:
|
||||||
|
return source.replace(search, replace, count)
|
||||||
|
# Replace *last* occurrences of "search" in "source"
|
||||||
|
slen = len(search)
|
||||||
|
i = len(source)
|
||||||
|
while True:
|
||||||
|
i = source.rfind(search, 0, i)
|
||||||
|
if i < 0:
|
||||||
|
break
|
||||||
|
source = source[:i] + replace + source[i + slen:]
|
||||||
|
count += 1
|
||||||
|
if count == 0:
|
||||||
|
break
|
||||||
|
return source
|
||||||
|
|
||||||
def llRot2Angle(r):
|
def llRot2Angle(r):
|
||||||
r = q2f(r)
|
r = q2f(r)
|
||||||
# Used by llAngleBetween.
|
# Used by llAngleBetween.
|
||||||
|
|
|
@ -197,4 +197,33 @@
|
||||||
, llSubStringIndex("a", "blah")
|
, llSubStringIndex("a", "blah")
|
||||||
, llStringTrim(" a\n
", STRING_TRIM)
|
, llStringTrim(" a\n
", STRING_TRIM)
|
||||||
, llStringTrim("", STRING_TRIM)
|
, llStringTrim("", STRING_TRIM)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", -4)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", -3)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", -2)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", -1)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", 0)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", 1)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", 2)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", 3)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "aba", "faba", 4)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "eba", "feba", -4)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "eba", "feba", -1)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "eba", "feba", 0)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "eba", "feba", 1)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "eba", "feba", 4)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "", "faba", -20)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "", "faba", -1)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "", "faba", 0)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "", "faba", 1)
|
||||||
|
, llReplaceSubString("cabadabaeaba", "", "faba", 20)
|
||||||
|
, llReplaceSubString("", "", "faba", -2)
|
||||||
|
, llReplaceSubString("", "", "faba", -1)
|
||||||
|
, llReplaceSubString("", "", "faba", 0)
|
||||||
|
, llReplaceSubString("", "", "faba", 1)
|
||||||
|
, llReplaceSubString("", "", "faba", 2)
|
||||||
|
, llReplaceSubString("", "a", "ba", -2)
|
||||||
|
, llReplaceSubString("", "a", "ba", -1)
|
||||||
|
, llReplaceSubString("", "a", "ba", 0)
|
||||||
|
, llReplaceSubString("", "a", "ba", 1)
|
||||||
|
, llReplaceSubString("", "a", "ba", 2)
|
||||||
]
|
]
|
||||||
|
|
|
@ -197,4 +197,33 @@
|
||||||
, -1
|
, -1
|
||||||
, "a"
|
, "a"
|
||||||
, ""
|
, ""
|
||||||
|
, "cfabadfabaefaba"
|
||||||
|
, "cfabadfabaefaba"
|
||||||
|
, "cabadfabaefaba"
|
||||||
|
, "cabadabaefaba"
|
||||||
|
, "cfabadfabaefaba"
|
||||||
|
, "cfabadabaeaba"
|
||||||
|
, "cfabadfabaeaba"
|
||||||
|
, "cfabadfabaefaba"
|
||||||
|
, "cfabadfabaefaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, "cabadabaeaba"
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
|
, ""
|
||||||
]
|
]
|
Loading…
Reference in a new issue