Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / includes / diff / UnifiedDiffFormatter.php
1 <?php
2 /**
3 * Portions taken from phpwiki-1.3.3.
4 *
5 * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
6 * You may copy this code freely under the conditions of the GPL.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 * @ingroup DifferenceEngine
25 */
26
27 /**
28 * A formatter that outputs unified diffs
29 * @ingroup DifferenceEngine
30 */
31 class UnifiedDiffFormatter extends DiffFormatter {
32
33 /** @var int */
34 protected $leadingContextLines = 2;
35
36 /** @var int */
37 protected $trailingContextLines = 2;
38
39 /**
40 * @param string[] $lines
41 * @param string $prefix
42 */
43 protected function lines( $lines, $prefix = ' ' ) {
44 foreach ( $lines as $line ) {
45 $this->writeOutput( "{$prefix}{$line}\n" );
46 }
47 }
48
49 /**
50 * @param string[] $lines
51 */
52 protected function added( $lines ) {
53 $this->lines( $lines, '+' );
54 }
55
56 /**
57 * @param string[] $lines
58 */
59 protected function deleted( $lines ) {
60 $this->lines( $lines, '-' );
61 }
62
63 /**
64 * @param string[] $orig
65 * @param string[] $closing
66 */
67 protected function changed( $orig, $closing ) {
68 $this->deleted( $orig );
69 $this->added( $closing );
70 }
71
72 /**
73 * @param int $xbeg
74 * @param int $xlen
75 * @param int $ybeg
76 * @param int $ylen
77 *
78 * @return string
79 */
80 protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
81 return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
82 }
83
84 }