Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llGetSubString and llDeleteSubString borked

Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-04-2005 16:15
CODE

ss(string a)
{
llSay(0,llList2CSV([a, llStringLength(a)]));
}
test(string a, integer b, integer c)
{
ss(llGetSubString(a,b,c) + "-" + llDeleteSubString(a,b,c));
}

default
{
state_entry()
{
string b = "0123456789abcdef";
test(b,5,10);
test(b,10,5);
test(b,-5,-10);
test(b,-10,-5);
test(b,-5,10);
test(b,10,-5);
test(b,5,-10);
test(b,-10,5);
test(b,-10,-10);
test(b,10,10);
}
}


CODE

SL 1.5.14
Object: 56789a-01234bcdef, 17
Object: 012345abcdef-6789, 17
Object: 0123456bcdef-0123456789abcdef, 29
Object: 6789ab-, 7
Object: 0123456789abcdef-bcdef, 22
Object: ab-0123456789, 13
Object: 56-01234, 8
Object: 0123456789abcdef-6789abcdef, 27
Object: 6-0123456789abcdef, 18
Object: a-0123456789bcdef, 17


CODE

Preview 1.6 build 5
Object: 56789a-01234bcdef, 17
Object: 0123459abcdef-678, 17
Object: bcdef-789, 9
Object: 6789abcdef-012345cdef, 21
Object: -, 1
Object: abcdef-0123456789cdef, 21
Object: 56789abcdef-01234789abcdef, 26
Object: -, 1
Object: 6789abcdef-012345789abcdef, 26
Object: a-0123456789bcdef, 17
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Kelly Linden
Linden Developer
Join date: 29 Mar 2004
Posts: 896
03-04-2005 18:25
Thanks Strife, I will be looking into this on Monday.
_____________________
- Kelly Linden
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-04-2005 20:18
looking at both of them it looks like llDeleteSubString is borked in 1.5.14 too.

i think it should be

CODE

Object: 56789a-01234bcdef, 17
Object: 012345abcdef-6789, 17
Object: 0123456bcdef-789a, 17
Object: 6789ab-012345cdef, 17
Object: 0123456789abcdef-, 17
Object: ab-0123456789cdef, 17
Object: 56-01234789abcdef, 17
Object: 0123456789abcdef-, 17
Object: 6-012345789abcdef, 17
Object: a-0123456789bcdef, 17
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-04-2005 22:22
CODE

//released into the public domain
string GetSubString(string src, integer begin, integer end)
{
string temp;
integer len = llStringLength(src);
integer count;
if(begin < 0)
{
if(-begin > len)
begin = 0;
else
begin += len;
}
else if (begin >= len)
begin = len - 1;
if(end< 0)
{
if(-end > len)
end = 0;
else
end += len;
}
else if (end >= len)
end = len - 1;
for(count = 0; count < len; count++)
if(((count >= begin) == (count <= end)) == (begin <= end))
temp += llGetSubString(src, count, count);
return temp;
}

string DeleteSubString(string src, integer begin, integer end)
{
string temp;
integer len = llStringLength(src);
integer count;
if(begin < 0)
{
if(-begin > len)
begin = 0;
else
begin += len;
}
else if (begin >= len)
begin = len - 1;
if(end< 0)
{
if(-end > len)
end = 0;
else
end += len;
}
else if (end >= len)
end = len - 1;
for(count = 0; count < len; count++)
if(((count < begin) != (count > end)) == (begin <= end))
temp += llGetSubString(src, count, count);
return temp;
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-07-2005 06:07
CODE

//released into the public domain

string DeleteSubString(string src, integer begin, integer end)
{
return cut(src, begin, end, 0);
}

string GetSubString(string src, integer begin, integer end)
{
return cut(src, begin, end, 1);
}

string cut(string src, integer begin, integer end, integer type)
{
string temp;
integer len = llStringLength(src);
if(begin < 0)
{
if(-begin > len)
begin = 0;
else
begin += len;
}
else if (begin >= len)
begin = len - 1;
if(end< 0)
{
if(-end > len)
end = 0;
else
end += len;
}
else if (end >= len)
end = len - 1;
integer test = ((begin <= end) == (type != 0)); //TRUE if include, FALSE if we exclude
integer count = 0; //could be optimized so it wouldn't have to read the entire string
for(; count < len; count++)
if(((count >= begin) == (count <= end)) == test)
temp += llGetSubString(src, count, count);
return temp;
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-08-2005 09:17
these are the "fast" versions of the functions.

CODE

//public domain
string GetSubString(string src, integer begin, integer end)
{
string temp;
integer len = llStringLength(src);
integer count;
if(begin < 0)
{
if(-begin > len)
begin = 0;
else
begin += len;
}
else if (begin >= len)
begin = len - 1;
if(end< 0)
{
if(-end > len)
end = 0;
else
end += len;
}
else if (end >= len)
end = len - 1;
if(begin <= end)
return llGetSubString(src, begin, end);
else
return llGetSubString(src, 0, end) + llGetSubString(src, begin, len - 1);
}

string DeleteSubString(string src, integer begin, integer end)
{
string temp;
integer len = llStringLength(src);
integer count;
if(begin < 0)
{
if(-begin > len)
begin = 0;
else
begin += len;
}
else if (begin >= len)
begin = len - 1;
if(end< 0)
{
if(-end > len)
end = 0;
else
end += len;
}
else if (end >= len)
end = len - 1;
if(begin <= end)
return llDeleteSubString(src, begin, end);
else
return llDeleteSubString(llDeleteSubString(src, begin, len - 1), 0, end);
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey