Diff::generatePartialDiff PHP Method

generatePartialDiff() private static method

The parameters are: $table - the table returned by the computeTable function $sequence1 - the first sequence $sequence2 - the second sequence $start - the starting index
private static generatePartialDiff ( $table, $sequence1, $sequence2, $start, $ignoreIndent = true )
    private static function generatePartialDiff($table, $sequence1, $sequence2, $start, $ignoreIndent = true)
    {
        //  initialise the diff
        $diff = array();
        // initialise the indices
        $index1 = count($table) - 1;
        $index2 = count($table[0]) - 1;
        // loop until there are no items remaining in either sequence
        while ($index1 > 0 || $index2 > 0) {
            // check what has happened to the items at these indices
            if ($index1 > 0 && $index2 > 0 && static::compareLine($sequence1[$index1 + $start - 1], $sequence2[$index2 + $start - 1], $ignoreIndent)) {
                // update the diff and the indices
                $diff[] = array($sequence1[$index1 + $start - 1], self::UNMODIFIED);
                $index1--;
                $index2--;
            } elseif ($index2 > 0 && static::compareLine($table[$index1][$index2], $table[$index1][$index2 - 1], $ignoreIndent)) {
                // update the diff and the indices
                $diff[] = array($sequence2[$index2 + $start - 1], self::INSERTED);
                $index2--;
            } else {
                // update the diff and the indices
                $diff[] = array($sequence1[$index1 + $start - 1], self::DELETED);
                $index1--;
            }
        }
        // return the diff
        return $diff;
    }