public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
{
if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID)) return new LSL_List();
// Note that although we have normalized, both
// indices could still be negative.
if (start < 0)
{
start = start + dest.Length;
}
if (end < 0)
{
end = end + dest.Length;
}
// The comventional case, remove a sequence starting with
// start and ending with end. And then insert the source
// list.
if (start <= end)
{
// If greater than zero, then there is going to be a
// surviving prefix. Otherwise the inclusive nature
// of the indices mean that we're going to add the
// source list as a prefix.
if (start > 0)
{
LSL_List pref = dest.GetSublist(0, start - 1);
// Only add a suffix if there is something
// beyond the end index (it's inclusive too).
if (end + 1 < dest.Length)
{
return pref + src + dest.GetSublist(end + 1, -1);
}
return pref + src;
}
// If start is less than or equal to zero, then
// the new list is simply a prefix. We still need to
// figure out any necessary surgery to the destination
// based upon end. Note that if end exceeds the upper
// bound in this case, the entire destination list
// is removed.
if (end + 1 < dest.Length)
{
return src + dest.GetSublist(end + 1, -1);
}
return src;
}
// Finally, if start > end, we strip away a prefix and
// a suffix, to leave the list that sits <between> ens
// and start, and then tag on the src list. AT least
// that's my interpretation. We can get sublist to do
// this for us. Note that one, or both of the indices
// might have been negative.
return dest.GetSublist(end + 1, start - 1) + src;
}