add a few string functions to OSSL

0.9.1.0-post-fixes
UbitUmarov 2018-11-18 22:40:59 +00:00
parent 01b84ef46b
commit 9dfb906666
3 changed files with 237 additions and 1 deletions

View File

@ -5130,5 +5130,180 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
return account.UserCountry;
}
public LSL_String osStringSubString(LSL_String src, LSL_Integer offset)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return "";
if (offset >= src.Length)
return "";
if (offset <= 0)
return src;
return ((string)src).Substring(offset);
}
public LSL_String osStringSubString(LSL_String src, LSL_Integer offset, LSL_Integer length)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return "";
if (length <= 0 || offset >= src.Length)
return "";
if (offset <= 0)
{
if(length == src.Length)
return src;
offset = 0;
}
if (length > src.Length - offset)
length = src.Length - offset;
return ((string)src).Substring(offset, length);
}
public LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return 0;
if (string.IsNullOrEmpty(value))
return 0;
bool ign = (ignorecase != 0);
return ((string)src).StartsWith(value, ignorecase, Culture.GetDefaultCurrentCulture()) ? 1 : 0;
}
public LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return 0;
if (string.IsNullOrEmpty(value))
return 0;
bool ign = (ignorecase != 0);
return ((string)src).EndsWith(value, ign, Culture.GetDefaultCurrentCulture()) ? 1 : 0;
}
public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return -1;
if (string.IsNullOrEmpty(value))
return -1;
if (ignorecase == 0)
return ((string)src).IndexOf(value, StringComparison.CurrentCulture);
return ((string)src).IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
}
public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value,
LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return -1;
if (string.IsNullOrEmpty(value))
return -1;
if (offset >= src.Length)
return -1;
else if (offset < 0)
offset = 0;
if (count <= 0)
count = src.Length - offset;
else if (count > src.Length - offset)
count = src.Length - offset;
if (ignorecase == 0)
return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCulture);
return ((string)src).IndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase);
}
public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return -1;
if (string.IsNullOrEmpty(value))
return -1;
if (ignorecase == 0)
return ((string)src).LastIndexOf(value, StringComparison.CurrentCulture);
return ((string)src).LastIndexOf(value, StringComparison.CurrentCultureIgnoreCase);
}
public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value,
LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
{
m_host.AddScriptLPS(1);
CheckThreatLevel();
if (string.IsNullOrEmpty(src))
return -1;
if (string.IsNullOrEmpty(value))
return -1;
if (offset >= src.Length)
return -1;
if (offset < 0)
offset = 0;
if (count <= 0)
count = src.Length - offset;
else if (count > src.Length - offset)
count = src.Length - offset;
if (ignorecase == 0)
return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCulture);
return ((string)src).LastIndexOf(value, offset, count, StringComparison.CurrentCultureIgnoreCase);
}
public LSL_String osStringRemove(LSL_String src, LSL_Integer offset, LSL_Integer count)
{
if (string.IsNullOrEmpty(src))
return "";
if (offset >= src.Length)
return "";
if (offset < 0)
offset = 0;
if (count <= 0)
count = src.Length - offset;
else if (count > src.Length - offset)
count = src.Length - offset;
if (count >= src.Length)
return "";
return ((string)src).Remove(offset, count);
}
public LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue)
{
if (string.IsNullOrEmpty(src))
return "";
if (string.IsNullOrEmpty(oldvalue))
return "";
if (string.IsNullOrEmpty(newvalue))
newvalue = null;
return ((string)src).Replace(oldvalue, newvalue);
}
}
}
}

View File

@ -529,5 +529,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_String osDetectedCountry(LSL_Integer number);
LSL_String osGetAgentCountry(LSL_Key agentId);
LSL_String osStringSubString(LSL_String src, LSL_Integer start);
LSL_String osStringSubString(LSL_String src, LSL_Integer start, LSL_Integer length);
LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase);
LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase);
LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase);
LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer start, LSL_Integer count, LSL_Integer ignorecase);
LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase);
LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer start, LSL_Integer count, LSL_Integer ignorecase);
LSL_String osStringRemove(LSL_String src, LSL_Integer start, LSL_Integer count);
LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue);
}
}

View File

@ -1287,5 +1287,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osGetAgentCountry(agentId);
}
public LSL_String osStringSubString(LSL_String src, LSL_Integer offset)
{
return m_OSSL_Functions.osStringSubString(src, offset);
}
public LSL_String osStringSubString(LSL_String src, LSL_Integer offset, LSL_Integer length)
{
return m_OSSL_Functions.osStringSubString(src, offset, length);
}
public LSL_Integer osStringStartsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
return m_OSSL_Functions.osStringStartsWith(src, value, ignorecase);
}
public LSL_Integer osStringEndsWith(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
return m_OSSL_Functions.osStringEndsWith(src, value, ignorecase);
}
public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
return m_OSSL_Functions.osStringIndexOf(src, value, ignorecase);
}
public LSL_Integer osStringIndexOf(LSL_String src, LSL_String value, LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
{
return m_OSSL_Functions.osStringIndexOf(src, value, offset, count, ignorecase);
}
public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer ignorecase)
{
return m_OSSL_Functions.osStringLastIndexOf(src, value, ignorecase);
}
public LSL_Integer osStringLastIndexOf(LSL_String src, LSL_String value, LSL_Integer offset, LSL_Integer count, LSL_Integer ignorecase)
{
return m_OSSL_Functions.osStringLastIndexOf(src, value, offset, count, ignorecase);
}
public LSL_String osStringRemove(LSL_String src, LSL_Integer offset, LSL_Integer count)
{
return m_OSSL_Functions.osStringRemove(src, offset, count);
}
public LSL_String osStringReplace(LSL_String src, LSL_String oldvalue, LSL_String newvalue)
{
return m_OSSL_Functions.osStringReplace(src, oldvalue, newvalue);
}
}
}