Skip to content

Commit d0431f1

Browse files
authored
Merge pull request #14 from JBlond/development
merge Development
2 parents efc8c8a + 288f33c commit d0431f1

File tree

13 files changed

+26
-306
lines changed

13 files changed

+26
-306
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ files. Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuer
4848

4949
* Ability to ignore blank line changes
5050
* 3 way diff support
51-
* Performance optimizations
5251

5352
## Contributors
5453

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"autoload": {
2828
"psr-4": {
29-
"jblond\\Diff\\": "lib/jblond"
29+
"jblond\\": "lib/jblond"
3030
}
3131
}
3232
}

example/b.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<title>Goodbye Cruel World!</title>
66
</head>
77
<body>
8+
<p>Just a small amount of new text...</p>
89
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
910

1011
<pre>
@@ -15,6 +16,5 @@
1516
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
1617
</pre>
1718
<p>Do you know in Japanese, "魚の缶詰" means fish can.</p>
18-
<p>Just a small amount of new text...</p>
1919
</body>
2020
</html>

lib/jblond/Diff.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,11 @@
1212
*
1313
* PHP version 7.1 or greater
1414
*
15-
* Copyright (c) 2009 Chris Boulton <[email protected]>
16-
*
17-
* All rights reserved.
18-
*
19-
* Redistribution and use in source and binary forms, with or without
20-
* modification, are permitted provided that the following conditions are met:
21-
*
22-
* - Redistributions of source code must retain the above copyright notice,
23-
* this list of conditions and the following disclaimer.
24-
* - Redistributions in binary form must reproduce the above copyright notice,
25-
* this list of conditions and the following disclaimer in the documentation
26-
* and/or other materials provided with the distribution.
27-
* - Neither the name of the Chris Boulton nor the names of its contributors
28-
* may be used to endorse or promote products derived from this software
29-
* without specific prior written permission.
30-
*
31-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
35-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41-
* POSSIBILITY OF SUCH DAMAGE.
42-
*
4315
* @package jblond
4416
* @author Chris Boulton <[email protected]>
4517
* @copyright (c) 2009 Chris Boulton
4618
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
47-
* @version 1.10
19+
* @version 1.11
4820
* @link https://github.com/JBlond/php-diff
4921
*/
5022
class Diff

lib/jblond/Diff/Renderer/Html/HtmlArray.php

