mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Add newly introduced functions llOrd, llChar, llHash
This commit is contained in:
parent
3400d19132
commit
c4f210138f
5 changed files with 146 additions and 1 deletions
|
@ -1098,6 +1098,54 @@ def llCeil(f):
|
|||
return -2147483648
|
||||
return int(math.ceil(f))
|
||||
|
||||
def llChar(code):
|
||||
code = fi(code)
|
||||
# The result is consistent with a conversion of the codepoint to
|
||||
# UTF-8-1993, then using InternalUTF8toString on the result.
|
||||
# A thorough test shows that llChar(n) equals llUnescapeURL(utf8_1993)
|
||||
# up to codepoint 0x13FFFF. Furthermore llChar(0x200000) returns "?????",
|
||||
# and llChar(0x7FFFFFFF) returns "??????", which are also consistent with
|
||||
# that. LSO also returns UTF-8-1993 for codepoints > 0x10FFFF. So, the
|
||||
# internal implementation is likely to form a UTF8-1993 string from the
|
||||
# codepoint and then convert that to string, like this:
|
||||
# if code < 0:
|
||||
# return u'?'
|
||||
# if code < 0x80:
|
||||
# s = (code,)
|
||||
# elif code < 0x800:
|
||||
# s = (0xC0+(code >> 6), 0x80+(code&0x3F))
|
||||
# elif code < 0x10000:
|
||||
# s = (0xE0+(code >> 12), 0x80+((code >> 6)&0x3F), 0x80+(code&0x3F))
|
||||
# elif code < 0x200000:
|
||||
# s = (0xF0+(code >> 18), 0x80+((code >> 12)&0x3F),
|
||||
# 0x80+((code >> 6)&0x3F), 0x80+(code&0x3F))
|
||||
# elif code < 0x4000000:
|
||||
# s = (0xF8+(code >> 24),
|
||||
# 0x80+((code >> 18)&0x3F), 0x80+((code >> 12)&0x3F),
|
||||
# 0x80+((code >> 6)&0x3F), 0x80+(code&0x3F))
|
||||
# else:
|
||||
# s = (0xFC+(code >> 30), 0x80+((code >> 24)&0x3F),
|
||||
# 0x80+((code >> 18)&0x3F), 0x80+((code >> 12)&0x3F),
|
||||
# 0x80+((code >> 6)&0x3F), 0x80+(code&0x3F))
|
||||
# return zstr(InternalUTF8toString(bytearray(s)))
|
||||
|
||||
# Here's an alternative, simpler implementation that only works for Mono:
|
||||
if lslcommon.LSO:
|
||||
raise ELSLCantCompute
|
||||
if code == 0:
|
||||
return u''
|
||||
if code < 0:
|
||||
return u'?'
|
||||
if code > 0x10FFFF:
|
||||
if code >= 0x4000000:
|
||||
return u'??????'
|
||||
if code >= 0x200000:
|
||||
return u'?????'
|
||||
return u'????'
|
||||
if (0xD800 <= code <= 0xDFFF) or code == 0xFFFE:
|
||||
return u'???'
|
||||
return unichr(code)
|
||||
|
||||
def llCos(f):
|
||||
f = ff(f)
|
||||
if math.isinf(f):
|
||||
|
@ -1235,6 +1283,13 @@ def llGetSubString(s, start, end):
|
|||
s = fs(s)
|
||||
return InternalGetDeleteSubSequence(s, start, end, isGet=True)
|
||||
|
||||
def llHash(s):
|
||||
s = fs(s)
|
||||
hash = 0
|
||||
for i in s:
|
||||
hash = (hash * 65599 + ord(i)) & 0xFFFFFFFF
|
||||
return S32(hash)
|
||||
|
||||
def llInsertString(s, pos, src):
|
||||
s = fs(s)
|
||||
pos = fi(pos)
|
||||
|
@ -1625,6 +1680,14 @@ def llModPow(base, exp, mod):
|
|||
|
||||
return S32(ret)
|
||||
|
||||
def llOrd(val, index):
|
||||
val = fs(val)
|
||||
index = fi(index)
|
||||
L = len(val)
|
||||
if -L <= index < L:
|
||||
return ord(val[index]) # we're assuming it won't ever need F32()
|
||||
return 0
|
||||
|
||||
def llParseString2List(s, exc, inc, KeepNulls=False):
|
||||
s = fs(s)
|
||||
exc = fl(exc)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue