context.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * "Context" diff renderer.
  4. *
  5. * This class renders the diff in classic "context diff" format.
  6. *
  7. * $Horde: framework/Text_Diff/Diff/Renderer/context.php,v 1.3.2.3 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. * @package Text_Diff
  15. */
  16. /** Text_Diff_Renderer */
  17. require_once 'Text/Diff/Renderer.php';
  18. /**
  19. * @package Text_Diff
  20. */
  21. class Text_Diff_Renderer_context extends Text_Diff_Renderer {
  22. /**
  23. * Number of leading context "lines" to preserve.
  24. */
  25. var $_leading_context_lines = 4;
  26. /**
  27. * Number of trailing context "lines" to preserve.
  28. */
  29. var $_trailing_context_lines = 4;
  30. var $_second_block = '';
  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. $this->_second_block = "--- $ybeg ----\n";
  40. return "***************\n*** $xbeg ****";
  41. }
  42. function _endBlock()
  43. {
  44. return $this->_second_block;
  45. }
  46. function _context($lines)
  47. {
  48. $this->_second_block .= $this->_lines($lines, ' ');
  49. return $this->_lines($lines, ' ');
  50. }
  51. function _added($lines)
  52. {
  53. $this->_second_block .= $this->_lines($lines, '+ ');
  54. return '';
  55. }
  56. function _deleted($lines)
  57. {
  58. return $this->_lines($lines, '- ');
  59. }
  60. function _changed($orig, $final)
  61. {
  62. $this->_second_block .= $this->_lines($final, '! ');
  63. return $this->_lines($orig, '! ');
  64. }
  65. }