From 6a2d9e8ec38a6764d1170afc7a086adcffb8d09c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 31 Jan 2023 17:16:33 +0000 Subject: [PATCH] mantis 9056: add llReplaceSubString() --- .../Shared/Api/Implementation/LSL_Api.cs | 35 +++++++++++++++++++ .../Shared/Api/Interface/ILSL_Api.cs | 1 + .../Shared/Api/Runtime/LSL_Stub.cs | 5 +++ 3 files changed, 41 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 1fcd58fa24..ea37803525 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -18668,6 +18668,41 @@ 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..66562915c3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs @@ -486,5 +486,6 @@ 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 b722f41c6c..c7ccfb2b39 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -2209,5 +2209,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); + } } }