Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Parser.php

function Parser::parse

Same name in this branch
  1. 11.1.x vendor/sebastian/cli-parser/src/Parser.php \SebastianBergmann\CliParser\Parser::parse()
  2. 11.1.x vendor/egulias/email-validator/src/Parser.php \Egulias\EmailValidator\Parser::parse()
  3. 11.1.x vendor/nikic/php-parser/lib/PhpParser/Parser.php \PhpParser\Parser::parse()
  4. 11.1.x vendor/twig/twig/src/Parser.php \Twig\Parser::parse()
  5. 11.1.x vendor/symfony/css-selector/Parser/Parser.php \Symfony\Component\CssSelector\Parser\Parser::parse()
  6. 11.1.x vendor/symfony/yaml/Parser.php \Symfony\Component\Yaml\Parser::parse()
  7. 11.1.x vendor/mck89/peast/lib/Peast/Selector/Parser.php \Peast\Selector\Parser::parse()
  8. 11.1.x vendor/mck89/peast/lib/Peast/Syntax/Parser.php \Peast\Syntax\Parser::parse()

Return value

Diff[]

File

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

Class

Parser
Unified diff parser.

Namespace

SebastianBergmann\Diff

Code

public function parse(string $string) : array {
    $lines = preg_split('(\\r\\n|\\r|\\n)', $string);
    if (!empty($lines) && $lines[count($lines) - 1] === '') {
        array_pop($lines);
    }
    $lineCount = count($lines);
    $diffs = [];
    $diff = null;
    $collected = [];
    for ($i = 0; $i < $lineCount; $i++) {
        if (preg_match('#^---\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i], $fromMatch) && preg_match('#^\\+\\+\\+\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i + 1], $toMatch)) {
            if ($diff !== null) {
                $this->parseFileDiff($diff, $collected);
                $diffs[] = $diff;
                $collected = [];
            }
            assert(!empty($fromMatch['file']));
            assert(!empty($toMatch['file']));
            $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 ($diff !== null && count($collected)) {
        $this->parseFileDiff($diff, $collected);
        $diffs[] = $diff;
    }
    return $diffs;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal