internal static PhpArray SpliceInternal(PhpArray array, int offset, int length, PhpValue replacement, bool deepCopy)
{
Debug.Assert(array != null);
int count = array.Count;
// converts offset and length to interval [first,last]:
PhpMath.AbsolutizeRange(ref offset, ref length, count);
PhpArray result = new PhpArray(length);
// replacement is an array:
if (replacement.IsArray)
{
// provides deep copies:
IEnumerable<PhpValue> e = replacement.Array.Values;
if (deepCopy)
{
e = e.Select(Operators.DeepCopy);
}
// does replacement:
array.ReindexAndReplace(offset, length, e, result);
}
else if (replacement.IsNull)
{
// replacement is null:
array.ReindexAndReplace(offset, length, null, result);
}
else
{
// replacement is another type //
// creates a deep copy:
if (deepCopy) replacement = replacement.DeepCopy();
// does replacement:
array.ReindexAndReplace(offset, length, new[] { replacement }, result);
}
return result;
}