ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Diff Class Reference
+ Inheritance diagram for Diff:
+ Collaboration diagram for Diff:

Public Member Functions

 Diff ($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 1202 of file class.WordLevelDiff.php.

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

1309 {
1310 $fname = 'Diff::_check';
1311 //wfProfileIn( $fname );
1312 if (serialize($from_lines) != serialize($this->orig()))
1313 trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
1314 if (serialize($to_lines) != serialize($this->closing()))
1315 trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
1316
1317 $rev = $this->reverse();
1318 if (serialize($to_lines) != serialize($rev->orig()))
1319 trigger_error("Reversed original doesn't match", E_USER_ERROR);
1320 if (serialize($from_lines) != serialize($rev->closing()))
1321 trigger_error("Reversed closing doesn't match", E_USER_ERROR);
1322
1323
1324 $prevtype = 'none';
1325 foreach ($this->edits as $edit) {
1326 if ( $prevtype == $edit->type )
1327 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
1328 $prevtype = $edit->type;
1329 }
1330
1331 $lcs = $this->lcs();
1332 trigger_error('Diff okay: LCS = '.$lcs, E_USER_NOTICE);
1333 //wfProfileOut( $fname );
1334 }
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 1294 of file class.WordLevelDiff.php.

1294 {
1295 $lines = array();
1296
1297 foreach ($this->edits as $edit) {
1298 if ($edit->closing)
1299 array_splice($lines, sizeof($lines), 0, $edit->closing);
1300 }
1301 return $lines;
1302 }

Referenced by _check().

+ Here is the caller graph for this function:

◆ Diff()

Diff::Diff (   $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.

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

1214 {
1215 $eng = new _DiffEngine;
1216 $this->edits = $eng->diff($from_lines, $to_lines);
1217 //$this->_check($from_lines, $to_lines);
1218 }
diff($from_lines, $to_lines)

References _DiffEngine\diff().

Referenced by MappedDiff\MappedDiff().

+ Here is the call graph for this function:
+ 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 1244 of file class.WordLevelDiff.php.

1244 {
1245 foreach ($this->edits as $edit) {
1246 if ($edit->type != 'copy')
1247 return false;
1248 }
1249 return true;
1250 }

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

1259 {
1260 $lcs = 0;
1261 foreach ($this->edits as $edit) {
1262 if ($edit->type == 'copy')
1263 $lcs += sizeof($edit->orig);
1264 }
1265 return $lcs;
1266 }

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

1276 {
1277 $lines = array();
1278
1279 foreach ($this->edits as $edit) {
1280 if ($edit->orig)
1281 array_splice($lines, sizeof($lines), 0, $edit->orig);
1282 }
1283 return $lines;
1284 }

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

1230 {
1231 $rev = $this;
1232 $rev->edits = array();
1233 foreach ($this->edits as $edit) {
1234 $rev->edits[] = $edit->reverse();
1235 }
1236 return $rev;
1237 }

Referenced by _check().

+ Here is the caller graph for this function:

Field Documentation

◆ $edits

Diff::$edits

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

Referenced by MappedDiff\MappedDiff().


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