Pchp.Library.Arrays.SpliceInternal C# (CSharp) Method

SpliceInternal() static private method

Implementation of array_splice(PhpArray,int,int,object) and array_splice(PhpArray,int,int,object).
Whether to make a deep-copy of items in the replacement.
static private SpliceInternal ( PhpArray array, int offset, int length, PhpValue replacement, bool deepCopy ) : PhpArray
array Pchp.Core.PhpArray
offset int
length int
replacement Pchp.Core.PhpValue
deepCopy bool
return Pchp.Core.PhpArray
        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;
        }