ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Diff Class Reference
+ Inheritance diagram for Diff:
+ Collaboration diagram for Diff:

Public Member Functions

 __construct ($from_lines, $to_lines)
 Constructor. More...
 
 reverse ()
 Compute reversed Diff. More...
 
 isEmpty ()
 Check for empty diff. More...
 
 lcs ()
 Compute the length of the Longest Common Subsequence (LCS). More...
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
 _check ($from_lines, $to_lines)
 Check a Diff for validity. More...
 

Data Fields

 $edits
 

Detailed Description

Definition at line 611 of file class.WordLevelDiff.php.

Constructor & Destructor Documentation

◆ __construct()

Diff::__construct (   $from_lines,
  $to_lines 
)

Constructor.

Computes diff between sequences of strings.

Parameters
$from_linesarray An array of strings. (Typically these are lines from a file.)
$to_linesarray An array of strings.

Reimplemented in WordLevelDiff.

Definition at line 623 of file class.WordLevelDiff.php.

624 {
625 $eng = new _DiffEngine();
626 $this->edits = $eng->diff($from_lines, $to_lines);
627 //$this->_check($from_lines, $to_lines);
628 }

Member Function Documentation

◆ _check()

Diff::_check (   $from_lines,
  $to_lines 
)

Check a Diff for validity.

This is here only for debugging purposes.

Definition at line 728 of file class.WordLevelDiff.php.

729 {
730 $fname = 'Diff::_check';
731 //wfProfileIn( $fname );
732 if (serialize($from_lines) != serialize($this->orig())) {
733 trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
734 }
735 if (serialize($to_lines) != serialize($this->closing())) {
736 trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
737 }
738
739 $rev = $this->reverse();
740 if (serialize($to_lines) != serialize($rev->orig())) {
741 trigger_error("Reversed original doesn't match", E_USER_ERROR);
742 }
743 if (serialize($from_lines) != serialize($rev->closing())) {
744 trigger_error("Reversed closing doesn't match", E_USER_ERROR);
745 }
746
747
748 $prevtype = 'none';
749 foreach ($this->edits as $edit) {
750 if ($prevtype == $edit->type) {
751 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
752 }
753 $prevtype = $edit->type;
754 }
755
756 $lcs = $this->lcs();
757 trigger_error('Diff okay: LCS = ' . $lcs, E_USER_NOTICE);
758 //wfProfileOut( $fname );
759 }
reverse()
Compute reversed Diff.
orig()
Get the original set of lines.
lcs()
Compute the length of the Longest Common Subsequence (LCS).
closing()
Get the closing set of lines.

References closing(), lcs(), orig(), and reverse().

+ Here is the call graph for this function:

◆ closing()

Diff::closing ( )

Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

Returns
array The sequence of strings.

Reimplemented in WordLevelDiff.

Definition at line 711 of file class.WordLevelDiff.php.

712 {
713 $lines = array();
714
715 foreach ($this->edits as $edit) {
716 if ($edit->closing) {
717 array_splice($lines, sizeof($lines), 0, $edit->closing);
718 }
719 }
720 return $lines;
721 }

Referenced by _check().

+ Here is the caller graph for this function:

◆ isEmpty()

Diff::isEmpty ( )

Check for empty diff.

Returns
bool True iff two sequences were identical.

Definition at line 655 of file class.WordLevelDiff.php.

656 {
657 foreach ($this->edits as $edit) {
658 if ($edit->type != 'copy') {
659 return false;
660 }
661 }
662 return true;
663 }

◆ lcs()

Diff::lcs ( )

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

This is mostly for diagnostic purposed.

Returns
int The length of the LCS.

Definition at line 672 of file class.WordLevelDiff.php.

673 {
674 $lcs = 0;
675 foreach ($this->edits as $edit) {
676 if ($edit->type == 'copy') {
677 $lcs += sizeof($edit->orig);
678 }
679 }
680 return $lcs;
681 }

Referenced by _check().

+ Here is the caller graph for this function:

◆ orig()

Diff::orig ( )

Get the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

Returns
array The original sequence of strings.

Reimplemented in WordLevelDiff.

Definition at line 691 of file class.WordLevelDiff.php.

692 {
693 $lines = array();
694
695 foreach ($this->edits as $edit) {
696 if ($edit->orig) {
697 array_splice($lines, sizeof($lines), 0, $edit->orig);
698 }
699 }
700 return $lines;
701 }

Referenced by _check().

+ Here is the caller graph for this function:

◆ reverse()

Diff::reverse ( )

Compute reversed Diff.

SYNOPSIS:

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

Returns
object A Diff object representing the inverse of the original diff.

Definition at line 640 of file class.WordLevelDiff.php.

641 {
642 $rev = $this;
643 $rev->edits = array();
644 foreach ($this->edits as $edit) {
645 $rev->edits[] = $edit->reverse();
646 }
647 return $rev;
648 }

Referenced by _check().

+ Here is the caller graph for this function:

Field Documentation

◆ $edits

Diff::$edits

Definition at line 613 of file class.WordLevelDiff.php.

Referenced by MappedDiff\__construct().


The documentation for this class was generated from the following file: