From 22822bb9417b03927064453d75ffc0ade5722542 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 11:13:17 +0100 Subject: [PATCH 01/52] Support for PHP 5.5 and above https://github.com/chrisboulton/php-diff/pull/25 --- lib/Diff/Renderer/Html/Array.php | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index 0b3f1d50..24df80bc 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -5,10 +5,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -16,20 +16,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package DiffLib @@ -177,7 +177,7 @@ private function formatLines($lines) $lines = array_map(array($this, 'ExpandTabs'), $lines); $lines = array_map(array($this, 'HtmlSafe'), $lines); foreach($lines as &$line) { - $line = preg_replace('# ( +)|^ #e', "\$this->fixSpaces('\\1')", $line); + $line = preg_replace_callback('# ( +)|^ #', array($this, 'fixSpaces'), $line); } return $lines; } @@ -185,12 +185,12 @@ private function formatLines($lines) /** * Replace a string containing spaces with a HTML representation using  . * - * @param string $spaces The string of spaces. + * @param array $matches The string of spaces. * @return string The HTML representation of the string. */ - function fixSpaces($spaces='') + function fixSpaces($matches) { - $count = strlen($spaces); + $count = strlen($matches['0']); if($count == 0) { return ''; } From 0bc8fa48d51214688e8e9f5489371708a338cef7 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 11:15:03 +0100 Subject: [PATCH 02/52] Make `Diff_Renderer_Html_Array::formatLines` method protected https://github.com/chrisboulton/php-diff/pull/26 --- lib/Diff/Renderer/Html/Array.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index 24df80bc..6df708d0 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -172,7 +172,7 @@ private function getChangeExtent($fromLine, $toLine) * @param array $lines Array of lines to format. * @return array Array of the formatted lines. */ - private function formatLines($lines) + protected function formatLines($lines) { $lines = array_map(array($this, 'ExpandTabs'), $lines); $lines = array_map(array($this, 'HtmlSafe'), $lines); From 25905e7155e651e82272cb5a927fec44af491c79 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 11:17:37 +0100 Subject: [PATCH 03/52] correct line number https://github.com/chrisboulton/php-diff/pull/23 --- lib/Diff/Renderer/Html/Inline.php | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index 60e8005a..eae3ae5b 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -5,10 +5,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -16,20 +16,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package DiffLib @@ -128,8 +128,8 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; - $html .= ''.$toLine.''; $html .= ' '; + $html .= ''.$toLine.''; $html .= ''.$line.''; $html .= ''; } From a9b8ef76f6b0ad4796f5269b19f67dbc493340f7 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 11:19:06 +0100 Subject: [PATCH 04/52] bug fix https://github.com/chrisboulton/php-diff/pull/21 --- lib/Diff/SequenceMatcher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index e819e810..07f05e0b 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -631,7 +631,7 @@ private function quickRatio() { if($this->fullBCount === null) { $this->fullBCount = array(); - $bLength = count ($b); + $bLength = count ($this->b); for($i = 0; $i < $bLength; ++$i) { $char = $this->b[$i]; $this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1; @@ -729,7 +729,7 @@ private function tupleSort($a, $b) } } - if(count($a) == $count($b)) { + if(count($a) == count($b)) { return 0; } else if(count($a) < count($b)) { From 0ef9663ae7a306a1f0d24bcf9f0feb55787c4b31 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 11:24:54 +0100 Subject: [PATCH 05/52] some fixing --- lib/Diff.php | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Diff.php b/lib/Diff.php index d1eb9da0..aee26648 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -8,10 +8,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -19,20 +19,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package Diff @@ -67,13 +67,16 @@ class Diff 'context' => 3, 'ignoreNewLines' => false, 'ignoreWhitespace' => false, - 'ignoreCase' => false + 'ignoreCase' => false, + 'title_a'=>'Old Version', + 'title_b'=>'New Version', + 'labelDifferences'=>'Differences' ); /** * @var array Array of the options that have been applied for generating the diff. */ - private $options = array(); + public $options = array(); /** * The constructor. From f63f3d6391073a10f7b4abcf1b1739c692e0d467 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 12:23:12 +0100 Subject: [PATCH 06/52] example files Chinese --- example/a.txt | 14 +------------- example/b.txt | 15 +-------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/example/a.txt b/example/a.txt index 6f3897b2..6535c3e2 100644 --- a/example/a.txt +++ b/example/a.txt @@ -1,13 +1 @@ - - - - Hello World! - - -

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.

- -

A heading we'll be removing

- -

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.

- - \ No newline at end of file +构建具有中国特色的医学人才培养体系 \ No newline at end of file diff --git a/example/b.txt b/example/b.txt index 5918964d..a3dc7426 100644 --- a/example/b.txt +++ b/example/b.txt @@ -1,14 +1 @@ - - - - Goodbye Cruel World! - - -

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.

- - -

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.

- -

Just a small amount of new text...

- - \ No newline at end of file +构建具有中国的医学人才培养体系 \ No newline at end of file From bf2398cf5df67145aac15dbe1e460a2cd6d71f84 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 12:28:27 +0100 Subject: [PATCH 07/52] clean ' --- lib/Diff/SequenceMatcher.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 07f05e0b..7118f9f0 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -533,18 +533,18 @@ public function getGroupedOpcodes($context=3) ); } - if($opCodes[0][0] == 'equal') { - $opCodes[0] = array( - $opCodes[0][0], - max($opCodes[0][1], $opCodes[0][2] - $context), - $opCodes[0][2], - max($opCodes[0][3], $opCodes[0][4] - $context), - $opCodes[0][4] + if($opCodes['0']['0'] == 'equal') { + $opCodes['0'] = array( + $opCodes['0']['0'], + max($opCodes['0']['1'], $opCodes['0']['2'] - $context), + $opCodes['0']['2'], + max($opCodes['0']['3'], $opCodes['0']['4'] - $context), + $opCodes['0']['4'] ); } $lastItem = count($opCodes) - 1; - if($opCodes[$lastItem][0] == 'equal') { + if($opCodes[$lastItem]['0'] == 'equal') { list($tag, $i1, $i2, $j1, $j2) = $opCodes[$lastItem]; $opCodes[$lastItem] = array( $tag, @@ -582,7 +582,7 @@ public function getGroupedOpcodes($context=3) ); } - if(!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) { + if(!empty($group) && !(count($group) == 1 && $group['0']['0'] == 'equal')) { $groups[] = $group; } From c81931f07ac0e9025e5a298b055cf63b5936e81a Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 12:31:35 +0100 Subject: [PATCH 08/52] Fix ' --- lib/Diff/Renderer/Text/Context.php | 44 +++++++++++++++--------------- lib/Diff/Renderer/Text/Unified.php | 38 +++++++++++++------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/Diff/Renderer/Text/Context.php b/lib/Diff/Renderer/Text/Context.php index 1200b01c..2b3cca8d 100644 --- a/lib/Diff/Renderer/Text/Context.php +++ b/lib/Diff/Renderer/Text/Context.php @@ -5,10 +5,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -16,20 +16,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package DiffLib @@ -66,13 +66,13 @@ public function render() foreach($opCodes as $group) { $diff .= "***************\n"; $lastItem = count($group)-1; - $i1 = $group[0][1]; - $i2 = $group[$lastItem][2]; - $j1 = $group[0][3]; - $j2 = $group[$lastItem][4]; + $i1 = $group['0']['1']; + $i2 = $group[$lastItem]['2']; + $j1 = $group['0']['3']; + $j2 = $group[$lastItem]['4']; if($i2 - $i1 >= 2) { - $diff .= '*** '.($group[0][1] + 1).','.$i2." ****\n"; + $diff .= '*** '.($group['0']['1'] + 1).','.$i2." ****\n"; } else { $diff .= '*** '.$i2." ****\n"; @@ -87,7 +87,7 @@ public function render() $hasVisible = false; foreach($group as $code) { - if($code[0] == 'replace' || $code[0] == 'delete') { + if($code['0'] == 'replace' || $code['0'] == 'delete') { $hasVisible = true; break; } @@ -105,7 +105,7 @@ public function render() $hasVisible = false; foreach($group as $code) { - if($code[0] == 'replace' || $code[0] == 'insert') { + if($code['0'] == 'replace' || $code['0'] == 'insert') { $hasVisible = true; break; } diff --git a/lib/Diff/Renderer/Text/Unified.php b/lib/Diff/Renderer/Text/Unified.php index e94d951d..105bb23b 100644 --- a/lib/Diff/Renderer/Text/Unified.php +++ b/lib/Diff/Renderer/Text/Unified.php @@ -5,10 +5,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -16,20 +16,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package DiffLib @@ -55,10 +55,10 @@ public function render() $opCodes = $this->diff->getGroupedOpcodes(); foreach($opCodes as $group) { $lastItem = count($group)-1; - $i1 = $group[0][1]; - $i2 = $group[$lastItem][2]; - $j1 = $group[0][3]; - $j2 = $group[$lastItem][4]; + $i1 = $group['0']['1']; + $i2 = $group[$lastItem]['2']; + $j1 = $group['0']['3']; + $j2 = $group[$lastItem]['4']; if($i1 == 0 && $i2 == 0) { $i1 = -1; From 1139134c375d51c1f546623ca68c14deb7692072 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 12:40:06 +0100 Subject: [PATCH 09/52] UTF-8 --- example/a.txt | 16 +++++++++++++++- example/b.txt | 17 ++++++++++++++++- example/example.php | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/example/a.txt b/example/a.txt index 6535c3e2..943abbdf 100644 --- a/example/a.txt +++ b/example/a.txt @@ -1 +1,15 @@ -构建具有中国特色的医学人才培养体系 \ No newline at end of file + + + + Hello World! + + +

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.

+ +

A heading we'll be removing

+
+构建具有中国特色的医学人才培养体系
+
+

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.

+ + diff --git a/example/b.txt b/example/b.txt index a3dc7426..53266346 100644 --- a/example/b.txt +++ b/example/b.txt @@ -1 +1,16 @@ -构建具有中国的医学人才培养体系 \ No newline at end of file + + + + + Goodbye Cruel World! + + +

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.

+
+构建具有中国的医学人才培养体系
+
+

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.

+ +

Just a small amount of new text...

+ + \ No newline at end of file diff --git a/example/example.php b/example/example.php index 234bc2c8..a5d068e1 100644 --- a/example/example.php +++ b/example/example.php @@ -1,9 +1,9 @@ - - PHP LibDiff - Examples + PHP LibDiff - Examples 构建具有中国特色的医学人才培养体系 From 09d0c4c7e47e2afaf32f1f022190ac2dbbd38d08 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 14:33:44 +0100 Subject: [PATCH 10/52] added ' --- lib/Diff/SequenceMatcher.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 07f05e0b..9d1c9985 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -533,13 +533,13 @@ public function getGroupedOpcodes($context=3) ); } - if($opCodes[0][0] == 'equal') { - $opCodes[0] = array( - $opCodes[0][0], - max($opCodes[0][1], $opCodes[0][2] - $context), - $opCodes[0][2], - max($opCodes[0][3], $opCodes[0][4] - $context), - $opCodes[0][4] + if($opCodes['0']['0'] == 'equal') { + $opCodes['0'] = array( + $opCodes['0']['0'], + max($opCodes['0']['1'], $opCodes['0']['2'] - $context), + $opCodes['0']['2'], + max($opCodes['0']['3'], $opCodes['0']['4'] - $context), + $opCodes['0']['4'] ); } @@ -582,7 +582,7 @@ public function getGroupedOpcodes($context=3) ); } - if(!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) { + if(!empty($group) && !(count($group) == 1 && $group['0']['0'] == 'equal')) { $groups[] = $group; } From cb6e774475ff287d57349921bbf7d3fa62018e0b Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 14:36:38 +0100 Subject: [PATCH 11/52] only the chinese line --- example/b.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/example/b.txt b/example/b.txt index 53266346..84e8baa4 100644 --- a/example/b.txt +++ b/example/b.txt @@ -6,6 +6,7 @@

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.

+
 构建具有中国的医学人才培养体系
 
From 19a92b36ebe787cafa70027053de68707c0636bb Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 4 Feb 2015 14:55:46 +0100 Subject: [PATCH 12/52] Replace the substring with multi byte --- lib/Diff/Renderer/Html/Array.php | 52 +++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index 6df708d0..f02bbbaa 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -51,6 +51,50 @@ class Diff_Renderer_Html_Array extends Diff_Renderer_Abstract 'tabSize' => 4 ); + /** + * From https://gist.github.com/stemar/8287074 + * @param mixed $string The input string. + * @param mixed $replacement The replacement string. + * @param mixed $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. + * @param mixed $length If given and is positive, it represents the length of the portion of string which is to be replaced. If it is negative, it represents the number of characters from the end of string at which to stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the end of string. Of course, if length is zero then this function will have the effect of inserting replacement into string at the given start offset. + * @return string The result string is returned. If string is an array then array is returned. + */ + public function mb_substr_replace($string, $replacement, $start, $length=NULL) { + if (is_array($string)) { + $num = count($string); + // $replacement + $replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement); + // $start + if (is_array($start)) { + $start = array_slice($start, 0, $num); + foreach ($start as $key => $value) + $start[$key] = is_int($value) ? $value : 0; + } + else { + $start = array_pad(array($start), $num, $start); + } + // $length + if (!isset($length)) { + $length = array_fill(0, $num, 0); + } + elseif (is_array($length)) { + $length = array_slice($length, 0, $num); + foreach ($length as $key => $value) + $length[$key] = isset($value) ? (is_int($value) ? $value : $num) : 0; + } + else { + $length = array_pad(array($length), $num, $length); + } + // Recursive call + return array_map(__FUNCTION__, $string, $replacement, $start, $length); + } + preg_match_all('/./us', (string)$string, $smatches); + preg_match_all('/./us', (string)$replacement, $rmatches); + if ($length === NULL) $length = mb_strlen($string); + array_splice($smatches[0], $start, $length, $rmatches[0]); + return join($smatches[0]); + } + /** * Render and return an array structure suitable for generating HTML * based differences. Generally called by subclasses that generate a @@ -83,11 +127,11 @@ public function render() list($start, $end) = $this->getChangeExtent($fromLine, $toLine); if($start != 0 || $end != 0) { $last = $end + strlen($fromLine); - $fromLine = substr_replace($fromLine, "\0", $start, 0); - $fromLine = substr_replace($fromLine, "\1", $last + 1, 0); + $fromLine = $this->mb_substr_replace($fromLine, "\0", $start, 0); + $fromLine = $this->mb_substr_replace($fromLine, "\1", $last + 1, 0); $last = $end + strlen($toLine); - $toLine = substr_replace($toLine, "\0", $start, 0); - $toLine = substr_replace($toLine, "\1", $last + 1, 0); + $toLine = $this->mb_substr_replace($toLine, "\0", $start, 0); + $toLine = $this->mb_substr_replace($toLine, "\1", $last + 1, 0); $a[$i1 + $i] = $fromLine; $b[$j1 + $i] = $toLine; } From c9c4c99625be29b0b9084f667d96d6fafac43d80 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 6 Feb 2015 17:54:39 +0100 Subject: [PATCH 13/52] updated to my repo --- composer.json | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index a6b043bb..d0a4e819 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,26 @@ { - "name": "chrisboulton/php-diff", + "name": "JBlond/php-diff", + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/JBlond/php-diff" + } + ], "type": "library", - "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", - "authors": [ - { - "name": "Chris Boulton", - "email": "@chrisboulton" - } - ], + "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", + "keywords": [ + "php", + "diff" + ], + "authors": [ + { + "name": "Chris Boulton", + "email": "@chrisboulton" + }, + { + "name": "Mario / JBlond" + } + ], "autoload": { "psr-0": { "Diff": "lib/" From 4804307c279152013e35b7b95fa8eae0f98ff299 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 6 Feb 2015 18:03:06 +0100 Subject: [PATCH 14/52]   is not HTML5 valid --- lib/Diff/Renderer/Html/Array.php | 2 +- lib/Diff/Renderer/Html/Inline.php | 14 +++--- lib/Diff/Renderer/Html/SideBySide.php | 62 +++++++++++++-------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index f02bbbaa..abc57380 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -241,7 +241,7 @@ function fixSpaces($matches) $div = floor($count / 2); $mod = $count % 2; - return str_repeat('  ', $div).str_repeat(' ', $mod); + return str_repeat('  ', $div).str_repeat(' ', $mod); } /** diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index eae3ae5b..9c1303a7 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -74,7 +74,7 @@ public function render() $html .= ''; $html .= '…'; $html .= '…'; - $html .= ' '; + $html .= ' '; $html .= ''; } @@ -97,9 +97,9 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; - $html .= ' '; + $html .= ' '; $html .= ''.$toLine.''; - $html .= ''.$line.' '; + $html .= ''.$line.' '; $html .= ''; } } @@ -109,8 +109,8 @@ public function render() $fromLine = $change['base']['offset'] + $no + 1; $html .= ''; $html .= ''.$fromLine.''; - $html .= ' '; - $html .= ''.$line.' '; + $html .= ' '; + $html .= ''.$line.' '; $html .= ''; } } @@ -120,7 +120,7 @@ public function render() $fromLine = $change['base']['offset'] + $no + 1; $html .= ''; $html .= ''.$fromLine.''; - $html .= ' '; + $html .= ' '; $html .= ''.$line.''; $html .= ''; } @@ -128,7 +128,7 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; - $html .= ' '; + $html .= ' '; $html .= ''.$toLine.''; $html .= ''.$line.''; $html .= ''; diff --git a/lib/Diff/Renderer/Html/SideBySide.php b/lib/Diff/Renderer/Html/SideBySide.php index 307af1c3..30d33081 100644 --- a/lib/Diff/Renderer/Html/SideBySide.php +++ b/lib/Diff/Renderer/Html/SideBySide.php @@ -5,10 +5,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -16,20 +16,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package DiffLib @@ -69,8 +69,8 @@ public function render() foreach($changes as $i => $blocks) { if($i > 0) { $html .= ''; - $html .= '… '; - $html .= '… '; + $html .= '… '; + $html .= '… '; $html .= ''; } @@ -83,9 +83,9 @@ public function render() $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; $html .= ''.$fromLine.''; - $html .= ''.$line.' '; + $html .= ''.$line.' '; $html .= ''.$toLine.''; - $html .= ''.$line.' '; + $html .= ''.$line.' '; $html .= ''; } } @@ -94,10 +94,10 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; - $html .= ' '; - $html .= ' '; + $html .= ' '; + $html .= ' '; $html .= ''.$toLine.''; - $html .= ''.$line.' '; + $html .= ''.$line.' '; $html .= ''; } } @@ -107,9 +107,9 @@ public function render() $fromLine = $change['base']['offset'] + $no + 1; $html .= ''; $html .= ''.$fromLine.''; - $html .= ''.$line.' '; - $html .= ' '; - $html .= ' '; + $html .= ''.$line.' '; + $html .= ' '; + $html .= ' '; $html .= ''; } } @@ -120,10 +120,10 @@ public function render() $fromLine = $change['base']['offset'] + $no + 1; $html .= ''; $html .= ''.$fromLine.''; - $html .= ''.$line.' '; + $html .= ''.$line.' '; if(!isset($change['changed']['lines'][$no])) { - $toLine = ' '; - $changedLine = ' '; + $toLine = ' '; + $changedLine = ' '; } else { $toLine = $change['base']['offset'] + $no + 1; @@ -137,8 +137,8 @@ public function render() else { foreach($change['changed']['lines'] as $no => $changedLine) { if(!isset($change['base']['lines'][$no])) { - $fromLine = ' '; - $line = ' '; + $fromLine = ' '; + $line = ' '; } else { $fromLine = $change['base']['offset'] + $no + 1; @@ -146,7 +146,7 @@ public function render() } $html .= ''; $html .= ''.$fromLine.''; - $html .= ''.$line.' '; + $html .= ''.$line.' '; $toLine = $change['changed']['offset'] + $no + 1; $html .= ''.$toLine.''; $html .= ''.$changedLine.''; From 47cae23f3c628c694e446ad8d6227492a49795ff Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 6 Feb 2015 18:08:25 +0100 Subject: [PATCH 15/52] issue catch from https://github.com/one2/php-diff/commit/784ff858c3b1d46d98c42a43673c07674fc2cd5e --- lib/Diff/SequenceMatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 7118f9f0..a4dc01f0 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -285,7 +285,7 @@ public function findLongestMatch($alo, $ahi, $blo, $bhi) } while($bestI > $alo && $bestJ > $blo && $this->isBJunk($b[$bestJ - 1]) && - !$this->isLineDifferent($bestI - 1, $bestJ - 1)) { + !$this->linesAreDifferent($bestI - 1, $bestJ - 1)) { --$bestI; --$bestJ; ++$bestSize; From ded9951fde74e1967bcbfaeca383ea0e0cabdd98 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 6 Feb 2015 18:14:38 +0100 Subject: [PATCH 16/52] HTML5 --- example/example.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/example/example.php b/example/example.php index a5d068e1..e1aca9f6 100644 --- a/example/example.php +++ b/example/example.php @@ -1,9 +1,8 @@ - + - - PHP LibDiff - Examples 构建具有中国特色的医学人才培养体系 + + PHP LibDiff - Examples From 7cb8e630a635b6f9f829ed56a8a2bd7c9a4f877f Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 13 Feb 2015 10:50:27 +0100 Subject: [PATCH 17/52] created License --- LICENSE | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..01769ba8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 JBlond + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From 358d10cdbcdfb7bc365f8f33dac45fc128f19321 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:19:44 +0100 Subject: [PATCH 18/52] not a valid email --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index d0a4e819..a64e9186 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,6 @@ "authors": [ { "name": "Chris Boulton", - "email": "@chrisboulton" }, { "name": "Mario / JBlond" From 765045124f615b4f498aded75253f56578a20c6a Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:24:11 +0100 Subject: [PATCH 19/52] syntax error --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a64e9186..e1b5fc0a 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "authors": [ { - "name": "Chris Boulton", + "name": "Chris Boulton" }, { "name": "Mario / JBlond" From 3b5b3387c566a4b591328c968dbc06262cac8144 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:31:50 +0100 Subject: [PATCH 20/52] added License --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index e1b5fc0a..901cea52 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "JBlond/php-diff", + "license": "BSD License", "repositories": [ { "type": "vcs", From b433ddbc69533c620e24d0fb00e21e4976237eef Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:32:34 +0100 Subject: [PATCH 21/52] end with a new line --- lib/Diff/SequenceMatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index a4dc01f0..3e780845 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -739,4 +739,4 @@ private function tupleSort($a, $b) return 1; } } -} \ No newline at end of file +} From b660567fbfdd66a305222325c250c63e58da7ff3 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:34:33 +0100 Subject: [PATCH 22/52] end witha new line --- lib/Diff.php | 2 +- lib/Diff/Renderer/Abstract.php | 32 +++++++++++++-------------- lib/Diff/Renderer/Html/Array.php | 2 +- lib/Diff/Renderer/Html/Inline.php | 2 +- lib/Diff/Renderer/Html/SideBySide.php | 2 +- lib/Diff/Renderer/Text/Context.php | 2 +- lib/Diff/Renderer/Text/Unified.php | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Diff.php b/lib/Diff.php index aee26648..d4b98483 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -179,4 +179,4 @@ public function getGroupedOpcodes() $this->groupedCodes = $sequenceMatcher->getGroupedOpcodes($this->options['context']); return $this->groupedCodes; } -} \ No newline at end of file +} diff --git a/lib/Diff/Renderer/Abstract.php b/lib/Diff/Renderer/Abstract.php index f63c3e7f..828ccf74 100644 --- a/lib/Diff/Renderer/Abstract.php +++ b/lib/Diff/Renderer/Abstract.php @@ -5,10 +5,10 @@ * PHP version 5 * * Copyright (c) 2009 Chris Boulton - * + * * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without + * + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, @@ -16,20 +16,20 @@ * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - Neither the name of the Chris Boulton nor the names of its contributors - * may be used to endorse or promote products derived from this software + * - Neither the name of the Chris Boulton nor the names of its contributors + * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package DiffLib @@ -79,4 +79,4 @@ public function setOptions(array $options) { $this->options = array_merge($this->defaultOptions, $options); } -} \ No newline at end of file +} diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index abc57380..b219c746 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -265,4 +265,4 @@ private function htmlSafe($string) { return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8'); } -} \ No newline at end of file +} diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index 9c1303a7..1cb92f5b 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -140,4 +140,4 @@ public function render() $html .= ''; return $html; } -} \ No newline at end of file +} diff --git a/lib/Diff/Renderer/Html/SideBySide.php b/lib/Diff/Renderer/Html/SideBySide.php index 30d33081..6418b4b6 100644 --- a/lib/Diff/Renderer/Html/SideBySide.php +++ b/lib/Diff/Renderer/Html/SideBySide.php @@ -160,4 +160,4 @@ public function render() $html .= ''; return $html; } -} \ No newline at end of file +} diff --git a/lib/Diff/Renderer/Text/Context.php b/lib/Diff/Renderer/Text/Context.php index 2b3cca8d..1d1ab457 100644 --- a/lib/Diff/Renderer/Text/Context.php +++ b/lib/Diff/Renderer/Text/Context.php @@ -125,4 +125,4 @@ public function render() } return $diff; } -} \ No newline at end of file +} diff --git a/lib/Diff/Renderer/Text/Unified.php b/lib/Diff/Renderer/Text/Unified.php index 105bb23b..87cfa20a 100644 --- a/lib/Diff/Renderer/Text/Unified.php +++ b/lib/Diff/Renderer/Text/Unified.php @@ -84,4 +84,4 @@ public function render() } return $diff; } -} \ No newline at end of file +} From d1a5e189db02679bb927903799769b2a8aa25807 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:36:46 +0100 Subject: [PATCH 23/52] added widget --- README.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0110b5c5..b46c46eb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ PHP Diff Class -------------- +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/aa609edb-cdb1-45cf-ad51-afbdab48f6a1/mini.png)](https://insight.sensiolabs.com/projects/aa609edb-cdb1-45cf-ad51-afbdab48f6a1) + Introduction ------------ A comprehensive library for generating differences between @@ -37,8 +39,8 @@ License (BSD License) --------------------- Copyright (c) 2009 Chris Boulton All rights reserved. - -Redistribution and use in source and binary forms, with or without + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, @@ -46,20 +48,20 @@ modification, are permitted provided that the following conditions are met: - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - - Neither the name of the Chris Boulton nor the names of its contributors - may be used to endorse or promote products derived from this software + - Neither the name of the Chris Boulton nor the names of its contributors + may be used to endorse or promote products derived from this software without specific prior written permission. ``` -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` From d42578aec0883d609d61260a8d6249f8641ca8ce Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 23 Feb 2015 11:40:48 +0100 Subject: [PATCH 24/52] Update LICENSE file new line at the end --- .gitignore | 2 +- LICENSE | 40 ++++++++++++++++++++++++---------------- composer.json | 4 ++-- example/example.php | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 187adb24..40b7eda7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/nbproject/ \ No newline at end of file +/nbproject/ diff --git a/LICENSE b/LICENSE index 01769ba8..a6a32cb8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,19 +1,27 @@ -Copyright (c) 2015 JBlond +Copyright (c) 2009 Chris Boulton +All rights reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Neither the name of the Chris Boulton nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/composer.json b/composer.json index 901cea52..48fa793b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "JBlond/php-diff", - "license": "BSD License", + "license": "BSD-3-Clause", "repositories": [ { "type": "vcs", @@ -26,4 +26,4 @@ "Diff": "lib/" } } -} \ No newline at end of file +} diff --git a/example/example.php b/example/example.php index e1aca9f6..87495980 100644 --- a/example/example.php +++ b/example/example.php @@ -65,4 +65,4 @@ ?> - \ No newline at end of file + From f0aba03dc4b038e8d96c47e8009ab3c106ac5184 Mon Sep 17 00:00:00 2001 From: kriss0r Date: Fri, 24 Jul 2015 21:42:39 +0200 Subject: [PATCH 25/52] Fix tab expansion and deprecated preg_replace use on fixSpaces. --- lib/Diff/Renderer/Html/Array.php | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index b012fb6b..542b63d4 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -177,7 +177,8 @@ protected function formatLines($lines) $lines = array_map(array($this, 'ExpandTabs'), $lines); $lines = array_map(array($this, 'HtmlSafe'), $lines); foreach($lines as &$line) { - $line = preg_replace('# ( +)|^ #e', "\$this->fixSpaces('\\1')", $line); + $line = str_replace(' ', ' ', $line); +// $line = preg_replace_callback('# ( +)|^ #', array($this, 'fixSpaces'), $line); } return $lines; } @@ -188,16 +189,19 @@ protected function formatLines($lines) * @param string $spaces The string of spaces. * @return string The HTML representation of the string. */ - function fixSpaces($spaces='') + function fixSpaces($matches) { - $count = strlen($spaces); - if($count == 0) { - return ''; + $buffer = ''; + foreach($matches as $spaces){ + $count = strlen($spaces); + if($count == 0) { + continue; + } + $div = floor($count / 2); + $mod = $count % 2; + $buffer .= str_repeat('  ', $div).str_repeat(' ', $mod); } - - $div = floor($count / 2); - $mod = $count % 2; - return str_repeat('  ', $div).str_repeat(' ', $mod); + return $buffer; } /** @@ -208,7 +212,16 @@ function fixSpaces($spaces='') */ private function expandTabs($line) { - return str_replace("\t", str_repeat(' ', $this->options['tabSize']), $line); + $tabSize = $this->options['tabSize']; + while(($pos = strpos($line, "\t")) !== FALSE){ + $left = substr($line, 0, $pos); + $right = substr($line, $pos + 1); + $length = $tabSize - ($pos % $tabSize); + $spaces = str_repeat(' ', $length); + $line = $left.$spaces.$right; + } + return $line; +// return str_replace("\t", str_repeat(' ', $this->options['tabSize']), $line); } /** From 4ffd7517df86733bd9fd993c5d233c946951515c Mon Sep 17 00:00:00 2001 From: JBlond Date: Sat, 31 Oct 2015 20:37:36 +0100 Subject: [PATCH 26/52] unused function --- lib/Diff/SequenceMatcher.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 3e780845..493652f8 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -658,20 +658,6 @@ private function quickRatio() $this->calculateRatio($matches, count ($this->a) + count ($this->b)); } - /** - * Return an upper bound ratio really quickly for the similarity of the strings. - * This is quicker to compute than Ratio() and quickRatio(). - * - * @return float The calculated ratio. - */ - private function realquickRatio() - { - $aLength = count ($this->a); - $bLength = count ($this->b); - - return $this->calculateRatio(min($aLength, $bLength), $aLength + $bLength); - } - /** * Helper function for calculating the ratio to measure similarity for the strings. * The ratio is defined as being 2 * (number of matches / total length) From c8efb81594ffc11aab2bde943a3f04f5d398e7e3 Mon Sep 17 00:00:00 2001 From: JBlond Date: Sat, 31 Oct 2015 20:39:41 +0100 Subject: [PATCH 27/52] unused function --- lib/Diff/SequenceMatcher.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 493652f8..6d6eb5cd 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -595,8 +595,7 @@ public function getGroupedOpcodes($context=3) * * Out of all of the ratio calculation functions, this is the most * expensive to call if getMatchingBlocks or getOpCodes is yet to be - * called. The other calculation methods (quickRatio and realquickRatio) - * can be used to perform quicker calculations but may be less accurate. + * called. * * The ratio is calculated as (2 * number of matches) / total number of * elements in both sequences. From f1d7fdc8fbb6acb1b1de8135d00dca6fc94935ed Mon Sep 17 00:00:00 2001 From: JBlond Date: Sat, 31 Oct 2015 20:56:01 +0100 Subject: [PATCH 28/52] clean up --- composer.json | 2 +- lib/Diff.php | 1 + lib/Diff/Renderer/Html/Array.php | 1 + lib/Diff/SequenceMatcher.php | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 48fa793b..c72fcc6c 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ } ], "type": "library", - "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", + "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ "php", "diff" diff --git a/lib/Diff.php b/lib/Diff.php index d4b98483..e1d7fc46 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -83,6 +83,7 @@ class Diff * * @param array $a Array containing the lines of the first string to compare. * @param array $b Array containing the lines for the second string to compare. + * @param array $options Array for the options */ public function __construct($a, $b, $options=array()) { diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index ad9d0063..c6aff798 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -235,6 +235,7 @@ protected function formatLines($lines) function fixSpaces($matches) { $buffer = ''; + $count = 0; foreach($matches as $spaces){ $count = strlen($spaces); if($count == 0) { diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 6d6eb5cd..de151028 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -67,6 +67,8 @@ class Diff_SequenceMatcher */ private $b2j = array(); + private $juncDict = array(); + private $options = array(); private $defaultOptions = array( @@ -83,6 +85,7 @@ class Diff_SequenceMatcher * @param string|array $a A string or array containing the lines to compare against. * @param string|array $b A string or array containing the lines to compare. * @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters. + * @param array $options */ public function __construct($a, $b, $junkCallback=null, $options) { @@ -207,6 +210,7 @@ private function chainB() * Checks if a particular character is in the junk dictionary * for the list of junk characters. * + * @param string $b * @return boolean $b True if the character is considered junk. False if not. */ private function isBJunk($b) From b3b089c60ba5a34afd34f7e383cec5da228c2dcc Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 11 Nov 2015 17:19:57 +0100 Subject: [PATCH 29/52] This function has never been used --- lib/Diff/SequenceMatcher.php | 37 ------------------------------------ 1 file changed, 37 deletions(-) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index de151028..6fb0d0fa 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -624,43 +624,6 @@ private function ratioReduce($sum, $triple) return $sum + ($triple[count($triple) - 1]); } - /** - * Quickly return an upper bound ratio for the similarity of the strings. - * This is quicker to compute than Ratio(). - * - * @return float The calculated ratio. - */ - private function quickRatio() - { - if($this->fullBCount === null) { - $this->fullBCount = array(); - $bLength = count ($this->b); - for($i = 0; $i < $bLength; ++$i) { - $char = $this->b[$i]; - $this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1; - } - } - - $avail = array(); - $matches = 0; - $aLength = count ($this->a); - for($i = 0; $i < $aLength; ++$i) { - $char = $this->a[$i]; - if(isset($avail[$char])) { - $numb = $avail[$char]; - } - else { - $numb = $this->arrayGetDefault($this->fullBCount, $char, 0); - } - $avail[$char] = $numb - 1; - if($numb > 0) { - ++$matches; - } - } - - $this->calculateRatio($matches, count ($this->a) + count ($this->b)); - } - /** * Helper function for calculating the ratio to measure similarity for the strings. * The ratio is defined as being 2 * (number of matches / total length) From edc62b4fa64202cf9c6377aa0dc47fd6b28eb51c Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 11 Nov 2015 17:21:48 +0100 Subject: [PATCH 30/52] update phpdoc block --- lib/Diff.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Diff.php b/lib/Diff.php index e1d7fc46..bede3853 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -99,7 +99,8 @@ public function __construct($a, $b, $options=array()) /** * Render a diff using the supplied rendering class and return it. * - * @param object $renderer An instance of the rendering object to use for generating the diff. + * @param \Diff_Renderer_Abstract|object $renderer An instance of the rendering object to use for generating the diff. + * * @return mixed The generated diff. Exact return value depends on the rendered. */ public function render(Diff_Renderer_Abstract $renderer) From 5d8ade80291ad224b440ca56538c0a14d05cb0fe Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 11 Nov 2015 17:24:35 +0100 Subject: [PATCH 31/52] use index instead of an assumption of a constant --- lib/Diff/Renderer/Html/Array.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index c6aff798..cf5f9502 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -91,8 +91,8 @@ public function mb_substr_replace($string, $replacement, $start, $length=NULL) { preg_match_all('/./us', (string)$string, $smatches); preg_match_all('/./us', (string)$replacement, $rmatches); if ($length === NULL) $length = mb_strlen($string); - array_splice($smatches[0], $start, $length, $rmatches[0]); - return join($smatches[0]); + array_splice($smatches['0'], $start, $length, $rmatches[0]); + return join($smatches['0']); } /** From c19f1d61c683873825e6e86c11accf600a8dae4d Mon Sep 17 00:00:00 2001 From: JBlond Date: Thu, 12 Nov 2015 15:06:17 +0100 Subject: [PATCH 32/52] opCodes wasn't declared --- lib/Diff/SequenceMatcher.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 6fb0d0fa..3fad45e5 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -71,6 +71,8 @@ class Diff_SequenceMatcher private $options = array(); + private $opCodes; + private $defaultOptions = array( 'ignoreNewLines' => false, 'ignoreWhitespace' => false, From e0ff768afc30758cb17b544bbf6f930f14b58649 Mon Sep 17 00:00:00 2001 From: JBlond Date: Thu, 12 Nov 2015 15:07:28 +0100 Subject: [PATCH 33/52] matchingBlocks wasn't declared --- lib/Diff/SequenceMatcher.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 3fad45e5..a1aa0c2e 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -73,6 +73,8 @@ class Diff_SequenceMatcher private $opCodes; + private $matchingBlocks; + private $defaultOptions = array( 'ignoreNewLines' => false, 'ignoreWhitespace' => false, From f99d93b306f34d1e13c0320677ac16cb39b8c430 Mon Sep 17 00:00:00 2001 From: JBlond Date: Thu, 12 Nov 2015 15:08:35 +0100 Subject: [PATCH 34/52] fullBCount wasn't declared --- lib/Diff/SequenceMatcher.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index a1aa0c2e..5285ba07 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -75,6 +75,8 @@ class Diff_SequenceMatcher private $matchingBlocks; + private $fullBCount; + private $defaultOptions = array( 'ignoreNewLines' => false, 'ignoreWhitespace' => false, From 712f326bb758b46409de474a7b5a057697390cab Mon Sep 17 00:00:00 2001 From: Tiny-Box Date: Sun, 10 Jul 2016 02:28:01 +0800 Subject: [PATCH 35/52] add css to fix the bug, which white space in empty lines in not highlighted --- example/a.txt | 3 +++ example/b.txt | 3 +++ example/styles.css | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/example/a.txt b/example/a.txt index 943abbdf..ff9edbdb 100644 --- a/example/a.txt +++ b/example/a.txt @@ -9,6 +9,9 @@

A heading we'll be removing

 构建具有中国特色的医学人才培养体系
+aaa
+
+bbb
 

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.

diff --git a/example/b.txt b/example/b.txt index 84e8baa4..270ac04d 100644 --- a/example/b.txt +++ b/example/b.txt @@ -9,6 +9,9 @@
 构建具有中国的医学人才培养体系
+aaa
+
+bbb
 

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.

diff --git a/example/styles.css b/example/styles.css index 5454896f..e45b11a6 100644 --- a/example/styles.css +++ b/example/styles.css @@ -87,6 +87,11 @@ body { background: #e99; } +.Differences ins, .Differences del { + text-decoration: none; + white-space: pre-wrap; +} + pre { width: 100%; overflow: auto; From bf77529f51663e560eba13a9861d4df46a6284e7 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 11:28:36 +0800 Subject: [PATCH 36/52] =?UTF-8?q?=E5=BC=95=E5=85=A5private=E4=BB=93?= =?UTF-8?q?=E5=BA=93=EF=BC=8C=E6=94=B9=E5=8A=A8composer.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index c72fcc6c..abf8d8d5 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,6 @@ { - "name": "JBlond/php-diff", + "name": "phpDiff", "license": "BSD-3-Clause", - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/JBlond/php-diff" - } - ], "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ @@ -19,10 +13,13 @@ }, { "name": "Mario / JBlond" - } + }, + { + "name": "TinyBox" + } ], "autoload": { - "psr-0": { + "psr-4": { "Diff": "lib/" } } From 96e174f613095e4bcef65caa7e3fb5065c122e4e Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 11:54:15 +0800 Subject: [PATCH 37/52] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index abf8d8d5..a77e625b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "phpDiff", + "name": "php-diff", "license": "BSD-3-Clause", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", From 4f8e9699e90152671230e5b1d3da83a0afce5ea6 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 15:47:57 +0800 Subject: [PATCH 38/52] code format --- composer.json | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index a77e625b..29d53a1b 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,26 @@ { - "name": "php-diff", - "license": "BSD-3-Clause", - "type": "library", - "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", - "keywords": [ - "php", - "diff" - ], - "authors": [ - { - "name": "Chris Boulton" - }, - { - "name": "Mario / JBlond" - }, - { - "name": "TinyBox" - } - ], - "autoload": { - "psr-4": { - "Diff": "lib/" - } - } + "name": "php-diff", + "license": "BSD-3-Clause", + "type": "library", + "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", + "keywords": [ + "php", + "diff" + ], + "authors": [ + { + "name": "Chris Boulton" + }, + { + "name": "Mario / JBlond" + }, + { + "name": "TinyBox" + } + ], + "autoload": { + "psr-4": { + "Diff": "lib/" + } + } } From 6f17b4ace0f6399ea6ca32b6d4987fdf0e1bb359 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 15:50:43 +0800 Subject: [PATCH 39/52] modify name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 29d53a1b..ab2b1d73 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "php-diff", + "name": "tinybox/php-diff", "license": "BSD-3-Clause", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", From 03eb00c8b157dd4d682b6af190c8cac870a91d6b Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 16:14:35 +0800 Subject: [PATCH 40/52] add version num --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index ab2b1d73..7c26be62 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", + "version": "1.0.0", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ From 449eb52bd303fb2299fc94c1418febcd34b3a50a Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 16:37:45 +0800 Subject: [PATCH 41/52] add repository --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 7c26be62..9ef7e03a 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,9 @@ "php", "diff" ], + "repositories": [ + {"type": "composer", "url": "https://packagist.baixing.cn/repo/private/"} + ], "authors": [ { "name": "Chris Boulton" From b039ac7c3bf2b85f5d7ab2548f2bc48a2f622bca Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 17:36:10 +0800 Subject: [PATCH 42/52] add namespace --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9ef7e03a..c0b27cb0 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ], "autoload": { "psr-4": { - "Diff": "lib/" + "Diff/": "lib/" } } } From 46e12281f2d661ce40372ee8f20e379eba100d58 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 17:41:53 +0800 Subject: [PATCH 43/52] add version num --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c0b27cb0..67e191ef 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", - "version": "1.0.0", + "version": "1.0.1", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ From 25df69fb5df7c000ccd5f3385d5c7c2e84e3fdf8 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 17:46:17 +0800 Subject: [PATCH 44/52] modify namespace --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 67e191ef..b8fbfd96 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", - "version": "1.0.1", + "version": "1.0.2", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ @@ -24,7 +24,7 @@ ], "autoload": { "psr-4": { - "Diff/": "lib/" + "Diff\\": "lib/" } } } From 62a27eaca68d8a27b523e9bd1072d1d579d23ab8 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Mon, 11 Jul 2016 18:05:28 +0800 Subject: [PATCH 45/52] modify namespace --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b8fbfd96..ee1d2fe1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", - "version": "1.0.2", + "version": "1.1.0", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ @@ -24,7 +24,7 @@ ], "autoload": { "psr-4": { - "Diff\\": "lib/" + "tinybox\\Diff\\": "lib/" } } } From ca8b4c8195ebca03c363e838b5fdaa5fd6543d67 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Tue, 12 Jul 2016 11:03:46 +0800 Subject: [PATCH 46/52] modify autoload --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ee1d2fe1..64e5b46d 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ } ], "autoload": { - "psr-4": { - "tinybox\\Diff\\": "lib/" - } + "classmap": [ + "src/" + ] } } From 0d506c1cdaf3f7c5629d355b70a614b7384a77bd Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Tue, 12 Jul 2016 11:06:12 +0800 Subject: [PATCH 47/52] add version num --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 64e5b46d..726498b0 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", - "version": "1.1.0", + "version": "1.1.2", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ From 050582f88def2be11b94a5699377af667ae686f0 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Tue, 12 Jul 2016 11:08:48 +0800 Subject: [PATCH 48/52] lib address --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 726498b0..e498bd38 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ], "autoload": { "classmap": [ - "src/" + "lib/" ] } } From b4e5f16cf8a1f6b743643a2c16e30bd7e69a85d5 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Tue, 12 Jul 2016 11:15:15 +0800 Subject: [PATCH 49/52] up version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e498bd38..e5684f6b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", - "version": "1.1.2", + "version": "1.1.3", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ From a96c7e3075209d2279ade9de0db7db33219216b2 Mon Sep 17 00:00:00 2001 From: wangyanxiang Date: Tue, 12 Jul 2016 16:25:02 +0800 Subject: [PATCH 50/52] clear bom --- composer.json | 2 +- example/example.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e5684f6b..c4e88007 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "tinybox/php-diff", "license": "BSD-3-Clause", - "version": "1.1.3", + "version": "1.1.4", "type": "library", "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).", "keywords": [ diff --git a/example/example.php b/example/example.php index 87495980..0aa58bcb 100644 --- a/example/example.php +++ b/example/example.php @@ -1,4 +1,4 @@ - + From 8aa38aac0ad1c86d9dabf3f962d29041ef21ba6f Mon Sep 17 00:00:00 2001 From: Tiny-Box Date: Fri, 26 Aug 2016 10:25:08 +0800 Subject: [PATCH 51/52] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=8F=AA=E6=98=BE=E7=A4=BAdiff=E7=9A=84render?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E4=BF=AE=E6=94=B9=E4=BA=86composer.?= =?UTF-8?q?json=E4=B8=8E=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + composer.json | 6 +-- example/example.php | 9 ++++ example/styles.css | 25 ++++++---- lib/Diff/Renderer/Html/Simple.php | 76 +++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 lib/Diff/Renderer/Html/Simple.php diff --git a/.gitignore b/.gitignore index 40b7eda7..c341f5f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /nbproject/ + +.DS_Store \ No newline at end of file diff --git a/composer.json b/composer.json index c4e88007..f823e420 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ } ], "autoload": { - "classmap": [ - "lib/" - ] + "psr-4": { + "Tinybox\\Diff\\": "lib/" + } } } diff --git a/example/example.php b/example/example.php index 0aa58bcb..61a3acd0 100644 --- a/example/example.php +++ b/example/example.php @@ -44,6 +44,15 @@ $renderer = new Diff_Renderer_Html_Inline; echo $diff->render($renderer); + ?> +

Simple Diff

+ render($renderer); + ?>

Unified Diff

';
+		$html .= '';
+		$html .= '';
+		foreach($changes as $i => $blocks) {
+			// If this is a separate block, we're condensing code so output ...,
+			// indicating a significant portion of the code has been collapsed as
+			// it is the same
+			if($i > 0) {
+				$html .= '';
+				$html .= '…';
+				$html .= '…';
+				$html .= ' ';
+				$html .= '';
+			}
+
+			foreach($blocks as $change) {
+				$html .= '';
+				// Added lines only on the right side
+				if($change['tag'] == 'insert') {
+					foreach($change['changed']['lines'] as $no => $line) {
+						$html .= '';
+						$html .= ''.$line.' ';
+						$html .= '';
+					}
+				}
+				// Show deleted lines only on the left side
+				else if($change['tag'] == 'delete') {
+					foreach($change['base']['lines'] as $no => $line) {
+						$html .= '';
+						$html .= ''.$line.' ';
+						$html .= '';
+					}
+				}
+				// Show modified lines on both sides
+				else if($change['tag'] == 'replace') {
+					foreach($change['base']['lines'] as $no => $line) {
+						$html .= '';
+						$html .= ''.$line.'';
+						$html .= '';
+					}
+
+					foreach($change['changed']['lines'] as $no => $line) {
+						$html .= '';
+						$html .= ''.$line.'';
+						$html .= '';
+					}
+				}
+				$html .= '';
+			}
+		}
+		$html .= '';
+		return $html;
+	}
+}

From f3a8e820b09456426133c9c714f3e0091e4e246d Mon Sep 17 00:00:00 2001
From: Tiny-Box 
Date: Fri, 26 Aug 2016 10:30:40 +0800
Subject: [PATCH 52/52] =?UTF-8?q?=E5=9C=A8composer.json=E4=B8=AD=E6=94=BE?=
 =?UTF-8?q?=E5=BC=83version=EF=BC=8C=E5=8F=AA=E4=BE=9D=E9=9D=A0tag?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 composer.json | 1 -
 1 file changed, 1 deletion(-)

diff --git a/composer.json b/composer.json
index f823e420..37714347 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,6 @@
 {
   "name": "tinybox/php-diff",
   "license": "BSD-3-Clause",
-  "version": "1.1.4",
   "type": "library",
   "description": "A comprehensive library for generating differences between two hash able objects (strings or arrays).",
   "keywords": [