PluginProbe
WP Reset / 2.06
WP Reset v2.06
trunk 1.0 1.1 1.11 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.77 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.90 All 42 releases
wp-reset / libs / diff / Renderer / Text / Unified.php

Unified.php in WP Reset 2.06, at libs/diff/Renderer/Text/Unified.php

87 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Unified diff generator for PHP DiffLib.
4 *
5 * PHP version 5
6 *
7 * Copyright (c) 2009 Chris Boulton <chris.boulton@interspire.com>
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the Chris Boulton nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * @package DiffLib
36 * @author Chris Boulton <chris.boulton@interspire.com>
37 * @copyright (c) 2009 Chris Boulton
38 * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
39 * @version 1.1
40 * @link http://github.com/chrisboulton/php-diff
41 */
42
43 require_once dirname(__FILE__).'/../Abstract.php';
44
45 class WPR_Diff_Renderer_Text_Unified extends WPR_Diff_Renderer_Abstract
46 {
47 /**
48 * Render and return a unified diff.
49 *
50 * @return string The unified diff.
51 */
52 public function render()
53 {
54 $diff = '';
55 $opCodes = $this->diff->getGroupedOpcodes();
56 foreach($opCodes as $group) {
57 $lastItem = count($group)-1;
58 $i1 = $group[0][1];
59 $i2 = $group[$lastItem][2];
60 $j1 = $group[0][3];
61 $j2 = $group[$lastItem][4];
62
63 if($i1 == 0 && $i2 == 0) {
64 $i1 = -1;
65 $i2 = -1;
66 }
67
68 $diff .= '@@ -'.($i1 + 1).','.($i2 - $i1).' +'.($j1 + 1).','.($j2 - $j1)." @@\n";
69 foreach($group as $code) {
70 list($tag, $i1, $i2, $j1, $j2) = $code;
71 if($tag == 'equal') {
72 $diff .= ' '.implode("\n ", $this->diff->GetA($i1, $i2))."\n";
73 }
74 else {
75 if($tag == 'replace' || $tag == 'delete') {
76 $diff .= '-'.implode("\n-", $this->diff->GetA($i1, $i2))."\n";
77 }
78
79 if($tag == 'replace' || $tag == 'insert') {
80 $diff .= '+'.implode("\n+", $this->diff->GetB($j1, $j2))."\n";
81 }
82 }
83 }
84 }
85 return $diff;
86 }
87 }