From 37a00427bc86bbff660f1d87643740fecf5b17a9 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 16 Feb 2009 01:58:26 +0000 Subject: Thank you, cmickeyb, for a patch to ass two string functions to OSSL. Fixes Mantis #3173 --- .../Shared/Api/Implementation/OSSL_Api.cs | 49 ++++++++++++++++++++++ .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 6 +++ .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 12 ++++++ 3 files changed, 67 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Shared') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 697fdb4..9658376 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -43,6 +43,7 @@ using OpenSim.Region.ScriptEngine.Shared.ScriptBase; using OpenSim.Region.ScriptEngine.Interfaces; using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces; using TPFlags = OpenSim.Framework.Constants.TeleportFlags; +using System.Text.RegularExpressions; using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; @@ -1105,5 +1106,53 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api loginURI = config.Configs["GridInfo"].GetString("login", loginURI); return loginURI; } + + public LSL_String osFormatString(string str, LSL_List strings) + { + CheckThreatLevel(ThreatLevel.Low, "osFormatString"); + m_host.AddScriptLPS(1); + + return String.Format(str, strings.Data); + } + + public LSL_List osMatchString(string src, string pattern, int start) + { + CheckThreatLevel(ThreatLevel.High, "osMatchString"); + m_host.AddScriptLPS(1); + + LSL_List result = new LSL_List(); + + // Normalize indices (if negative). + // After normlaization they may still be + // negative, but that is now relative to + // the start, rather than the end, of the + // sequence. + if (start < 0) + { + start = src.Length + start; + } + + if (start < 0 || start >= src.Length) + { + return result; // empty list + } + + // Find matches beginning at start position + Regex matcher = new Regex(pattern); + Match match = matcher.Match(src, start); + if (match.Success) + { + foreach (System.Text.RegularExpressions.Group g in match.Groups) + { + if (g.Success) + { + result.Add(g.Value); + result.Add(g.Index); + } + } + } + + return result; + } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index aab91df..72bb60c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -31,6 +31,8 @@ using OpenSim.Region.ScriptEngine.Interfaces; using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; +using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; +using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces { @@ -104,5 +106,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces string osGetGridNick(); string osGetGridName(); string osGetGridLoginURI(); + + LSL_String osFormatString(string str, LSL_List strings); + LSL_List osMatchString(string src, string pattern, int start); + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 50acc1e..a92f046 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -38,6 +38,8 @@ using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; +using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; +using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { @@ -262,6 +264,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osGetGridLoginURI(); } + public LSL_String osFormatString(string str, LSL_List strings) + { + return m_OSSL_Functions.osFormatString(str, strings); + } + + public LSL_List osMatchString(string src, string pattern, int start) + { + return m_OSSL_Functions.osMatchString(src, pattern, start); + } + public OSSLPrim Prim; [Serializable] -- cgit v1.1