From 3449c56dceb573279cc799d62458bc67b64ec24c Mon Sep 17 00:00:00 2001 From: jdlx Date: Wed, 6 Jul 2011 22:36:45 +0200 Subject: [PATCH 1/8] fix typo --- 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 e819e810..6a5914cf 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -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 1ef549f1ab72cb2483b20c178dffc114471757f1 Mon Sep 17 00:00:00 2001 From: jdlx Date: Wed, 6 Jul 2011 22:59:24 +0200 Subject: [PATCH 2/8] added option: custom strings for "Old/New Version" --- example/example.php | 2 ++ lib/Diff.php | 6 ++++-- lib/Diff/Renderer/Html/SideBySide.php | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/example/example.php b/example/example.php index 234bc2c8..d9eedbb7 100644 --- a/example/example.php +++ b/example/example.php @@ -22,6 +22,8 @@ $options = array( //'ignoreWhitespace' => true, //'ignoreCase' => true, + //'title_a' => 'some other title than "Old Version"', + //'title_b' => 'some other title than "New Version"', ); // Initialize the diff class diff --git a/lib/Diff.php b/lib/Diff.php index 35305c03..b628e36c 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -67,13 +67,15 @@ class Diff 'context' => 3, 'ignoreNewLines' => false, 'ignoreWhitespace' => false, - 'ignoreCase' => false + 'ignoreCase' => false, + 'title_a'=>'Old Version', + 'title_b'=>'New Version' ); /** * @var array Array of the options that have been applied for generating the diff. */ - private $options = array(); + public $options = array(); /** * The constructor. diff --git a/lib/Diff/Renderer/Html/SideBySide.php b/lib/Diff/Renderer/Html/SideBySide.php index 307af1c3..f5e1a579 100644 --- a/lib/Diff/Renderer/Html/SideBySide.php +++ b/lib/Diff/Renderer/Html/SideBySide.php @@ -53,6 +53,8 @@ class Diff_Renderer_Html_SideBySide extends Diff_Renderer_Html_Array public function render() { $changes = parent::render(); + $title_a = $this->diff->options['title_a']; + $title_b = $this->diff->options['title_b']; $html = ''; if(empty($changes)) { @@ -62,8 +64,8 @@ public function render() $html .= ''; $html .= ''; $html .= ''; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; $html .= ''; $html .= ''; foreach($changes as $i => $blocks) { From 27ad2477f6e01aae1dc886d7b65e666c279f5477 Mon Sep 17 00:00:00 2001 From: jdlx Date: Thu, 7 Jul 2011 00:50:41 +0200 Subject: [PATCH 3/8] fix non-working context option --- lib/Diff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Diff.php b/lib/Diff.php index b628e36c..2368e8bf 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -172,7 +172,7 @@ public function getGroupedOpcodes() require_once dirname(__FILE__).'/Diff/SequenceMatcher.php'; $sequenceMatcher = new Diff_SequenceMatcher($this->a, $this->b, null, $this->options); - $this->groupedCodes = $sequenceMatcher->getGroupedOpcodes(); + $this->groupedCodes = $sequenceMatcher->getGroupedOpcodes($this->options['context']); return $this->groupedCodes; } } \ No newline at end of file From dadc728ac9795b532f71ff7caf58040aec972899 Mon Sep 17 00:00:00 2001 From: MartyIX Date: Fri, 29 Jul 2011 22:00:49 +0200 Subject: [PATCH 4/8] Fix: The library was updated in order to process UTF8 characters (hopefully). --- example/a.txt | 2 ++ example/b.txt | 2 ++ lib/Diff/SequenceMatcher.php | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/example/a.txt b/example/a.txt index 6f3897b2..72561fac 100644 --- a/example/a.txt +++ b/example/a.txt @@ -4,6 +4,8 @@ Hello World! +

Příliš žluťoučký kůň úpěl ďábelské ódy

+

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

diff --git a/example/b.txt b/example/b.txt index 5918964d..72114fc0 100644 --- a/example/b.txt +++ b/example/b.txt @@ -4,6 +4,8 @@ Goodbye Cruel World! +

Příliš žluťoučký kůň úpěl ďábelské ódy -- previous sentence is a pangram for Czech language (see http://en.wikipedia.org/wiki/Pangram)

+

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/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index 6a5914cf..399b22d5 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -119,7 +119,7 @@ public function setSequences($a, $b) public function setSeq1($a) { if(!is_array($a)) { - $a = str_split($a); + $a = preg_split('//u', $a, -1, PREG_SPLIT_NO_EMPTY); } if($a == $this->a) { return; @@ -139,7 +139,7 @@ public function setSeq1($a) public function setSeq2($b) { if(!is_array($b)) { - $b = str_split($b); + $b = preg_split('//u', $b, -1, PREG_SPLIT_NO_EMPTY); } if($b == $this->b) { return; From d19fc0cab5bab9177d1ad30cd0105d3c538bf50d Mon Sep 17 00:00:00 2001 From: jorrel Date: Mon, 19 Mar 2012 14:34:33 +0800 Subject: [PATCH 5/8] Line numbers for 'New' now appears under the appropriate column --- lib/Diff/Renderer/Html/Inline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index 60e8005a..70cc9041 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -128,8 +128,8 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= '
'; - $html .= ''; $html .= ''; + $html .= ''; $html .= ''; $html .= ''; } From 4cdeb36b6c4cafa73bcf4226e2efc88202f57555 Mon Sep 17 00:00:00 2001 From: jorrel Date: Mon, 19 Mar 2012 14:38:24 +0800 Subject: [PATCH 6/8] Added support for custom titles for inline renderer --- lib/Diff/Renderer/Html/Inline.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index 70cc9041..b50e945f 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -53,6 +53,9 @@ class Diff_Renderer_Html_Inline extends Diff_Renderer_Html_Array public function render() { $changes = parent::render(); + $title_a = $this->diff->options['title_a']; + $title_b = $this->diff->options['title_b']; + $html = ''; if(empty($changes)) { return $html; @@ -61,8 +64,8 @@ public function render() $html .= '
Old VersionNew Version'.$title_a.''.$title_b.'
'.$toLine.' '.$toLine.''.$line.'
'; $html .= ''; $html .= ''; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; $html .= ''; $html .= ''; $html .= ''; From 483adf913deaed1bbb522bf9881318bd4a56828e Mon Sep 17 00:00:00 2001 From: Deds Castillo Date: Sat, 27 Oct 2012 17:49:33 +0800 Subject: [PATCH 7/8] corrects the column placement of line numbers for right side replacements --- lib/Diff/Renderer/Html/Inline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index 60e8005a..70cc9041 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -128,8 +128,8 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; - $html .= ''; $html .= ''; + $html .= ''; $html .= ''; $html .= ''; } From 240fd879cb7eb7644d8e88406e0da1d796b5e281 Mon Sep 17 00:00:00 2001 From: Deds Castillo Date: Sat, 27 Oct 2012 19:32:14 +0800 Subject: [PATCH 8/8] add option to provide label for "Differences" in inline render --- lib/Diff.php | 3 ++- lib/Diff/Renderer/Html/Inline.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Diff.php b/lib/Diff.php index 2368e8bf..62805dc7 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -69,7 +69,8 @@ class Diff 'ignoreWhitespace' => false, 'ignoreCase' => false, 'title_a'=>'Old Version', - 'title_b'=>'New Version' + 'title_b'=>'New Version', + 'labelDifferences'=>'Differences' ); /** diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index b50e945f..28a1fe64 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -55,6 +55,7 @@ public function render() $changes = parent::render(); $title_a = $this->diff->options['title_a']; $title_b = $this->diff->options['title_b']; + $label_differences = $this->diff->options['labelDifferences']; $html = ''; if(empty($changes)) { @@ -66,7 +67,7 @@ public function render() $html .= ''; $html .= ''; $html .= ''; - $html .= ''; + $html .= ''; $html .= ''; $html .= ''; foreach($changes as $i => $blocks) {
OldNew'.$title_a.''.$title_b.'Differences
'.$toLine.' '.$toLine.''.$line.'
'.$title_a.''.$title_b.'Differences'.$label_differences.'