本文整理汇总了PHP中Diff::setChunks方法的典型用法代码示例。如果您正苦于以下问题:PHP Diff::setChunks方法的具体用法?PHP Diff::setChunks怎么用?PHP Diff::setChunks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Diff
的用法示例。
在下文中一共展示了Diff::setChunks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFileDiff
/**
* @param Diff $diff
* @param array $lines
*/
private function parseFileDiff(Diff $diff, array $lines)
{
$chunks = array();
foreach ($lines as $line) {
if (preg_match('/^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@/', $line, $match)) {
$chunk = new Chunk($match['start'], isset($match['startrange']) ? max(1, $match['startrange']) : 1, $match['end'], isset($match['endrange']) ? max(1, $match['endrange']) : 1);
$chunks[] = $chunk;
$diffLines = array();
continue;
}
if (preg_match('/^(?P<type>[+ -])?(?P<line>.*)/', $line, $match)) {
$type = Line::UNCHANGED;
if ($match['type'] == '+') {
$type = Line::ADDED;
} elseif ($match['type'] == '-') {
$type = Line::REMOVED;
}
$diffLines[] = new Line($type, $match['line']);
if (isset($chunk)) {
$chunk->setLines($diffLines);
}
}
}
$diff->setChunks($chunks);
}
示例2: parseFileDiff
/**
* @param Diff $diff
* @param array $lines
*/
private function parseFileDiff(Diff $diff, array $lines)
{
$chunks = array();
while (count($lines)) {
while (!preg_match('(^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@)', $last = array_shift($lines), $match)) {
if ($last === null) {
break 2;
}
}
$chunk = new Chunk($match['start'], isset($match['startrange']) ? max(1, $match['startrange']) : 1, $match['end'], isset($match['endrange']) ? max(1, $match['endrange']) : 1);
$diffLines = array();
$last = null;
while (count($lines) && (preg_match('(^(?P<type>[+ -])?(?P<line>.*))', $last = array_shift($lines), $match) || strpos($last, '\\ No newline at end of file') === 0)) {
if (count($match)) {
$type = Line::UNCHANGED;
if ($match['type'] == '+') {
$type = Line::ADDED;
} elseif ($match['type'] == '-') {
$type = Line::REMOVED;
}
$diffLines[] = new Line($type, $match['line']);
}
}
$chunk->setLines($diffLines);
$chunks[] = $chunk;
if ($last !== null) {
array_unshift($lines, $last);
}
}
$diff->setChunks($chunks);
}