rewrote hanging llParseStringKeepNulls()
parent
6c6c7b0927
commit
90c5555d6d
|
@ -8627,130 +8627,105 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
|
|
||||||
public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
|
public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
|
||||||
{
|
{
|
||||||
int beginning = 0;
|
|
||||||
int srclen = src.Length;
|
int srclen = src.Length;
|
||||||
int seplen = separators.Length;
|
int seplen = separators.Length;
|
||||||
object[] separray = separators.Data;
|
object[] separray = separators.Data;
|
||||||
int spclen = spacers.Length;
|
int spclen = spacers.Length;
|
||||||
object[] spcarray = spacers.Data;
|
object[] spcarray = spacers.Data;
|
||||||
int mlen = seplen+spclen;
|
|
||||||
|
|
||||||
int[] offset = new int[mlen+1];
|
int outlen = 0;
|
||||||
bool[] active = new bool[mlen];
|
LSL_String[] outarray = new LSL_String[srclen*2+1];
|
||||||
|
|
||||||
int best;
|
int i, j, lastUsed;
|
||||||
int j;
|
|
||||||
|
|
||||||
// Initial capacity reduces resize cost
|
|
||||||
|
|
||||||
LSL_List tokens = new LSL_List();
|
|
||||||
|
|
||||||
m_host.AddScriptLPS(1);
|
m_host.AddScriptLPS(1);
|
||||||
|
|
||||||
// All entries are initially valid
|
/*
|
||||||
|
* Point to beginning of current non-delimeter string.
|
||||||
|
*/
|
||||||
|
lastUsed = 0;
|
||||||
|
|
||||||
for (int i = 0; i < mlen; i++)
|
/*
|
||||||
active[i] = true;
|
* Scan through source string from beginning to end.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < srclen;) {
|
||||||
|
|
||||||
offset[mlen] = srclen;
|
/*
|
||||||
|
* See if rest of string (starting at i) matches any separator.
|
||||||
|
*/
|
||||||
|
string rest = src.Substring(i);
|
||||||
|
for (j = 0; j < seplen; j ++) {
|
||||||
|
string sep = separray[j].ToString();
|
||||||
|
if ((sep.Length > 0) && rest.StartsWith(sep)) {
|
||||||
|
|
||||||
while (beginning < srclen)
|
/*
|
||||||
{
|
* Separator matched, output string from end of last delimeter to beginning of this one.
|
||||||
|
*/
|
||||||
|
outarray[outlen++] = new LSL_String(src.Substring(lastUsed,i-lastUsed));
|
||||||
|
|
||||||
best = mlen; // as bad as it gets
|
/*
|
||||||
|
* Remove separator from input string.
|
||||||
|
*/
|
||||||
|
i += sep.Length;
|
||||||
|
|
||||||
// Scan for separators
|
/*
|
||||||
|
* Next non-delimeter starts where this separator left off.
|
||||||
for (j = 0; j < seplen; j++)
|
*/
|
||||||
{
|
lastUsed = i;
|
||||||
if (active[j])
|
goto nextsrc;
|
||||||
{
|
|
||||||
// scan all of the markers
|
|
||||||
if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
|
|
||||||
{
|
|
||||||
// not present at all
|
|
||||||
active[j] = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// present and correct
|
|
||||||
if (offset[j] < offset[best])
|
|
||||||
{
|
|
||||||
// closest so far
|
|
||||||
best = j;
|
|
||||||
if (offset[best] == beginning)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan for spacers
|
/*
|
||||||
|
* See if rest of string (starting at i) matches any spacer.
|
||||||
|
*/
|
||||||
|
for (j = 0; j < spclen; j ++) {
|
||||||
|
string spc = spcarray[j].ToString();
|
||||||
|
if ((spc.Length > 0) && rest.StartsWith(spc)) {
|
||||||
|
|
||||||
if (offset[best] != beginning)
|
/*
|
||||||
{
|
* Spacer matched, output string from end of last delimeter to beginning of this one.
|
||||||
for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
|
* Then output the spacer itself.
|
||||||
{
|
*/
|
||||||
if (active[j])
|
outarray[outlen++] = new LSL_String(src.Substring(lastUsed,i-lastUsed));
|
||||||
{
|
outarray[outlen++] = new LSL_String(spc);
|
||||||
// scan all of the markers
|
|
||||||
if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
|
/*
|
||||||
{
|
* Remove spacer from input string.
|
||||||
// not present at all
|
*/
|
||||||
active[j] = false;
|
i += spc.Length;
|
||||||
}
|
|
||||||
else
|
/*
|
||||||
{
|
* Next non-delimeter starts where this spacer left off.
|
||||||
// present and correct
|
*/
|
||||||
if (offset[j] < offset[best])
|
lastUsed = i;
|
||||||
{
|
goto nextsrc;
|
||||||
// closest so far
|
|
||||||
best = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the normal exit from the scanning loop
|
/*
|
||||||
|
* Didn't match any separator or spacer, skip over it and it
|
||||||
if (best == mlen)
|
* becomes part of the non-delimeter string starting with
|
||||||
{
|
* lastUsed.
|
||||||
// no markers were found on this pass
|
*/
|
||||||
// so we're pretty much done
|
i ++;
|
||||||
tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
|
nextsrc:;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise we just add the newly delimited token
|
/*
|
||||||
// and recalculate where the search should continue.
|
* Output last non-delimeter (including a possible null string if
|
||||||
|
* delimeter ran to end of source string).
|
||||||
|
*/
|
||||||
|
outarray[outlen++] = new LSL_String(src.Substring(lastUsed));
|
||||||
|
|
||||||
tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning)));
|
/*
|
||||||
|
* Make up an exact-sized output array suitable for an LSL_List object.
|
||||||
if (best < seplen)
|
*/
|
||||||
{
|
object[] outlist = new object[outlen];
|
||||||
beginning = offset[best] + (separray[best].ToString()).Length;
|
for (i = 0; i < outlen; i ++) {
|
||||||
|
outlist[i] = outarray[i];
|
||||||
}
|
}
|
||||||
else
|
return new LSL_List(outlist);
|
||||||
{
|
|
||||||
beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
|
|
||||||
tokens.Add(new LSL_String(spcarray[best - seplen].ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This an awkward an not very intuitive boundary case. If the
|
|
||||||
// last substring is a tokenizer, then there is an implied trailing
|
|
||||||
// null list entry. Hopefully the single comparison will not be too
|
|
||||||
// arduous. Alternatively the 'break' could be replced with a return
|
|
||||||
// but that's shabby programming.
|
|
||||||
|
|
||||||
if (beginning == srclen)
|
|
||||||
{
|
|
||||||
if (srclen != 0)
|
|
||||||
tokens.Add(new LSL_String(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
return tokens;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_Integer llGetObjectPermMask(int mask)
|
public LSL_Integer llGetObjectPermMask(int mask)
|
||||||
|
|
Loading…
Reference in New Issue