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/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..62805dc7 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -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. @@ -170,7 +173,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 diff --git a/lib/Diff/Renderer/Html/Inline.php b/lib/Diff/Renderer/Html/Inline.php index 60e8005a..28a1fe64 100644 --- a/lib/Diff/Renderer/Html/Inline.php +++ b/lib/Diff/Renderer/Html/Inline.php @@ -53,6 +53,10 @@ 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']; + $label_differences = $this->diff->options['labelDifferences']; + $html = ''; if(empty($changes)) { return $html; @@ -61,9 +65,9 @@ public function render() $html .= ''; $html .= ''; $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; $html .= ''; $html .= ''; foreach($changes as $i => $blocks) { @@ -128,8 +132,8 @@ public function render() foreach($change['changed']['lines'] as $no => $line) { $toLine = $change['changed']['offset'] + $no + 1; $html .= ''; - $html .= ''; $html .= ''; + $html .= ''; $html .= ''; $html .= ''; } 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 .= '
OldNewDifferences'.$title_a.''.$title_b.''.$label_differences.'
'.$toLine.' '.$toLine.''.$line.'
'; $html .= ''; $html .= ''; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; $html .= ''; $html .= ''; foreach($changes as $i => $blocks) { diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index e819e810..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; @@ -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)) {
Old VersionNew Version'.$title_a.''.$title_b.'