From 9edba5582eefda28106c901f4b6fbede5d6c8e94 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 31 Jan 2023 16:58:09 +0000 Subject: [PATCH] mantis 9056: add llReplaceSubString() --- .../Shared/Api/Implementation/LSL_Api.cs | 36 +++++++++++++++++++ .../Shared/Api/Interface/ILSL_Api.cs | 2 ++ .../Shared/Api/Runtime/LSL_Stub.cs | 5 +++ 3 files changed, 43 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 7ee9d77e4a..eda1cf0bf0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -18700,6 +18700,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } return hash; } + + public LSL_String llReplaceSubString(LSL_String src, LSL_String pattern, LSL_String replacement, int count) + { + RegexOptions RegexOptions; + if (count < 0) + { + RegexOptions = RegexOptions.CultureInvariant | RegexOptions.RightToLeft; + count = -count; + } + else + { + RegexOptions = RegexOptions.CultureInvariant; + if (count == 0) + count = -1; + } + + + try + { + if (string.IsNullOrEmpty(src.m_string)) + return src; + + if (string.IsNullOrEmpty(pattern.m_string)) + return src; + + Regex rx = new Regex(pattern, RegexOptions, new TimeSpan(500000)); // 50ms) + if (replacement == null) + return rx.Replace(src.m_string, string.Empty, count); + + return rx.Replace(src.m_string, replacement.m_string, count); + } + catch + { + return src; + } + } } public class NotecardCache diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index c188c11391..16850de035 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs @@ -486,5 +486,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_String llChar(LSL_Integer unicode); LSL_Integer llOrd(LSL_String s, LSL_Integer index); LSL_Integer llHash(LSL_String s); + + LSL_String llReplaceSubString(LSL_String src, LSL_String pattern, LSL_String replacement, int count); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index 08c30e7299..7e35c4927d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -2212,5 +2212,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { return m_LSL_Functions.llHash(s); } + + public LSL_String llReplaceSubString(LSL_String src, LSL_String pattern, LSL_String replacement, int count) + { + return m_LSL_Functions.llReplaceSubString(src, pattern, replacement, count); + } } }