ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 1300 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 1312 of file class.WordLevelDiff.php.

1313 {
1314 $eng = new _DiffEngine;
1315 $this->edits = $eng->diff($from_lines, $to_lines);
1316 //$this->_check($from_lines, $to_lines);
1317 }
diff($from_lines, $to_lines)

References _DiffEngine\diff().

+ Here is the call graph for this function:

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

1418 {
1419 $fname = 'Diff::_check';
1420 //wfProfileIn( $fname );
1421 if (serialize($from_lines) != serialize($this->orig())) {
1422 trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
1423 }
1424 if (serialize($to_lines) != serialize($this->closing())) {
1425 trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
1426 }
1427
1428 $rev = $this->reverse();
1429 if (serialize($to_lines) != serialize($rev->orig())) {
1430 trigger_error("Reversed original doesn't match", E_USER_ERROR);
1431 }
1432 if (serialize($from_lines) != serialize($rev->closing())) {
1433 trigger_error("Reversed closing doesn't match", E_USER_ERROR);
1434 }
1435
1436
1437 $prevtype = 'none';
1438 foreach ($this->edits as $edit) {
1439 if ($prevtype == $edit->type) {
1440 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
1441 }
1442 $prevtype = $edit->type;
1443 }
1444
1445 $lcs = $this->lcs();
1446 trigger_error('Diff okay: LCS = ' . $lcs, E_USER_NOTICE);
1447 //wfProfileOut( $fname );
1448 }
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 1400 of file class.WordLevelDiff.php.

1401 {
1402 $lines = array();
1403
1404 foreach ($this->edits as $edit) {
1405 if ($edit->closing) {
1406 array_splice($lines, sizeof($lines), 0, $edit->closing);
1407 }
1408 }
1409 return $lines;
1410 }

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

1345 {
1346 foreach ($this->edits as $edit) {
1347 if ($edit->type != 'copy') {
1348 return false;
1349 }
1350 }
1351 return true;
1352 }

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

1362 {
1363 $lcs = 0;
1364 foreach ($this->edits as $edit) {
1365 if ($edit->type == 'copy') {
1366 $lcs += sizeof($edit->orig);
1367 }
1368 }
1369 return $lcs;
1370 }

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

1381 {
1382 $lines = array();
1383
1384 foreach ($this->edits as $edit) {
1385 if ($edit->orig) {
1386 array_splice($lines, sizeof($lines), 0, $edit->orig);
1387 }
1388 }
1389 return $lines;
1390 }

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

1330 {
1331 $rev = $this;
1332 $rev->edits = array();
1333 foreach ($this->edits as $edit) {
1334 $rev->edits[] = $edit->reverse();
1335 }
1336 return $rev;
1337 }

Referenced by _check().

+ Here is the caller graph for this function:

Field Documentation

◆ $edits

Diff::$edits

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

Referenced by MappedDiff\__construct().


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