Back to Patcher class

Method findHunk

protected static bool
findHunk
(mixed &$lines, mixed &$srcLine, mixed &$srcSize, mixed &$dstLine, mixed &$dstSize)
Find the next hunk of difference
Parameters
  • array $lines The udiff array of lines
  • string $srcLine The beginning of the patch for the source file
  • string $srcSize The size of the patch for the source file
  • string $dstLine The beginning of the patch for the destination file
  • string $dstSize The size of the patch for the destination file
Returns
  • bool TRUE in case of success, false in case of failure
Since
  • 3.0.0
-
  • \RuntimeException
Class: Patcher
Project: Joomla

Method findHunk - Source code

/**
 * Find the next hunk of difference
 *
 * The internal array pointer of $lines is on the next line after the finding
 *
 * @param   array   $lines    The udiff array of lines
 * @param   string  $srcLine  The beginning of the patch for the source file
 * @param   string  $srcSize  The size of the patch for the source file
 * @param   string  $dstLine  The beginning of the patch for the destination file
 * @param   string  $dstSize  The size of the patch for the destination file
 *
 * @return  boolean  TRUE in case of success, false in case of failure
 *
 * @since   3.0.0
 * @throws  \RuntimeException
 */
protected static function findHunk(&$lines, &$srcLine, &$srcSize, &$dstLine, &$dstSize)
{
    $line = current($lines);
    if (preg_match(self::HUNK, $line, $m)) {
        $srcLine = (int) $m[1];
        $srcSize = 1;
        if ($m[3] !== '') {
            $srcSize = (int) $m[3];
        }
        $dstLine = (int) $m[4];
        $dstSize = 1;
        if ($m[6] !== '') {
            $dstSize = (int) $m[6];
        }
        if (next($lines) === false) {
            throw new \RuntimeException('Unexpected EOF');
        }
        return true;
    }
    return false;
}