Class Text_Diff

Description

General API for generating and formatting diffs - the differences between two sequences of strings.

The original PHP version of this code was written by Geoffrey T. Dairiki <dairiki@dairiki.org>, and is used/adapted with his permission.

$Horde: framework/Text_Diff/Diff.php,v 1.11.2.12 2009/01/06 15:23:41 jan Exp $

Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org> Copyright 2004-2009 The Horde Project (http://www.horde.org/)

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

Located in /Text_Diff/Diff.php (line 20)


	
			
Direct descendents
Class Description
 class Text_MappedDiff
 class Text_Diff3 A class for computing three way diffs.
 class Text_Diff_Mapped $Horde: framework/Text_Diff/Diff/Mapped.php,v 1.3.2.4 2009/01/06 15:23:41 jan Exp $
 class Text_Diff_ThreeWay A class for computing three way diffs.
Variable Summary
 array $_edits
Method Summary
 static string _getTempDir ()
 Text_Diff Text_Diff (string $engine, array $params)
 integer countAddedLines ()
 integer countDeletedLines ()
 void getDiff ()
 array getFinal ()
 array getOriginal ()
 boolean isEmpty ()
 integer lcs ()
 void trimNewlines ( &$line, integer $key, string $line)
 void _check ( $from_lines,  $to_lines)
Variables
array $_edits (line 27)

Array of changes.

Methods
static _getTempDir (line 226)

Determines the location of the system temporary directory.

  • return: A directory name which can be used for temp files. Returns false if one could not be found.
  • access: protected
static string _getTempDir ()
Constructor Text_Diff (line 38)

Computes diffs between sequences of strings.

Text_Diff Text_Diff (string $engine, array $params)
  • string $engine: Name of the diffing engine to use. 'auto' will automatically select the best.
  • array $params: Parameters to pass to the diffing engine. Normally an array of two arrays, each containing the lines from a file.
countAddedLines (line 75)

returns the number of new (added) lines in a given diff.

  • return: The number of new lines
  • since: Text_Diff 1.1.0
  • since: Horde 3.2
integer countAddedLines ()
countDeletedLines (line 95)

Returns the number of deleted (removed) lines in a given diff.

  • return: The number of deleted lines
  • since: Text_Diff 1.1.0
  • since: Horde 3.2
integer countDeletedLines ()
getDiff (line 62)

Returns the array of differences.

void getDiff ()
getFinal (line 193)

Gets the final set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

  • return: The sequence of strings.
array getFinal ()
getOriginal (line 175)

Gets the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

  • return: The original sequence of strings.
array getOriginal ()
isEmpty (line 140)

Checks for an empty diff.

  • return: True if two sequences were identical.
boolean isEmpty ()
lcs (line 157)

Computes the length of the Longest Common Subsequence (LCS).

This is mostly for diagnostic purposes.

  • return: The length of the LCS.
integer lcs ()
reverse (line 121)

Computes a reversed diff.

Example:

  1.  $diff new Text_Diff($lines1$lines2);
  2.  $rev $diff->reverse();

  • return: A Diff object representing the inverse of the original diff. Note that we purposely don't return a reference here, since this essentially is a clone() method.
Text_Diff reverse ()
trimNewlines (line 211)

Removes trailing newlines from a line of text. This is meant to be used with array_walk().

void trimNewlines ( &$line, integer $key, string $line)
  • string $line: The line to trim.
  • integer $key: The index of the line in the array. Not used.
  • &$line
_check (line 258)

Checks a diff for validity.

This is here only for debugging purposes.

void _check ( $from_lines,  $to_lines)
  • $from_lines
  • $to_lines

Documentation generated on Sun, 30 Jan 2011 05:16:47 +0000 by phpDocumentor 1.4.3