wppaste
WordPress

Text_Diff_Engine_xdiff

Source
wp-includes/Text/Diff/Engine/xdiff.php:16
Class used internally by Diff to actually compute the diffs.

Description

This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff) to compute the differences between the two input arrays.

Copyright 2004-2010 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see https://opensource.org/license/lgpl-2-1/.

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 1

Source code

class Text_Diff_Engine_xdiff {     /**     */    function diff($from_lines, $to_lines)    {        array_walk($from_lines, array('Text_Diff', 'trimNewlines'));        array_walk($to_lines, array('Text_Diff', 'trimNewlines'));         /* Convert the two input arrays into strings for xdiff processing. */        $from_string = implode("\n", $from_lines);        $to_string = implode("\n", $to_lines);         /* Diff the two strings and convert the result to an array. */        $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));        $diff = explode("\n", $diff);         /* Walk through the diff one line at a time.  We build the $edits         * array of diff operations by reading the first character of the         * xdiff output (which is in the "unified diff" format).         *         * Note that we don't have enough information to detect "changed"         * lines using this approach, so we can't add Text_Diff_Op_changed         * instances to the $edits array.  The result is still perfectly         * valid, albeit a little less descriptive and efficient. */        $edits = array();        foreach ($diff as $line) {            if (!strlen($line)) {                continue;            }            switch ($line[0]) {            case ' ':                $edits[] = new Text_Diff_Op_copy(array(substr($line, 1)));                break;             case '+':                $edits[] = new Text_Diff_Op_add(array(substr($line, 1)));                break;             case '-':                $edits[] = new Text_Diff_Op_delete(array(substr($line, 1)));                break;            }        }         return $edits;    } }

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/Text/Diff/Engine/xdiff.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.