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

Breadcrumb

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

function Parser::parseFileDiff

1 call to Parser::parseFileDiff()
Parser::parse in vendor/sebastian/diff/src/Parser.php

File

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

Class

Parser
Unified diff parser.

Namespace

SebastianBergmann\Diff

Code

private function parseFileDiff(Diff $diff, array $lines) : void {
    $chunks = [];
    $chunk = null;
    $diffLines = [];
    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, PREG_UNMATCHED_AS_NULL)) {
            $chunk = new Chunk((int) $match['start'], isset($match['startrange']) ? max(0, (int) $match['startrange']) : 1, (int) $match['end'], isset($match['endrange']) ? max(0, (int) $match['endrange']) : 1);
            $chunks[] = $chunk;
            $diffLines = [];
            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']);
            $chunk?->setLines($diffLines);
        }
    }
    $diff->setChunks($chunks);
}

API Navigation

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