You are here

public function Parser::parse in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/yaml/Parser.php \Symfony\Component\Yaml\Parser::parse()
  2. 8.0 vendor/sebastian/diff/src/Parser.php \SebastianBergmann\Diff\Parser::parse()
  3. 8.0 vendor/symfony/css-selector/Parser/Parser.php \Symfony\Component\CssSelector\Parser\Parser::parse()
  4. 8.0 vendor/egulias/email-validator/src/Egulias/EmailValidator/Parser/Parser.php \Egulias\EmailValidator\Parser\Parser::parse()
Same name and namespace in other branches
  1. 8 vendor/sebastian/diff/src/Parser.php \SebastianBergmann\Diff\Parser::parse()

Parameters

string $string:

Return value

Diff[]

File

vendor/sebastian/diff/src/Parser.php, line 29

Class

Parser
Unified diff parser.

Namespace

SebastianBergmann\Diff

Code

public function parse($string) {
  $lines = preg_split('(\\r\\n|\\r|\\n)', $string);
  $lineCount = count($lines);
  $diffs = array();
  $diff = null;
  $collected = array();
  for ($i = 0; $i < $lineCount; ++$i) {
    if (preg_match('(^---\\s+(?P<file>\\S+))', $lines[$i], $fromMatch) && preg_match('(^\\+\\+\\+\\s+(?P<file>\\S+))', $lines[$i + 1], $toMatch)) {
      if ($diff !== null) {
        $this
          ->parseFileDiff($diff, $collected);
        $diffs[] = $diff;
        $collected = array();
      }
      $diff = new Diff($fromMatch['file'], $toMatch['file']);
      ++$i;
    }
    else {
      if (preg_match('/^(?:diff --git |index [\\da-f\\.]+|[+-]{3} [ab])/', $lines[$i])) {
        continue;
      }
      $collected[] = $lines[$i];
    }
  }
  if (count($collected) && $diff !== null) {
    $this
      ->parseFileDiff($diff, $collected);
    $diffs[] = $diff;
  }
  return $diffs;
}