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.xassetservice
parent
7a88d21e59
commit
8a375f3c30
|
@ -2160,6 +2160,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
return result;
|
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()
|
public string osLoadedCreationDate()
|
||||||
{
|
{
|
||||||
CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
|
CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
|
||||||
|
|
|
@ -165,6 +165,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||||
|
|
||||||
LSL_String osFormatString(string str, LSL_List strings);
|
LSL_String osFormatString(string str, LSL_List strings);
|
||||||
LSL_List osMatchString(string src, string pattern, int start);
|
LSL_List osMatchString(string src, string pattern, int start);
|
||||||
|
LSL_String osReplaceString(string src, string pattern, string replace, int count, int start);
|
||||||
|
|
||||||
// Information about data loaded into the region
|
// Information about data loaded into the region
|
||||||
string osLoadedCreationDate();
|
string osLoadedCreationDate();
|
||||||
|
|
|
@ -472,6 +472,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||||
return m_OSSL_Functions.osMatchString(src, pattern, start);
|
return m_OSSL_Functions.osMatchString(src, pattern, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
|
||||||
|
{
|
||||||
|
return m_OSSL_Functions.osReplaceString(src,pattern,replace,count,start);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Information about data loaded into the region
|
// Information about data loaded into the region
|
||||||
public string osLoadedCreationDate()
|
public string osLoadedCreationDate()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue