mantis 9056: add llReplaceSubString()

This commit is contained in:
UbitUmarov
2023-01-31 16:58:09 +00:00
parent 61cde32562
commit 9edba5582e
3 changed files with 43 additions and 0 deletions

View File

@@ -18700,6 +18700,42 @@ 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,7 @@ 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

@@ -2212,5 +2212,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);
}
}
}