BlockBuilder.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
  4. *
  5. * See the enclosed file COPYING for license information (LGPL). If you did
  6. * not receive this file, see http://www.horde.org/licenses/lgpl21.
  7. *
  8. * @package Text_Diff
  9. * @author Geoffrey T. Dairiki <dairiki@dairiki.org>
  10. */
  11. class Horde_Text_Diff_ThreeWay_BlockBuilder
  12. {
  13. public function __construct()
  14. {
  15. $this->_init();
  16. }
  17. public function input($lines)
  18. {
  19. if ($lines) {
  20. $this->_append($this->orig, $lines);
  21. }
  22. }
  23. public function out1($lines)
  24. {
  25. if ($lines) {
  26. $this->_append($this->final1, $lines);
  27. }
  28. }
  29. public function out2($lines)
  30. {
  31. if ($lines) {
  32. $this->_append($this->final2, $lines);
  33. }
  34. }
  35. public function isEmpty()
  36. {
  37. return !$this->orig && !$this->final1 && !$this->final2;
  38. }
  39. public function finish()
  40. {
  41. if ($this->isEmpty()) {
  42. return false;
  43. } else {
  44. $edit = new Horde_Text_Diff_ThreeWay_Op_Base($this->orig, $this->final1, $this->final2);
  45. $this->_init();
  46. return $edit;
  47. }
  48. }
  49. protected function _init()
  50. {
  51. $this->orig = $this->final1 = $this->final2 = array();
  52. }
  53. protected function _append(&$array, $lines)
  54. {
  55. array_splice($array, sizeof($array), 0, $lines);
  56. }
  57. }