mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 08:55:56 +08:00
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.
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user