context.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.4 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. * @package Text_Diff
  15. */
  16. /**
  17. * @package Text_Diff
  18. */
  19. class Text_Diff_Renderer_context extends Text_Diff_Renderer {
  20. /**
  21. * Number of leading context "lines" to preserve.
  22. */
  23. var $_leading_context_lines = 4;
  24. /**
  25. * Number of trailing context "lines" to preserve.
  26. */
  27. var $_trailing_context_lines = 4;
  28. var $_second_block = '';
  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. $this->_second_block = "--- $ybeg ----\n";
  38. return "***************\n*** $xbeg ****";
  39. }
  40. function _endBlock()
  41. {
  42. return $this->_second_block;
  43. }
  44. function _context($lines)
  45. {
  46. $this->_second_block .= $this->_lines($lines, ' ');
  47. return $this->_lines($lines, ' ');
  48. }
  49. function _added($lines)
  50. {
  51. $this->_second_block .= $this->_lines($lines, '+ ');
  52. return '';
  53. }
  54. function _deleted($lines)
  55. {
  56. return $this->_lines($lines, '- ');
  57. }
  58. function _changed($orig, $final)
  59. {
  60. $this->_second_block .= $this->_lines($final, '! ');
  61. return $this->_lines($orig, '! ');
  62. }
  63. }