in src/utils/PhutilEditDistanceMatrix.php [230:329]
public function getEditString() {
$this->requireSequences();
$x = $this->x;
$y = $this->y;
if (!$x && !$y) {
return $this->padEditString('');
}
if (!$x) {
return $this->padEditString(str_repeat('i', count($y)));
}
if (!$y) {
return $this->padEditString(str_repeat('d', count($x)));
}
if ($x === $y) {
return $this->padEditString(str_repeat('s', count($x)));
}
$max = $this->getMaximumLength();
if (count($x) > $max || count($y) > $max) {
$this->reachedMaximumLength = true;
return $this->padEditString(
str_repeat('d', count($x)).
str_repeat('i', count($y)));
}
$matrix = $this->getTypeMatrix();
$xx = count($x);
$yy = count($y);
$transposes = array();
$str = '';
while (true) {
$type = $matrix[$xx][$yy];
if (is_array($type)) {
$chr = 't';
$transposes[$type[0]][$type[1]] = true;
$type = $type[2];
} else {
$chr = $type;
}
if (isset($transposes[$xx][$yy])) {
$chr = 't';
}
if ($type == 's' || $type == 'x') {
$xx -= 1;
$yy -= 1;
} else if ($type == 'i') {
$yy -= 1;
} else if ($type == 'd') {
$xx -= 1;
} else {
throw new Exception(pht("Unknown type '%s' in type matrix.", $type));
}
$str .= $chr;
if ($xx <= 0 && $yy <= 0) {
break;
}
}
$str = strrev($str);
// For full smoothing, we pad the edit string before smoothing it, so
// ranges of similar characters at the beginning or end of the string can
// also be smoothed.
// For internal smoothing, we only smooth ranges within the change itself.
$smoothing = $this->getApplySmoothing();
switch ($smoothing) {
case self::SMOOTHING_FULL:
$str = $this->padEditString($str);
$str = $this->applySmoothing($str, true);
break;
case self::SMOOTHING_INTERNAL:
$str = $this->applySmoothing($str, false);
$str = $this->padEditString($str);
break;
case self::SMOOTHING_NONE:
$str = $this->padEditString($str);
break;
default:
throw new Exception(
pht(
'Unknown smoothing type "%s".',
$smoothing));
}
return $str;
}