Skip to content

Commit d7ed17e

Browse files
committed
modified Merge branch 'master' of https://github.com/kriss0r/php-diff
2 parents d42578a + f0aba03 commit d7ed17e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/Diff/Renderer/Html/Array.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,15 @@ protected function formatLines($lines)
234234
*/
235235
function fixSpaces($matches)
236236
{
237-
$count = strlen($matches['0']);
238-
if($count == 0) {
239-
return '';
237+
$buffer = '';
238+
foreach($matches as $spaces){
239+
$count = strlen($spaces);
240+
if($count == 0) {
241+
continue;
242+
}
243+
$div = floor($count / 2);
244+
$mod = $count % 2;
245+
$buffer .= str_repeat('  ', $div).str_repeat(' ', $mod);
240246
}
241247

242248
$div = floor($count / 2);
@@ -252,7 +258,15 @@ function fixSpaces($matches)
252258
*/
253259
private function expandTabs($line)
254260
{
255-
return str_replace("\t", str_repeat(' ', $this->options['tabSize']), $line);
261+
$tabSize = $this->options['tabSize'];
262+
while(($pos = strpos($line, "\t")) !== FALSE){
263+
$left = substr($line, 0, $pos);
264+
$right = substr($line, $pos + 1);
265+
$length = $tabSize - ($pos % $tabSize);
266+
$spaces = str_repeat(' ', $length);
267+
$line = $left.$spaces.$right;
268+
}
269+
return $line;
256270
}
257271

258272
/**

0 commit comments

Comments
 (0)