[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/ -> DifferenceEngine.php (summary)

(no description)

File Size: 1568 lines (47 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 20 classes

_DiffOp:: (3 methods):
  reverse()
  norig()
  nclosing()

_DiffOp_Copy:: (2 methods):
  __construct()
  reverse()

_DiffOp_Delete:: (2 methods):
  __construct()
  reverse()

_DiffOp_Add:: (2 methods):
  __construct()
  reverse()

_DiffOp_Change:: (2 methods):
  __construct()
  reverse()

_DiffEngine:: (5 methods):
  diff()
  _diag()
  _lcs_pos()
  _compareseq()
  _shift_boundaries()

Diff:: (7 methods):
  __construct()
  reverse()
  isEmpty()
  lcs()
  orig()
  closing()
  _check()

MappedDiff:: (1 method):
  __construct()

DiffFormatter:: (13 methods):
  format()
  _block()
  _start_diff()
  _end_diff()
  _block_header()
  _start_block()
  _end_block()
  _lines()
  _context()
  _added()
  _deleted()
  _changed()
  _escape()

HTMLDiff:: (1 method):
  css()

_HWLDF_WordAccumulator:: (6 methods):
  __construct()
  _flushGroup()
  _flushLine()
  addWords()
  getLines()
  _escape()

WordLevelDiff:: (4 methods):
  __construct()
  _split()
  orig()
  closing()

InlineWordLevelDiff:: (3 methods):
  __construct()
  _split()
  inline()

UnifiedDiffFormatter:: (5 methods):
  __construct()
  _block_header()
  _added()
  _deleted()
  _changed()

TableDiffFormatter:: (17 methods):
  __construct()
  format()
  _pre()
  _block_header()
  _start_block()
  _end_block()
  _lines()
  addedLine()
  deletedLine()
  emptyLine()
  contextLine()
  _added()
  _addedLines()
  _deleted()
  _context()
  _changed()
  _escape()

InlineDiffFormatter:: (12 methods):
  __construct()
  format()
  _pre()
  _block_header()
  _start_block()
  _end_block()
  _lines()
  _added()
  _deleted()
  _context()
  _changed()
  _escape()

Diff3:: (3 methods):
  __construct()
  mergedOutput()
  _diff3()

_Diff3_Op:: (3 methods):
  __construct()
  merged()
  isConflict()

_Diff3_Op_copy:: (3 methods):
  __construct()
  merged()
  isConflict()

_Diff3_BlockBuilder:: (8 methods):
  __construct()
  input()
  out1()
  out2()
  isEmpty()
  finish()
  _init()
  _append()


Class: _DiffOp  - X-Ref

A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)

Additions by Axel Boldt for MediaWiki

reverse()   X-Ref

return: _DiffOp

norig()   X-Ref
No description

nclosing()   X-Ref
No description

Class: _DiffOp_Copy  - X-Ref

__construct($orig, $closing = false)   X-Ref
No description

reverse()   X-Ref
No description

Class: _DiffOp_Delete  - X-Ref

__construct($lines)   X-Ref
No description

reverse()   X-Ref
No description

Class: _DiffOp_Add  - X-Ref

__construct($lines)   X-Ref
No description

reverse()   X-Ref
No description

Class: _DiffOp_Change  - X-Ref

__construct($orig, $closing)   X-Ref
No description

reverse()   X-Ref
No description

Class: _DiffEngine  - X-Ref

Class used internally by Diff to actually compute the diffs.

The algorithm used here is mostly lifted from the perl module
Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip

More ideas are taken from:
http://www.ics.uci.edu/~eppstein/161/960229.html

Some ideas are (and a bit of code) are from from analyze.c, from GNU
diffutils-2.7, which can be found at:
ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz

closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
are my own.

diff($from_lines, $to_lines)   X-Ref

return: _DiffOp[]
param: array $from_lines
param: array $to_lines

_diag($xoff, $xlim, $yoff, $ylim, $nchunks)   X-Ref
Divide the Largest Common Subsequence (LCS) of the sequences
[XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
sized segments.

Returns (LCS, PTS).  LCS is the length of the LCS. PTS is an
array of NCHUNKS+1 (X, Y) indexes giving the diving points between
sub sequences.  The first sub-sequence is contained in [X0, X1),
[Y0, Y1), the second in [X1, X2), [Y1, Y2) and so on.  Note
that (X0, Y0) == (XOFF, YOFF) and
(X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).

This function assumes that the first lines of the specified portions
of the two files do not match, and likewise that the last lines do not
match.  The caller must trim matching lines from the beginning and end
of the portions it is going to specify.

return: array
param: integer $xoff
param: integer $xlim
param: integer $yoff
param: integer $ylim
param: integer $nchunks

_lcs_pos($ypos)   X-Ref
No description

_compareseq($xoff, $xlim, $yoff, $ylim)   X-Ref
Find LCS of two sequences.

The results are recorded in the vectors $this->{x,y}changed[], by
storing a 1 in the element for each line that is an insertion
or deletion (ie. is not in the LCS).

The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.

Note that XLIM, YLIM are exclusive bounds.
All line numbers are origin-0 and discarded lines are not counted.

param: integer $xoff
param: integer $xlim
param: integer $yoff
param: integer $ylim

_shift_boundaries($lines, &$changed, $other_changed)   X-Ref
Adjust inserts/deletes of identical lines to join changes
as much as possible.

We do something when a run of changed lines include a
line at one end and has an excluded, identical line at the other.
We are free to choose which identical line is included.
`compareseq' usually chooses the one at the beginning,
but usually it is cleaner to consider the following identical line
to be the "change".

This is extracted verbatim from analyze.c (GNU diffutils-2.7).

param: array $lines
param: array $changed
param: array $other_changed

Class: Diff  - X-Ref

Class representing a 'diff' between two sequences of strings.

__construct($from_lines, $to_lines)   X-Ref
Constructor.
Computes diff between sequences of strings.

param: array $from_lines An array of strings.
param: array $to_lines   An array of strings.

reverse()   X-Ref
Compute reversed Diff.

SYNOPSIS:

$diff = new Diff($lines1, $lines2);
$rev = $diff->reverse();

return: Diff  A Diff object representing the inverse of the

isEmpty()   X-Ref
Check for empty diff.

return: bool True iff two sequences were identical.

lcs()   X-Ref
Compute the length of the Longest Common Subsequence (LCS).

This is mostly for diagnostic purposed.

return: int The length of the LCS.

orig()   X-Ref
Get the original set of lines.

This reconstructs the $from_lines parameter passed to the
constructor.

return: array The original sequence of strings.

closing()   X-Ref
Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the
constructor.

return: array The sequence of strings.

_check($from_lines, $to_lines)   X-Ref
Check a Diff for validity.

This is here only for debugging purposes.

param: mixed $from_lines
param: mixed $to_lines

Class: MappedDiff  - X-Ref

FIXME: bad name.

__construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)   X-Ref
Constructor.

Computes diff between sequences of strings.

This can be used to compute things like
case-insensitve diffs, or diffs which ignore
changes in white-space.

param: string[] $from_lines         An array of strings.
param: string[] $to_lines           An array of strings.
param: string[] $mapped_from_lines  This array should
param: string[] $mapped_to_lines    This array should

Class: DiffFormatter  - X-Ref

A class to format Diffs

This class formats the diff in classic diff format.
It is intended that this class be customized via inheritance,
to obtain fancier outputs.
format($diff)   X-Ref
Format a diff.

return: string The formatted output.
param: Diff $diff A Diff object.

_block($xbeg, $xlen, $ybeg, $ylen, &$edits)   X-Ref

param: int $xbeg
param: int $xlen
param: int $ybeg
param: int $ylen
param: array $edits

_start_diff()   X-Ref
No description

_end_diff()   X-Ref
No description

_block_header($xbeg, $xlen, $ybeg, $ylen)   X-Ref

return: string
param: int $xbeg
param: int $xlen
param: int $ybeg
param: int $ylen

_start_block($header)   X-Ref

param: string $header

_end_block()   X-Ref
No description

_lines($lines, $prefix = ' ')   X-Ref
No description

_context($lines)   X-Ref
No description

_added($lines)   X-Ref
No description

_deleted($lines)   X-Ref
No description

_changed($orig, $closing)   X-Ref
No description

_escape($str)   X-Ref
Escape string

Override this method within other formatters if escaping required.
Base class requires $str to be returned WITHOUT escaping.

return: string The escaped string.
param: $str string Text string to escape

Class: HTMLDiff  - X-Ref

Utilityclass for styling HTML formatted diffs

Depends on global var $DIFF_INLINESTYLES, if true some minimal predefined
inline styles are used. Useful for HTML mails and RSS feeds

css($classname)   X-Ref
Return a class or style parameter

return: string
param: string $classname

Class: _HWLDF_WordAccumulator  - X-Ref

__construct()   X-Ref
No description

_flushGroup($new_tag)   X-Ref
No description

_flushLine($new_tag)   X-Ref

param: string $new_tag

addWords($words, $tag = '')   X-Ref
No description

getLines()   X-Ref
No description

_escape($str)   X-Ref
No description

Class: WordLevelDiff  - X-Ref

__construct($orig_lines, $closing_lines)   X-Ref
No description

_split($lines)   X-Ref
No description

orig()   X-Ref
No description

closing()   X-Ref
No description

Class: InlineWordLevelDiff  - X-Ref

__construct($orig_lines, $closing_lines)   X-Ref
No description

_split($lines)   X-Ref
No description

inline()   X-Ref
No description

Class: UnifiedDiffFormatter  - X-Ref

"Unified" diff formatter.

This class formats the diff in classic "unified diff" format.

NOTE: output is plain text and unsafe for use in HTML without escaping.
__construct($context_lines = 4)   X-Ref
No description

_block_header($xbeg, $xlen, $ybeg, $ylen)   X-Ref
No description

_added($lines)   X-Ref
No description

_deleted($lines)   X-Ref
No description

_changed($orig, $final)   X-Ref
No description

Class: TableDiffFormatter  - X-Ref

Wikipedia Table style diff formatter.

__construct()   X-Ref
No description

format($diff)   X-Ref

return: string
param: Diff $diff

_pre($text)   X-Ref
No description

_block_header($xbeg, $xlen, $ybeg, $ylen)   X-Ref
No description

_start_block($header)   X-Ref
No description

_end_block()   X-Ref
No description

_lines($lines, $prefix=' ', $color="white")   X-Ref
No description

addedLine($line,$escaped=false)   X-Ref
No description

deletedLine($line,$escaped=false)   X-Ref
No description

emptyLine()   X-Ref
No description

contextLine($line)   X-Ref
No description

_added($lines)   X-Ref
No description

_addedLines($lines,$escaped=false)   X-Ref
No description

_deleted($lines)   X-Ref
No description

_context($lines)   X-Ref
No description

_changed($orig, $closing)   X-Ref
No description

_escape($str)   X-Ref
No description

Class: InlineDiffFormatter  - X-Ref

Inline style diff formatter.

__construct()   X-Ref
No description

format($diff)   X-Ref

return: string
param: Diff $diff

_pre($text)   X-Ref
No description

_block_header($xbeg, $xlen, $ybeg, $ylen)   X-Ref
No description

_start_block($header)   X-Ref
No description

_end_block()   X-Ref
No description

_lines($lines, $prefix=' ', $color="white")   X-Ref
No description

_added($lines)   X-Ref
No description

_deleted($lines)   X-Ref
No description

_context($lines)   X-Ref
No description

_changed($orig, $closing)   X-Ref
No description

_escape($str)   X-Ref
No description

Class: Diff3  - X-Ref

A class for computing three way diffs.

__construct($orig, $final1, $final2)   X-Ref
Computes diff between 3 sequences of strings.

param: array $orig    The original lines to use.
param: array $final1  The first version to compare to.
param: array $final2  The second version to compare to.

mergedOutput($label1='<<<<<<<',$label2='>>>>>>>',$label3='=======')   X-Ref
Returns the merged lines

return: array          lines of the merged text
param: string $label1  label for first version
param: string $label2  label for second version
param: string $label3  separator between versions

_diff3($edits1, $edits2)   X-Ref

return: array
param: array $edits1
param: array $edits2

Class: _Diff3_Op  - X-Ref


__construct($orig = false, $final1 = false, $final2 = false)   X-Ref
No description

merged()   X-Ref
No description

isConflict()   X-Ref
No description

Class: _Diff3_Op_copy  - X-Ref


__construct($lines = false)   X-Ref
No description

merged()   X-Ref
No description

isConflict()   X-Ref
No description

Class: _Diff3_BlockBuilder  - X-Ref


__construct()   X-Ref
No description

input($lines)   X-Ref
No description

out1($lines)   X-Ref
No description

out2($lines)   X-Ref
No description

isEmpty()   X-Ref
No description

finish()   X-Ref
No description

_init()   X-Ref
No description

_append(&$array, $lines)   X-Ref
No description