Unified.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * "Unified" diff renderer.
  4. *
  5. * This class renders the diff in classic "unified diff" format.
  6. *
  7. * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
  8. *
  9. * See the enclosed file COPYING for license information (LGPL). If you did
  10. * not receive this file, see http://www.horde.org/licenses/lgpl21.
  11. *
  12. * @author Ciprian Popovici
  13. * @package Text_Diff
  14. */
  15. class Horde_Text_Diff_Renderer_Unified extends Horde_Text_Diff_Renderer
  16. {
  17. /**
  18. * Number of leading context "lines" to preserve.
  19. */
  20. protected $_leading_context_lines = 4;
  21. /**
  22. * Number of trailing context "lines" to preserve.
  23. */
  24. protected $_trailing_context_lines = 4;
  25. protected function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
  26. {
  27. if ($xlen != 1) {
  28. $xbeg .= ',' . $xlen;
  29. }
  30. if ($ylen != 1) {
  31. $ybeg .= ',' . $ylen;
  32. }
  33. return "@@ -$xbeg +$ybeg @@";
  34. }
  35. protected function _context($lines)
  36. {
  37. return $this->_lines($lines, ' ');
  38. }
  39. protected function _added($lines)
  40. {
  41. return $this->_lines($lines, '+');
  42. }
  43. protected function _deleted($lines)
  44. {
  45. return $this->_lines($lines, '-');
  46. }
  47. protected function _changed($orig, $final)
  48. {
  49. return $this->_deleted($orig) . $this->_added($final);
  50. }
  51. }