ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 608 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 620 of file class.WordLevelDiff.php.

621 {
622 $eng = new _DiffEngine();
623 $this->edits = $eng->diff($from_lines, $to_lines);
624 //$this->_check($from_lines, $to_lines);
625 }

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 725 of file class.WordLevelDiff.php.

726 {
727 $fname = 'Diff::_check';
728 //wfProfileIn( $fname );
729 if (serialize($from_lines) != serialize($this->orig())) {
730 throw new \LogicException("Reconstructed original doesn't match");
731 }
732 if (serialize($to_lines) != serialize($this->closing())) {
733 throw new \LogicException("Reconstructed closing doesn't match");
734 }
735
736 $rev = $this->reverse();
737 if (serialize($to_lines) != serialize($rev->orig())) {
738 throw new \LogicException("Reversed original doesn't match");
739 }
740 if (serialize($from_lines) != serialize($rev->closing())) {
741 throw new \LogicException("Reversed closing doesn't match");
742 }
743
744
745 $prevtype = 'none';
746 foreach ($this->edits as $edit) {
747 if ($prevtype == $edit->type) {
748 throw new \RuntimeException("Edit sequence is non-optimal");
749 }
750 $prevtype = $edit->type;
751 }
752
753 $lcs = $this->lcs();
754 trigger_error('Diff okay: LCS = ' . $lcs, E_USER_NOTICE);
755 //wfProfileOut( $fname );
756 }
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 708 of file class.WordLevelDiff.php.

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

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 652 of file class.WordLevelDiff.php.

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

◆ 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 669 of file class.WordLevelDiff.php.

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

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 688 of file class.WordLevelDiff.php.

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

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 637 of file class.WordLevelDiff.php.

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

Referenced by _check().

+ Here is the caller graph for this function:

Field Documentation

◆ $edits

Diff::$edits

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

Referenced by MappedDiff\__construct().


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