Inheritance diagram for Text_Diff:Public Member Functions | |
| Text_Diff ($from_lines, $to_lines) | |
| Computes diffs between sequences of strings. | |
| getDiff () | |
| Returns the array of differences. | |
| reverse () | |
| Computes a reversed diff. | |
| isEmpty () | |
| Checks for an empty diff. | |
| lcs () | |
| Computes the length of the Longest Common Subsequence (LCS). | |
| getOriginal () | |
| Gets the original set of lines. | |
| getFinal () | |
| Gets the final set of lines. | |
| _trimNewlines (&$line, $key) | |
| Removes trailing newlines from a line of text. | |
| _check ($from_lines, $to_lines) | |
| Checks a diff for validity. | |
Data Fields | |
| $_edits | |
Definition at line 16 of file Diff.php.
| Text_Diff::_check | ( | $ | from_lines, | |
| $ | to_lines | |||
| ) |
Checks a diff for validity.
This is here only for debugging purposes.
Definition at line 165 of file Diff.php.
References getFinal(), getOriginal(), and reverse().
{
if (serialize($from_lines) != serialize($this->getOriginal())) {
trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
}
if (serialize($to_lines) != serialize($this->getFinal())) {
trigger_error("Reconstructed final doesn't match", E_USER_ERROR);
}
$rev = $this->reverse();
if (serialize($to_lines) != serialize($rev->getOriginal())) {
trigger_error("Reversed original doesn't match", E_USER_ERROR);
}
if (serialize($from_lines) != serialize($rev->getFinal())) {
trigger_error("Reversed final doesn't match", E_USER_ERROR);
}
$prevtype = null;
foreach ($this->_edits as $edit) {
if ($prevtype == get_class($edit)) {
trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
}
$prevtype = get_class($edit);
}
return true;
}
Here is the call graph for this function:| Text_Diff::_trimNewlines | ( | &$ | line, | |
| $ | key | |||
| ) |
| Text_Diff::getDiff | ( | ) |
| Text_Diff::getFinal | ( | ) |
Gets the final set of lines.
This reconstructs the $to_lines parameter passed to the constructor.
Definition at line 137 of file Diff.php.
Referenced by _check().
{
$lines = array();
foreach ($this->_edits as $edit) {
if ($edit->final) {
array_splice($lines, count($lines), 0, $edit->final);
}
}
return $lines;
}
Here is the caller graph for this function:| Text_Diff::getOriginal | ( | ) |
Gets the original set of lines.
This reconstructs the $from_lines parameter passed to the constructor.
Definition at line 119 of file Diff.php.
Referenced by _check().
{
$lines = array();
foreach ($this->_edits as $edit) {
if ($edit->orig) {
array_splice($lines, count($lines), 0, $edit->orig);
}
}
return $lines;
}
Here is the caller graph for this function:| Text_Diff::isEmpty | ( | ) |
Checks for an empty diff.
Definition at line 84 of file Diff.php.
{
foreach ($this->_edits as $edit) {
if (!$edit instanceof Text_Diff_Op_copy) {
return false;
}
}
return true;
}
| Text_Diff::lcs | ( | ) |
Computes the length of the Longest Common Subsequence (LCS).
This is mostly for diagnostic purposes.
Definition at line 101 of file Diff.php.
{
$lcs = 0;
foreach ($this->_edits as $edit) {
if ($edit instanceof Text_Diff_Op_copy) {
$lcs += count($edit->orig);
}
}
return $lcs;
}
| Text_Diff::reverse | ( | ) |
Computes a reversed diff.
Example: $diff = &new Text_Diff($lines1, $lines2); $rev = $diff->reverse();
Definition at line 68 of file Diff.php.
Referenced by _check().
{
$rev = clone($obj);
$rev->_edits = array();
foreach ($this->_edits as $edit) {
$rev->_edits[] = $edit->reverse();
}
return $rev;
}
Here is the caller graph for this function:| Text_Diff::Text_Diff | ( | $ | from_lines, | |
| $ | to_lines | |||
| ) |
Computes diffs between sequences of strings.
| array | $from_lines An array of strings. Typically these are lines from a file. | |
| array | $to_lines An array of strings. |
Definition at line 32 of file Diff.php.
Referenced by Text_MappedDiff::Text_MappedDiff().
{
array_walk($from_lines, array($this, '_trimNewlines'));
array_walk($to_lines, array($this, '_trimNewlines'));
if (extension_loaded('xdiff')) {
$engine = new Text_Diff_Engine_xdiff();
} else {
$engine = new Text_Diff_Engine_native();
}
$this->_edits = $engine->diff($from_lines, $to_lines);
}
Here is the caller graph for this function:
1.7.1