+12-40
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,11 @@
99
*
1010
* PHP version 7.1 or greater
1111
*
12-
* Copyright (c) 2009 Chris Boulton <[email protected]>
13-
*
14-
* All rights reserved.
15-
*
16-
* Redistribution and use in source and binary forms, with or without
17-
* modification, are permitted provided that the following conditions are met:
18-
*
19-
* - Redistributions of source code must retain the above copyright notice,
20-
* this list of conditions and the following disclaimer.
21-
* - Redistributions in binary form must reproduce the above copyright notice,
22-
* this list of conditions and the following disclaimer in the documentation
23-
* and/or other materials provided with the distribution.
24-
* - Neither the name of the Chris Boulton nor the names of its contributors
25-
* may be used to endorse or promote products derived from this software
26-
* without specific prior written permission.
27-
*
28-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38-
* POSSIBILITY OF SUCH DAMAGE.
39-
*
4012
* @package jblond\Diff\Renderer\Html
4113
* @author Chris Boulton <[email protected]>
4214
* @copyright (c) 2009 Chris Boulton
4315
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
44-
* @version 1.10
16+
* @version 1.11
4517
* @link https://github.com/JBlond/php-diff
4618
*/
4719
class HtmlArray extends RendererAbstract
@@ -112,11 +84,11 @@ public function renderHtml($changes, $object)
11284
*/
11385
public function render()
11486
{
115-
// As we'll be modifying a & b to include our change markers,
87+
// As we'll be modifying old & new to include our change markers,
11688
// we need to get the contents and store them here. That way
11789
// we're not going to destroy the original data
118-
$a = $this->diff->getOld();
119-
$b = $this->diff->getNew();
90+
$old = $this->diff->getOld();
91+
$new = $this->diff->getNew();
12092

12193
$changes = array();
12294
$opCodes = $this->diff->getGroupedOpcodes();
@@ -129,8 +101,8 @@ public function render()
129101

130102
if ($tag == 'replace' && $i2 - $i1 == $j2 - $j1) {
131103
for ($i = 0; $i < ($i2 - $i1); ++$i) {
132-
$fromLine = $a[$i1 + $i];
133-
$toLine = $b[$j1 + $i];
104+
$fromLine = $old[$i1 + $i];
105+
$toLine = $new[$j1 + $i];
134106

135107
list($start, $end) = $this->getChangeExtent($fromLine, $toLine);
136108
if ($start != 0 || $end != 0) {
@@ -145,8 +117,8 @@ public function render()
145117
"\0" . mb_substr($toLine, $start, $realEnd - $start) . "\1" .
146118
mb_substr($toLine, $realEnd);
147119

148-
$a[$i1 + $i] = $fromLine;
149-
$b[$j1 + $i] = $toLine;
120+
$old[$i1 + $i] = $fromLine;
121+
$new[$j1 + $i] = $toLine;
150122
}
151123
}
152124
}
@@ -159,20 +131,20 @@ public function render()
159131
$lastTag = $tag;
160132

161133
if ($tag == 'equal') {
162-
$lines = array_slice($a, $i1, ($i2 - $i1));
134+
$lines = array_slice($old, $i1, ($i2 - $i1));
163135
$blocks[$lastBlock]['base']['lines'] += $this->formatLines($lines);
164-
$lines = array_slice($b, $j1, ($j2 - $j1));
136+
$lines = array_slice($new, $j1, ($j2 - $j1));
165137
$blocks[$lastBlock]['changed']['lines'] += $this->formatLines($lines);
166138
} else {
167139
if ($tag == 'replace' || $tag == 'delete') {
168-
$lines = array_slice($a, $i1, ($i2 - $i1));
140+
$lines = array_slice($old, $i1, ($i2 - $i1));
169141
$lines = $this->formatLines($lines);
170142
$lines = str_replace(array("\0", "\1"), array('<del>', '</del>'), $lines);
171143
$blocks[$lastBlock]['base']['lines'] += $lines;
172144
}
173145

174146
if ($tag == 'replace' || $tag == 'insert') {
175-
$lines = array_slice($b, $j1, ($j2 - $j1));
147+
$lines = array_slice($new, $j1, ($j2 - $j1));
176148
$lines = $this->formatLines($lines);
177149
$lines = str_replace(array("\0", "\1"), array('<ins>', '</ins>'), $lines);
178150
$blocks[$lastBlock]['changed']['lines'] += $lines;

lib/jblond/Diff/Renderer/Html/Inline.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,11 @@
77
*
88
* PHP version 7.1 or greater
99
*
10-
* Copyright (c) 2009 Chris Boulton <[email protected]>
11-
*
12-
* All rights reserved.
13-
*
14-
* Redistribution and use in source and binary forms, with or without
15-
* modification, are permitted provided that the following conditions are met:
16-
*
17-
* - Redistributions of source code must retain the above copyright notice,
18-
* this list of conditions and the following disclaimer.
19-
* - Redistributions in binary form must reproduce the above copyright notice,
20-
* this list of conditions and the following disclaimer in the documentation
21-
* and/or other materials provided with the distribution.
22-
* - Neither the name of the Chris Boulton nor the names of its contributors
23-
* may be used to endorse or promote products derived from this software
24-
* without specific prior written permission.
25-
*
26-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36-
* POSSIBILITY OF SUCH DAMAGE.
37-
*
3810
* @package jblond\Diff\Renderer\Html
3911
* @author Chris Boulton <[email protected]>
4012
* @copyright (c) 2009 Chris Boulton
4113
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
42-
* @version 1.10
14+
* @version 1.11
4315
* @link https://github.com/JBlond/php-diff
4416
*/
4517
class Inline extends HtmlArray

lib/jblond/Diff/Renderer/Html/SideBySide.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,11 @@
77
*
88
* PHP version 7.1 or greater
99
*
10-
* Copyright (c) 2009 Chris Boulton <[email protected]>
11-
*
12-
* All rights reserved.
13-
*
14-
* Redistribution and use in source and binary forms, with or without
15-
* modification, are permitted provided that the following conditions are met:
16-
*
17-
* - Redistributions of source code must retain the above copyright notice,
18-
* this list of conditions and the following disclaimer.
19-
* - Redistributions in binary form must reproduce the above copyright notice,
20-
* this list of conditions and the following disclaimer in the documentation
21-
* and/or other materials provided with the distribution.
22-
* - Neither the name of the Chris Boulton nor the names of its contributors
23-
* may be used to endorse or promote products derived from this software
24-
* without specific prior written permission.
25-
*
26-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36-
* POSSIBILITY OF SUCH DAMAGE.
37-
*
3810
* @package jblond\Diff\Renderer\Html
3911
* @author Chris Boulton <[email protected]>
4012
* @copyright (c) 2009 Chris Boulton
4113
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
42-
* @version 1.10
14+
* @version 1.11
4315
* @link https://github.com/JBlond/php-diff
4416
*/
4517
class SideBySide extends HtmlArray

lib/jblond/Diff/Renderer/RendererAbstract.php

+5-30
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,25 @@
22
declare(strict_types=1);
33
namespace jblond\Diff\Renderer;
44

5+
use jblond\Diff;
6+
57
/**
68
* Abstract class for diff renderers in PHP DiffLib.
79
*
810
* PHP version 7.1 or greater
911
*
10-
* Copyright (c) 2009 Chris Boulton <[email protected]>
11-
*
12-
* All rights reserved.
13-
*
14-
* Redistribution and use in source and binary forms, with or without
15-
* modification, are permitted provided that the following conditions are met:
16-
*
17-
* - Redistributions of source code must retain the above copyright notice,
18-
* this list of conditions and the following disclaimer.
19-
* - Redistributions in binary form must reproduce the above copyright notice,
20-
* this list of conditions and the following disclaimer in the documentation
21-
* and/or other materials provided with the distribution.
22-
* - Neither the name of the Chris Boulton nor the names of its contributors
23-
* may be used to endorse or promote products derived from this software
24-
* without specific prior written permission.
25-
*
26-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36-
* POSSIBILITY OF SUCH DAMAGE.
37-
*
3812
* @package jblond\Diff\Renderer
3913
* @author Chris Boulton <[email protected]>
4014
* @copyright (c) 2009 Chris Boulton
4115
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
42-
* @version 1.10
16+
* @version 1.11
4317
* @link https://github.com/JBlond/php-diff
4418
*/
4519
abstract class RendererAbstract
4620
{
21+
4722
/**
48-
* @var object Instance of the diff class that this renderer is generating the rendered diff for.
23+
* @var Diff $diff Instance of the diff class that this renderer is generating the rendered diff for.
4924
*/
5025
public $diff;
5126

lib/jblond/Diff/Renderer/Text/Context.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,11 @@
99
*
1010
* PHP version 7.1 or greater
1111
*
12-
* Copyright (c) 2009 Chris Boulton <[email protected]>
13-
*
14-
* All rights reserved.
15-
*
16-
* Redistribution and use in source and binary forms, with or without
17-
* modification, are permitted provided that the following conditions are met:
18-
*
19-
* - Redistributions of source code must retain the above copyright notice,
20-
* this list of conditions and the following disclaimer.
21-
* - Redistributions in binary form must reproduce the above copyright notice,
22-
* this list of conditions and the following disclaimer in the documentation
23-
* and/or other materials provided with the distribution.
24-
* - Neither the name of the Chris Boulton nor the names of its contributors
25-
* may be used to endorse or promote products derived from this software
26-
* without specific prior written permission.
27-
*
28-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38-
* POSSIBILITY OF SUCH DAMAGE.
39-
*
4012
* @package jblond\Diff\Renderer\Text
4113
* @author Chris Boulton <[email protected]>
4214
* @copyright (c) 2009 Chris Boulton
4315
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
44-
* @version 1.10
16+
* @version 1.11
4517
* @link https://github.com/JBlond/php-diff
4618
*/
4719
class Context extends RendererAbstract

lib/jblond/Diff/Renderer/Text/Unified.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,11 @@
99
*
1010
* PHP version 7.1 or greater
1111
*
12-
* Copyright (c) 2009 Chris Boulton <[email protected]>
13-
*
14-
* All rights reserved.
15-
*
16-
* Redistribution and use in source and binary forms, with or without
17-
* modification, are permitted provided that the following conditions are met:
18-
*
19-
* - Redistributions of source code must retain the above copyright notice,
20-
* this list of conditions and the following disclaimer.
21-
* - Redistributions in binary form must reproduce the above copyright notice,
22-
* this list of conditions and the following disclaimer in the documentation
23-
* and/or other materials provided with the distribution.
24-
* - Neither the name of the Chris Boulton nor the names of its contributors
25-
* may be used to endorse or promote products derived from this software
26-
* without specific prior written permission.
27-
*
28-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38-
* POSSIBILITY OF SUCH DAMAGE.
39-
*
4012
* @package jblond\Diff\Renderer\Text
4113
* @author Chris Boulton <[email protected]>
4214
* @copyright (c) 2009 Chris Boulton
4315
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
44-
* @version 1.10
16+
* @version 1.11
4517
* @link https://github.com/JBlond/php-diff
4618
*/
4719

0 commit comments

Comments
 (0)