Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

65 Zeilen
2.2 KiB

  1. <?php
  2. /**
  3. * Class used internally by Diff to actually compute the diffs.
  4. *
  5. * This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
  6. * to compute the differences between the two input arrays.
  7. *
  8. * Copyright 2004-2010 The Horde Project (http://www.horde.org/)
  9. *
  10. * See the enclosed file COPYING for license information (LGPL). If you did
  11. * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
  12. *
  13. * @author Jon Parise <jon@horde.org>
  14. * @package Text_Diff
  15. */
  16. class Text_Diff_Engine_xdiff {
  17. /**
  18. */
  19. function diff($from_lines, $to_lines)
  20. {
  21. array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
  22. array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
  23. /* Convert the two input arrays into strings for xdiff processing. */
  24. $from_string = implode("\n", $from_lines);
  25. $to_string = implode("\n", $to_lines);
  26. /* Diff the two strings and convert the result to an array. */
  27. $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
  28. $diff = explode("\n", $diff);
  29. /* Walk through the diff one line at a time. We build the $edits
  30. * array of diff operations by reading the first character of the
  31. * xdiff output (which is in the "unified diff" format).
  32. *
  33. * Note that we don't have enough information to detect "changed"
  34. * lines using this approach, so we can't add Text_Diff_Op_changed
  35. * instances to the $edits array. The result is still perfectly
  36. * valid, albeit a little less descriptive and efficient. */
  37. $edits = array();
  38. foreach ($diff as $line) {
  39. if (!strlen($line)) {
  40. continue;
  41. }
  42. switch ($line[0]) {
  43. case ' ':
  44. $edits[] = new Text_Diff_Op_copy(array(substr($line, 1)));
  45. break;
  46. case '+':
  47. $edits[] = new Text_Diff_Op_add(array(substr($line, 1)));
  48. break;
  49. case '-':
  50. $edits[] = new Text_Diff_Op_delete(array(substr($line, 1)));
  51. break;
  52. }
  53. }
  54. return $edits;
  55. }
  56. }