From 8a375f3c30302c4a7ace1afb05a8b49fbb415640 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Thu, 1 Mar 2012 14:49:49 -0800 Subject: Adds an OSSL command for regular expression-based string replacement. Parameters are osReplaceString(string source, string patter, string replace, integer count, integer start) The count parameter specifies the total number of replacements to make, -1 makes all replacements. --- .../Shared/Api/Implementation/OSSL_Api.cs | 25 ++++++++++++++++++++++ 1 file changed, 25 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 ff1f5fd..8edd146 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2160,6 +2160,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return result; } + public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start) + { + CheckThreatLevel(ThreatLevel.High, "osReplaceString"); + m_host.AddScriptLPS(1); + + // 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 src; + } + + // Find matches beginning at start position + Regex matcher = new Regex(pattern); + return matcher.Replace(src,replace,count,start); + } + public string osLoadedCreationDate() { CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate"); -- cgit v1.1