mantis 9056: add llReplaceSubString()

This commit is contained in:
UbitUmarov
2023-01-31 17:16:33 +00:00
parent 9e60afbb68
commit 6a2d9e8ec3
3 changed files with 41 additions and 0 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}