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 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs') 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; + } } } -- cgit v1.1