add llOrd, llChar llHash

This commit is contained in:
UbitUmarov
2021-10-02 14:17:11 +01:00
parent a5b417fca1
commit 68efbfc603
5 changed files with 312 additions and 83 deletions

View File

@@ -3258,7 +3258,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return src.Substring(0,end+1);
}
// Both indices are positive
return src.Substring(start, (end+1) - start);
return src.Substring(start, (end + 1) - start);
}
// Inverted substring (end < start)
@@ -3295,11 +3295,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
if (start < src.Length)
{
return src.Substring(0,end+1) + src.Substring(start);
return src.Substring(0, end + 1) + src.Substring(start);
}
else
{
return src.Substring(0,end+1);
return src.Substring(0, end + 1);
}
}
}
@@ -3331,7 +3331,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (start <= end)
{
// If both bounds are outside of the existing
// string, then return unchanges.
// string, then return unchanged.
if (end < 0 || start >= src.Length)
{
return src;
@@ -3364,11 +3364,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
if (start < src.Length)
{
return src.Remove(start).Remove(0,end+1);
return src.Remove(start).Remove(0, end + 1);
}
else
{
return src.Remove(0,end+1);
return src.Remove(0, end + 1);
}
}
else
@@ -3391,10 +3391,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// which case it is end-relative. The index may exceed either
/// string bound, with the result being a concatenation.
/// </summary>
// this is actually wrong. acording to SL wiki, this function should not support negative indexes.
// this is actually wrong. according to SL wiki, this function should not support negative indexes.
public LSL_String llInsertString(string dest, int index, string src)
{
// Normalize indices (if negative).
// After normalization they may still be
// negative, but that is now relative to
@@ -3429,7 +3428,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (index >= dest.Length)
{
return dest+src;
return dest + src;
}
// The index is in bounds.
@@ -3437,7 +3436,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// be assigned to the first character of the inserted string.
// So unlike the other string operations, we do not add one
// to get the correct string length.
return dest.Substring(0,index)+src+dest.Substring(index);
return dest.Substring(0, index) + src + dest.Substring(index);
}
@@ -11153,7 +11152,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
{
// acording to SL wiki this must indicate a single link number or link_root or link_this.
// according to SL wiki this must indicate a single link number or link_root or link_this.
// keep other options as before
List<SceneObjectPart> parts;
@@ -18402,6 +18401,104 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return ScriptBaseClass.JSON_INVALID;
}
}
public LSL_String llChar(LSL_Integer unicode)
{
if(unicode == 0)
return string.Empty;
try
{
return Char.ConvertFromUtf32(unicode);
}
catch { }
return "\ufffd";
}
public LSL_Integer llOrd(LSL_String s, LSL_Integer index)
{
if (string.IsNullOrEmpty(s))
return 0;
if(index < 0)
index += s.Length;
if (index < 0 || index >= s.Length)
return 0;
char c = s.m_string[index];
if(c >= 0xdc00 && c <= 0xdfff)
{
--index;
if (index < 0)
return 0;
int a = c - 0xdc00;
c = s.m_string[index];
if (c < 0xd800 || c > 0xdbff)
return 0;
c -= (char)(0xd800 - 0x40);
return a + (c << 10);
}
if (c >= 0xd800)
{
if(c < 0xdc00)
{
++index;
if (index >= s.Length)
return 0;
c -= (char)(0xd800 - 0x40);
int a = (c << 10);
c = s.m_string[index];
if (c < 0xdc00 || c > 0xdfff)
return 0;
c -= (char)0xdc00;
return a + c;
}
else if(c < 0xe000)
return 0;
}
return (int)c;
}
public LSL_Integer llHash(LSL_String s)
{
if (string.IsNullOrEmpty(s))
return 0;
int hash = 0;
char c;
for(int i = 0; i < s.Length; ++i)
{
hash *= 65599;
// on modern intel/amd this is faster than the tradicional optimization:
// hash = (hash << 6) + (hash << 16) - hash;
c = s.m_string[i];
if (c >= 0xd800)
{
if(c < 0xdc00)
{
++i;
if(i >= s.Length)
return 0;
c -= (char)(0xd800 - 0x40);
hash += (c << 10);
c = s.m_string[i];
if(c < 0xdc00 || c > 0xdfff)
return 0;
c -= (char)(0xdc00);
}
else if(c < 0xe000)
return 0;
}
hash += c;
}
return hash;
}
}
public class NotecardCache

View File

@@ -479,5 +479,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_Rotation llGetRegionSunRotation();
LSL_Rotation llGetMoonRotation();
LSL_Rotation llGetRegionMoonRotation();
LSL_String llChar(LSL_Integer unicode);
LSL_Integer llOrd(LSL_String s, LSL_Integer index);
LSL_Integer llHash(LSL_String s);
}
}

View File

@@ -35,7 +35,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public partial class ScriptBaseClass
{
// SCRIPTS CONSTANTS
public static readonly LSLInteger OS_APIVERSION = 18;
public static readonly LSLInteger OS_APIVERSION = 19;
public static readonly LSLInteger TRUE = 1;
public static readonly LSLInteger FALSE = 0;

View File

@@ -2182,5 +2182,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_LSL_Functions.llGetRegionMoonRotation();
}
public LSL_String llChar(LSL_Integer unicode)
{
return m_LSL_Functions.llChar(unicode);
}
public LSL_Integer llOrd(LSL_String s, LSL_Integer index)
{
return m_LSL_Functions.llOrd(s, index);
}
public LSL_Integer llHash(LSL_String s)
{
return m_LSL_Functions.llHash(s);
}
}
}