unified.php 1.4 KB

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