Definition at line 16 of file Diff.php.
◆ __construct()
Text_Diff::__construct |
( |
|
$from_lines, |
|
|
|
$to_lines |
|
) |
| |
Computes diffs between sequences of strings.
- Parameters
-
array | $from_lines | An array of strings. Typically these are lines from a file. |
array | $to_lines | An array of strings. |
Definition at line 33 of file Diff.php.
References $engine, and array.
35 array_walk($from_lines,
array($this,
'_trimNewlines'));
36 array_walk($to_lines,
array($this,
'_trimNewlines'));
38 if (extension_loaded(
'xdiff')) {
44 $this->_edits =
$engine->diff($from_lines, $to_lines);
Create styles array
The data for the language used.
◆ _check()
Text_Diff::_check |
( |
|
$from_lines, |
|
|
|
$to_lines |
|
) |
| |
Checks a diff for validity.
This is here only for debugging purposes.
Definition at line 166 of file Diff.php.
References getFinal(), getOriginal(), and reverse().
168 if (serialize($from_lines) != serialize($this->
getOriginal())) {
169 trigger_error(
"Reconstructed original doesn't match", E_USER_ERROR);
171 if (serialize($to_lines) != serialize($this->
getFinal())) {
172 trigger_error(
"Reconstructed final doesn't match", E_USER_ERROR);
176 if (serialize($to_lines) != serialize($rev->getOriginal())) {
177 trigger_error(
"Reversed original doesn't match", E_USER_ERROR);
179 if (serialize($from_lines) != serialize($rev->getFinal())) {
180 trigger_error(
"Reversed final doesn't match", E_USER_ERROR);
184 foreach ($this->_edits as $edit) {
185 if ($prevtype == get_class($edit)) {
186 trigger_error(
"Edit sequence is non-optimal", E_USER_ERROR);
188 $prevtype = get_class($edit);
getOriginal()
Gets the original set of lines.
getFinal()
Gets the final set of lines.
reverse()
Computes a reversed diff.
◆ _trimNewlines()
Text_Diff::_trimNewlines |
( |
& |
$line, |
|
|
|
$key |
|
) |
| |
Removes trailing newlines from a line of text.
This is meant to be used with array_walk().
- Parameters
-
string | $line | The line to trim. |
integer | $key | The index of the line in the array. Not used. |
Definition at line 156 of file Diff.php.
References array.
158 $line = str_replace(
array(
"\n",
"\r"),
'', $line);
Create styles array
The data for the language used.
◆ getDiff()
Returns the array of differences.
Definition at line 50 of file Diff.php.
References $_edits.
◆ getFinal()
Gets the final set of lines.
This reconstructs the $to_lines parameter passed to the constructor.
- Returns
- array The sequence of strings.
Definition at line 138 of file Diff.php.
References array.
Referenced by _check().
141 foreach ($this->_edits as $edit) {
143 array_splice($lines, count($lines), 0, $edit->final);
Create styles array
The data for the language used.
◆ getOriginal()
Text_Diff::getOriginal |
( |
| ) |
|
Gets the original set of lines.
This reconstructs the $from_lines parameter passed to the constructor.
- Returns
- array The original sequence of strings.
Definition at line 120 of file Diff.php.
References array.
Referenced by _check().
123 foreach ($this->_edits as $edit) {
125 array_splice($lines, count($lines), 0, $edit->orig);
Create styles array
The data for the language used.
◆ isEmpty()
Checks for an empty diff.
- Returns
- boolean True if two sequences were identical.
Definition at line 85 of file Diff.php.
87 foreach ($this->_edits as $edit) {
◆ lcs()
◆ reverse()
Computes a reversed diff.
Example: $diff = &new Text_Diff($lines1, $lines2); $rev = $diff->reverse();
- Returns
- Text_Diff A Diff object representing the inverse of the original diff. Note that we purposely don't return a reference here, since this essentially is a clone() method.
Definition at line 69 of file Diff.php.
References array.
Referenced by _check().
73 $rev->_edits =
array();
74 foreach ($this->_edits as $edit) {
75 $rev->_edits[] = $edit->reverse();
Create styles array
The data for the language used.
◆ $_edits
The documentation for this class was generated from the following file:
- Services/XHTMLValidator/validator/Text_Diff/Diff.php