ILIAS  release_7 Revision v7.30-3-g800a261c036
Text_Diff_Engine_xdiff Class Reference
+ Collaboration diagram for Text_Diff_Engine_xdiff:

Public Member Functions

 diff ($from_lines, $to_lines)
 

Detailed Description

Definition at line 258 of file Diff.php.

Member Function Documentation

◆ diff()

Text_Diff_Engine_xdiff::diff (   $from_lines,
  $to_lines 
)

Definition at line 260 of file Diff.php.

261 {
262 /* Convert the two input arrays into strings for xdiff processing. */
263 $from_string = implode("\n", $from_lines);
264 $to_string = implode("\n", $to_lines);
265
266 /* Diff the two strings and convert the result to an array. */
267 $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
268 $diff = explode("\n", $diff);
269
270 /* Walk through the diff one line at a time. We build the $edits
271 * array of diff operations by reading the first character of the
272 * xdiff output (which is in the "unified diff" format).
273 *
274 * Note that we don't have enough information to detect "changed"
275 * lines using this approach, so we can't add Text_Diff_Op_changed
276 * instances to the $edits array. The result is still perfectly
277 * valid, albeit a little less descriptive and efficient. */
278 $edits = array();
279 foreach ($diff as $line) {
280 switch ($line[0]) {
281 case ' ':
282 $edits[] = new Text_Diff_Op_copy(array(substr($line, 1)));
283 break;
284
285 case '+':
286 $edits[] = new Text_Diff_Op_add(array(substr($line, 1)));
287 break;
288
289 case '-':
290 $edits[] = new Text_Diff_Op_delete(array(substr($line, 1)));
291 break;
292 }
293 }
294
295 return $edits;
296 }

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