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:
18: public function input($lines)
19: {
20: if ($lines) {
21: $this->_append($this->orig, $lines);
22: }
23: }
24:
25: public function out1($lines)
26: {
27: if ($lines) {
28: $this->_append($this->final1, $lines);
29: }
30: }
31:
32: public function out2($lines)
33: {
34: if ($lines) {
35: $this->_append($this->final2, $lines);
36: }
37: }
38:
39: public function isEmpty()
40: {
41: return !$this->orig && !$this->final1 && !$this->final2;
42: }
43:
44: public function finish()
45: {
46: if ($this->isEmpty()) {
47: return false;
48: } else {
49: $edit = new Horde_Text_Diff_ThreeWay_Op_Base($this->orig, $this->final1, $this->final2);
50: $this->_init();
51: return $edit;
52: }
53: }
54:
55: protected function _init()
56: {
57: $this->orig = $this->final1 = $this->final2 = array();
58: }
59:
60: protected function _append(&$array, $lines)
61: {
62: array_splice($array, sizeof($array), 0, $lines);
63: }
64: }
65: