From 9dfb906666e5d5d1a17fdfd170fbd58254a0cce0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 18 Nov 2018 22:40:59 +0000 Subject: add a few string functions to OSSL --- .../Shared/Api/Implementation/OSSL_Api.cs | 177 ++++++++++++++++++++- .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 11 ++ .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 50 ++++++ 3 files changed, 237 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index e9a3d0b..f0177db 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -5130,5 +5130,180 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key); return account.UserCountry; } + + public LSL_String osStringSubString(LSL_String src, LSL_Integer offset) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return ""; + if (offset >= src.Length) + return ""; + if (offset <= 0) + return src; + return ((string)src).Substring(offset); + } + + public LSL_String osStringSubString(LSL_String src, LSL_Integer offset, LSL_Integer length) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return ""; + if (length <= 0 || offset >= src.Length) + return ""; + if (offset <= 0) + { + if(length == src.Length) + return src; + offset = 0; + } + if (length > src.Length - offset) + length = src.Length - offset; + return ((string)src).Substring(offset, length); + } + + public LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return 0; + if (string.IsNullOrEmpty(value)) + return 0; + + bool ign = (ignorecase != 0); + return ((string)src).StartsWith(value, ignorecase, Culture.GetDefaultCurrentCulture()) ? 1 : 0; + } + + public LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return 0; + if (string.IsNullOrEmpty(value)) + return 0; + + bool ign = (ignorecase != 0); + return ((string)src).EndsWith(value, ign, Culture.GetDefaultCurrentCulture()) ? 1 : 0; + } + + public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return -1; + if (string.IsNullOrEmpty(value)) + return -1; + + if (ignorecase == 0) + return ((string)src).IndexOf(value, StringComparison.CurrentCulture); + return ((string)src).IndexOf(value, StringComparison.CurrentCultureIgnoreCase); + } + + public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, + LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return -1; + if (string.IsNullOrEmpty(value)) + return -1; + if (offset >= src.Length) + return -1; + else if (offset < 0) + offset = 0; + + if (count <= 0) + count = src.Length - offset; + else if (count > src.Length - offset) + count = src.Length - offset; + + if (ignorecase == 0) + return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCulture); + return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase); + } + + public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return -1; + if (string.IsNullOrEmpty(value)) + return -1; + + if (ignorecase == 0) + return ((string)src).LastIndexOf(value, StringComparison.CurrentCulture); + return ((string)src).LastIndexOf(value, StringComparison.CurrentCultureIgnoreCase); + } + + public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, + LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase) + { + m_host.AddScriptLPS(1); + CheckThreatLevel(); + + if (string.IsNullOrEmpty(src)) + return -1; + if (string.IsNullOrEmpty(value)) + return -1; + if (offset >= src.Length) + return -1; + if (offset < 0) + offset = 0; + + if (count <= 0) + count = src.Length - offset; + else if (count > src.Length - offset) + count = src.Length - offset; + + if (ignorecase == 0) + return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCulture); + return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase); + } + + public LSL_String osStringRemove(LSL_String src, LSL_Integer offset, LSL_Integer count) + { + if (string.IsNullOrEmpty(src)) + return ""; + if (offset >= src.Length) + return ""; + if (offset < 0) + offset = 0; + + if (count <= 0) + count = src.Length - offset; + else if (count > src.Length - offset) + count = src.Length - offset; + + if (count >= src.Length) + return ""; + + + return ((string)src).Remove(offset, count); + } + + public LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue) + { + if (string.IsNullOrEmpty(src)) + return ""; + if (string.IsNullOrEmpty(oldvalue)) + return ""; + if (string.IsNullOrEmpty(newvalue)) + newvalue = null; + + return ((string)src).Replace(oldvalue, newvalue); + } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 2487a21..2ab1fff 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -529,5 +529,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_String osDetectedCountry(LSL_Integer number); LSL_String osGetAgentCountry(LSL_Key agentId); + + LSL_String osStringSubString(LSL_String src, LSL_Integer start); + LSL_String osStringSubString(LSL_String src, LSL_Integer start, LSL_Integer length); + LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase); + LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase); + LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase); + LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer start, LSL_Integer count, LSL_Integer ignorecase); + LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase); + LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer start, LSL_Integer count, LSL_Integer ignorecase); + LSL_String osStringRemove(LSL_String src, LSL_Integer start, LSL_Integer count); + LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index bc5aa5c..1c003a0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -1287,5 +1287,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { return m_OSSL_Functions.osGetAgentCountry(agentId); } + + public LSL_String osStringSubString(LSL_String src, LSL_Integer offset) + { + return m_OSSL_Functions.osStringSubString(src, offset); + } + + public LSL_String osStringSubString(LSL_String src, LSL_Integer offset, LSL_Integer length) + { + return m_OSSL_Functions.osStringSubString(src, offset, length); + } + + public LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + return m_OSSL_Functions.osStringStartsWith(src, value, ignorecase); + } + + public LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + return m_OSSL_Functions.osStringEndsWith(src, value, ignorecase); + } + + public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + return m_OSSL_Functions.osStringIndexOf(src, value, ignorecase); + } + + public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase) + { + return m_OSSL_Functions.osStringIndexOf(src, value, offset, count, ignorecase); + } + + public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase) + { + return m_OSSL_Functions.osStringLastIndexOf(src, value, ignorecase); + } + + public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase) + { + return m_OSSL_Functions.osStringLastIndexOf(src, value, offset, count, ignorecase); + } + + public LSL_String osStringRemove(LSL_String src, LSL_Integer offset, LSL_Integer count) + { + return m_OSSL_Functions.osStringRemove(src, offset, count); + } + + public LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue) + { + return m_OSSL_Functions.osStringReplace(src, oldvalue, newvalue); + } } } -- cgit v1.1