Text_Diff
- Source
wp-includes/Text/Diff.php:18
General API for generating and formatting diffs - the differences between two sequences of strings.
Description
The original PHP version of this code was written by Geoffrey T. Dairiki [email protected], and is used/adapted with his permission.
Copyright 2004 Geoffrey T. Dairiki [email protected] 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).
Properties · 1
$_editsarraypublic- Array of changes.
Methods · 13
- __construct()Computes diffs between sequences of strings.
- Text_Diff()PHP4 constructor.
- getDiff()Returns the array of differences.
- countAddedLines()returns the number of new (added) lines in a given diff.
- countDeletedLines()Returns the number of deleted (removed) lines in a given diff.
- reverse()Computes a reversed diff.
- isEmpty()Checks for an empty diff.
- lcs()Computes the length of the Longest Common Subsequence (LCS).
- getOriginal()Gets the original set of lines.
- getFinal()Gets the final set of lines.
- trimNewlines()Removes trailing newlines from a line of text. This is meant to be used with array_walk().
- _getTempDir()Determines the location of the system temporary directory.
- _check()Checks a diff for validity.
Source code
class Text_Diff { /** * Array of changes. * * @var array */ var $_edits; /** * Computes diffs between sequences of strings. * * @param string $engine Name of the diffing engine to use. 'auto' * will automatically select the best. * @param array $params Parameters to pass to the diffing engine. * Normally an array of two arrays, each * containing the lines from a file. */ function __construct( $engine, $params ) { // Backward compatibility workaround. if (!is_string($engine)) { $params = array($engine, $params); $engine = 'auto'; } if ($engine == 'auto') { $engine = extension_loaded('xdiff') ? 'xdiff' : 'native'; } else { $engine = basename($engine); } // WP #7391 require_once dirname(__FILE__).'/Diff/Engine/' . $engine . '.php'; $class = 'Text_Diff_Engine_' . $engine; $diff_engine = new $class(); $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params); } /** * PHP4 constructor. */ public function Text_Diff( $engine, $params ) { self::__construct( $engine, $params ); } /** * Returns the array of differences. */ function getDiff() { return $this->_edits; } /** * returns the number of new (added) lines in a given diff. * * @since Text_Diff 1.1.0 * * @return int The number of new lines */ function countAddedLines() { $count = 0; foreach ($this->_edits as $edit) { if (is_a($edit, 'Text_Diff_Op_add') || is_a($edit, 'Text_Diff_Op_change')) { $count += $edit->nfinal(); } } return $count; } /** * Returns the number of deleted (removed) lines in a given diff. * * @since Text_Diff 1.1.0 * * @return int The number of deleted linesChangelog
Unchanged from 6.7.7 through 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.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.