当前位置: 首页>>代码示例>>PHP>>正文


PHP Diff::setChunks方法代码示例

本文整理汇总了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);
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:29,代码来源:Parser.php

示例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);
 }
开发者ID:HarveyCheng,项目名称:myblog,代码行数:35,代码来源:Parser.php


注:本文中的Diff::setChunks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。