Text_Diff_Engine_xdiff

Class used internally by Diff to actually compute the diffs.

Defined (1)

The class is defined in the following location(s).

/wp-includes/Text/Diff/Engine/xdiff.php  
  1. class Text_Diff_Engine_xdiff { 
  2.  
  3. /** 
  4. */ 
  5. function diff($from_lines, $to_lines) 
  6. array_walk($from_lines, array('Text_Diff', 'trimNewlines')); 
  7. array_walk($to_lines, array('Text_Diff', 'trimNewlines')); 
  8.  
  9. /** Convert the two input arrays into strings for xdiff processing. */ 
  10. $from_string = implode("\n", $from_lines); 
  11. $to_string = implode("\n", $to_lines); 
  12.  
  13. /** Diff the two strings and convert the result to an array. */ 
  14. $diff = xdiff_string_diff($from_string, $to_string, count($to_lines)); 
  15. $diff = explode("\n", $diff); 
  16.  
  17. /** Walk through the diff one line at a time. We build the $edits 
  18. * array of diff operations by reading the first character of the 
  19. * xdiff output (which is in the "unified diff" format). 
  20. * Note that we don't have enough information to detect "changed" 
  21. * lines using this approach, so we can't add Text_Diff_Op_changed 
  22. * instances to the $edits array. The result is still perfectly 
  23. * valid, albeit a little less descriptive and efficient. */ 
  24. $edits = array(); 
  25. foreach ($diff as $line) { 
  26. if (!strlen($line)) { 
  27. continue; 
  28. switch ($line[0]) { 
  29. case ' ': 
  30. $edits[] = new Text_Diff_Op_copy(array(substr($line, 1))); 
  31. break; 
  32.  
  33. case '+': 
  34. $edits[] = new Text_Diff_Op_add(array(substr($line, 1))); 
  35. break; 
  36.  
  37. case '-': 
  38. $edits[] = new Text_Diff_Op_delete(array(substr($line, 1))); 
  39. break; 
  40.  
  41. return $edits; 
  42.