add LSL_Integer osListFindListNext(LSL_List src, LSL_List test, LSL_Integer lstart, LSL_Integer lend, LSL_Integer instance), like ll one but with search restricted to a substring. Untested, sorry

This commit is contained in:
UbitUmarov
2025-04-04 01:30:41 +01:00
parent 9a02b55bf2
commit bde18322eb
5 changed files with 110 additions and 103 deletions

View File

@@ -6639,5 +6639,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
green = Math.Clamp(green, 0, 1.0f);
return new LSL_Vector(red, green, 1.0f);
}
public LSL_Integer osListFindListNext(LSL_List src, LSL_List test, LSL_Integer lstart, LSL_Integer lend, LSL_Integer instance)
{
if (src.Length == 0)
return -1;
if (test.Length == 0)
return 0;
if (test.Length > src.Length)
return -1;
int start = lstart.value;
if (start < 0)
{
start += src.Length;
if (start < 0)
return -1;
}
else if (start >= src.Length)
return -1;
int end = lend.value;
if (end < 0)
{
end += src.Length;
if (end < 0)
return -1;
end -= test.Length - 1;
}
else if (end > src.Length - test.Length)
end = src.Length - test.Length;
if(instance < 0)
instance = 0;
else if (instance > src.Length / test.Length)
return -1;
int nmatchs = 0;
object test0 = test[0];
for (int i = start; i <= end; i++)
{
if (LSL_List.ListFind_areEqual(test0, src[i]))
{
int k = i + 1;
int j = 1;
while(j < test.Length)
{
if (!LSL_List.ListFind_areEqual(test[j], src[k]))
break;
++j;
++k;
}
if (j == test.Length)
{
if(nmatchs == instance)
return i;
nmatchs++;
}
}
}
return -1;
}
}
}