add missing diff function

This commit is contained in:
Dennis Eichhorn 2019-02-14 18:53:24 +01:00
parent 5db3d81d25
commit 10fd3ee7da

View File

@ -427,7 +427,45 @@ final class StringUtils
}
}
public static function computeLCSDiff(string $from, string $to) : array
public static function diffline(string $line1, string $line2) : string
{
$diff = self::computeLCSDiff(str_split($line1), str_split($line2));
$diffval = $diff['values'];
$diffmask = $diff['mask'];
$n = count($diffval);
$pmc = 0;
$result = '';
for ($i = 0; $i < $n; $i++)
{
$mc = $diffmask[$i];
if ($mc != $pmc)
{
switch ($pmc)
{
case -1: $result .= '</del>'; break;
case 1: $result .= '</ins>'; break;
}
switch ($mc)
{
case -1: $result .= '<del>'; break;
case 1: $result .= '<ins>'; break;
}
}
$result .= $diffval[$i];
$pmc = $mc;
}
switch ($pmc)
{
case -1: $result .= '</del>'; break;
case 1: $result .= '</ins>'; break;
}
return $result;
}
private static function computeLCSDiff(string $from, string $to) : array
{
$diffValues = [];
$diffMask = [];