ILIAS  release_8 Revision v8.24
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 1297 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 1309 of file class.WordLevelDiff.php.

1310 {
1311 $eng = new _DiffEngine();
1312 $this->edits = $eng->diff($from_lines, $to_lines);
1313 //$this->_check($from_lines, $to_lines);
1314 }

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

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

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

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

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

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

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

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

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

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

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

Referenced by _check().

+ Here is the caller graph for this function:

Field Documentation

◆ $edits

Diff::$edits

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

Referenced by MappedDiff\__construct().


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