unified.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.6 2008/01/04 10:37:27 jan Exp $
  8. *
  9. * Copyright 2004-2008 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. /** Text_Diff_Renderer */
  18. require_once 'Text/Diff/Renderer.php';
  19. /**
  20. * @package Text_Diff
  21. */
  22. class Text_Diff_Renderer_unified extends Text_Diff_Renderer {
  23. /**
  24. * Number of leading context "lines" to preserve.
  25. */
  26. var $_leading_context_lines = 4;
  27. /**
  28. * Number of trailing context "lines" to preserve.
  29. */
  30. var $_trailing_context_lines = 4;
  31. function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
  32. {
  33. if ($xlen != 1) {
  34. $xbeg .= ',' . $xlen;
  35. }
  36. if ($ylen != 1) {
  37. $ybeg .= ',' . $ylen;
  38. }
  39. return "@@ -$xbeg +$ybeg @@";
  40. }
  41. function _context($lines)
  42. {
  43. return $this->_lines($lines, ' ');
  44. }
  45. function _added($lines)
  46. {
  47. return $this->_lines($lines, '+');
  48. }
  49. function _deleted($lines)
  50. {
  51. return $this->_lines($lines, '-');
  52. }
  53. function _changed($orig, $final)
  54. {
  55. return $this->_deleted($orig) . $this->_added($final);
  56. }
  57. }