Context.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * "Context" diff renderer.
  4. *
  5. * This class renders the diff in classic "context 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. * @package Text_Diff
  13. */
  14. class Horde_Text_Diff_Renderer_Context extends Horde_Text_Diff_Renderer
  15. {
  16. /**
  17. * Number of leading context "lines" to preserve.
  18. */
  19. protected $_leading_context_lines = 4;
  20. /**
  21. * Number of trailing context "lines" to preserve.
  22. */
  23. protected $_trailing_context_lines = 4;
  24. protected $_second_block = '';
  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. $this->_second_block = "--- $ybeg ----\n";
  34. return "***************\n*** $xbeg ****";
  35. }
  36. protected function _endBlock()
  37. {
  38. return $this->_second_block;
  39. }
  40. protected function _context($lines)
  41. {
  42. $this->_second_block .= $this->_lines($lines, ' ');
  43. return $this->_lines($lines, ' ');
  44. }
  45. protected function _added($lines)
  46. {
  47. $this->_second_block .= $this->_lines($lines, '+ ');
  48. return '';
  49. }
  50. protected function _deleted($lines)
  51. {
  52. return $this->_lines($lines, '- ');
  53. }
  54. protected function _changed($orig, $final)
  55. {
  56. $this->_second_block .= $this->_lines($final, '! ');
  57. return $this->_lines($orig, '! ');
  58. }
  59. }