mirror of
https://github.com/opensim/opensim.git
synced 2026-05-15 03:15:41 +08:00
mantis 9056: add llReplaceSubString()
This commit is contained in:
@@ -18668,6 +18668,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public LSL_String llReplaceSubString(LSL_String src, LSL_String pattern, LSL_String replacement, int count)
|
||||
{
|
||||
RegexOptions RegexOptions;
|
||||
if (count < 0)
|
||||
{
|
||||
RegexOptions = RegexOptions.CultureInvariant | RegexOptions.RightToLeft;
|
||||
count = -count;
|
||||
}
|
||||
else
|
||||
{
|
||||
RegexOptions = RegexOptions.CultureInvariant;
|
||||
if (count == 0)
|
||||
count = -1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(src.m_string))
|
||||
return src;
|
||||
|
||||
if (string.IsNullOrEmpty(pattern.m_string))
|
||||
return src;
|
||||
|
||||
Regex rx = new Regex(pattern, RegexOptions, new TimeSpan(500000)); // 50ms)
|
||||
if (replacement == null)
|
||||
return rx.Replace(src.m_string, string.Empty, count);
|
||||
|
||||
return rx.Replace(src.m_string, replacement.m_string, count);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return src;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class NotecardCache
|
||||
|
||||
@@ -486,5 +486,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
LSL_String llChar(LSL_Integer unicode);
|
||||
LSL_Integer llOrd(LSL_String s, LSL_Integer index);
|
||||
LSL_Integer llHash(LSL_String s);
|
||||
LSL_String llReplaceSubString(LSL_String src, LSL_String pattern, LSL_String replacement, int count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2209,5 +2209,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
{
|
||||
return m_LSL_Functions.llHash(s);
|
||||
}
|
||||
|
||||
public LSL_String llReplaceSubString(LSL_String src, LSL_String pattern, LSL_String replacement, int count)
|
||||
{
|
||||
return m_LSL_Functions.llReplaceSubString(src, pattern, replacement, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user