1<?php
2/**
3 * "Unified" diff renderer.
4 *
5 * This class renders the diff in classic "unified diff" format.
6 *
7 * Copyright 2004-2017 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 * @author  Ciprian Popovici
13 * @package Text_Diff
14 */
15class Horde_Text_Diff_Renderer_Unified extends Horde_Text_Diff_Renderer
16{
17    /**
18     * Number of leading context "lines" to preserve.
19     */
20    protected $_leading_context_lines = 4;
21
22    /**
23     * Number of trailing context "lines" to preserve.
24     */
25    protected $_trailing_context_lines = 4;
26
27    protected function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
28    {
29        if ($xlen != 1) {
30            $xbeg .= ',' . $xlen;
31        }
32        if ($ylen != 1) {
33            $ybeg .= ',' . $ylen;
34        }
35        return "@@ -$xbeg +$ybeg @@";
36    }
37
38    protected function _context($lines)
39    {
40        return $this->_lines($lines, ' ');
41    }
42
43    protected function _added($lines)
44    {
45        return $this->_lines($lines, '+');
46    }
47
48    protected function _deleted($lines)
49    {
50        return $this->_lines($lines, '-');
51    }
52
53    protected function _changed($orig, $final)
54    {
55        return $this->_deleted($orig) . $this->_added($final);
56    }
57}
58