Skip to content

5.5 and cleanup #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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
*/
public function __construct($a, $b, $options=array())
{
Expand All @@ -92,7 +93,7 @@ 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 $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)
Expand Down
7 changes: 4 additions & 3 deletions lib/Diff/Renderer/Html/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,20 @@ 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('# ( +)|^ #', __CLASS__."::fixSpaces", $line);
}
return $lines;
}

/**
* Replace a string containing spaces with a HTML representation using  .
*
* @param string $spaces The string of spaces.
* @param string $matches Regex matches array.
* @return string The HTML representation of the string.
*/
function fixSpaces($spaces='')
public static function fixSpaces($matches)
{
$spaces = isset($matches[1]) ? $matches[1] : '';
$count = strlen($spaces);
if($count == 0) {
return '';
Expand Down
14 changes: 10 additions & 4 deletions lib/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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)
{
Expand All @@ -93,6 +94,11 @@ public function __construct($a, $b, $junkCallback=null, $options)
$this->setSequences($a, $b);
}

/**
* Set new options
*
* @param array $options
*/
public function setOptions($options)
{
$this->options = array_merge($this->defaultOptions, $options);
Expand Down Expand Up @@ -206,8 +212,8 @@ private function chainB()
/**
* Checks if a particular character is in the junk dictionary
* for the list of junk characters.
*
* @return boolean $b True if the character is considered junk. False if not.
* @param $b
* @return boolean True if the character is considered junk. False if not.
*/
private function isBJunk($b)
{
Expand Down Expand Up @@ -631,7 +637,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;
Expand Down Expand Up @@ -729,7 +735,7 @@ private function tupleSort($a, $b)
}
}

if(count($a) == $count($b)) {
if(count($a) == count($b)) {
return 0;
}
else if(count($a) < count($b)) {
Expand Down