PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / sebastian / diff / src / Parser.php
kubio / vendor / sebastian / diff / src Last commit date
Exception 1 year ago Output 1 year ago Chunk.php 1 year ago Diff.php 1 year ago Differ.php 1 year ago Line.php 1 year ago LongestCommonSubsequenceCalculator.php 1 year ago MemoryEfficientLongestCommonSubsequenceCalculator.php 1 year ago Parser.php 1 year ago TimeEfficientLongestCommonSubsequenceCalculator.php 1 year ago
Parser.php
111 lines
1 <?php declare(strict_types=1);
2 /*
3 * This file is part of sebastian/diff.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 namespace SebastianBergmann\Diff;
11
12 use function array_pop;
13 use function count;
14 use function max;
15 use function preg_match;
16 use function preg_split;
17
18 /**
19 * Unified diff parser.
20 */
21 final class Parser
22 {
23 /**
24 * @return Diff[]
25 */
26 public function parse(string $string): array
27 {
28 $lines = preg_split('(\r\n|\r|\n)', $string);
29
30 if (!empty($lines) && $lines[count($lines) - 1] === '') {
31 array_pop($lines);
32 }
33
34 $lineCount = count($lines);
35 $diffs = [];
36 $diff = null;
37 $collected = [];
38
39 for ($i = 0; $i < $lineCount; ++$i) {
40 if (preg_match('#^---\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i], $fromMatch) &&
41 preg_match('#^\\+\\+\\+\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i + 1], $toMatch)) {
42 if ($diff !== null) {
43 $this->parseFileDiff($diff, $collected);
44
45 $diffs[] = $diff;
46 $collected = [];
47 }
48
49 $diff = new Diff($fromMatch['file'], $toMatch['file']);
50
51 ++$i;
52 } else {
53 if (preg_match('/^(?:diff --git |index [\da-f\.]+|[+-]{3} [ab])/', $lines[$i])) {
54 continue;
55 }
56
57 $collected[] = $lines[$i];
58 }
59 }
60
61 if ($diff !== null && count($collected)) {
62 $this->parseFileDiff($diff, $collected);
63
64 $diffs[] = $diff;
65 }
66
67 return $diffs;
68 }
69
70 private function parseFileDiff(Diff $diff, array $lines): void
71 {
72 $chunks = [];
73 $chunk = null;
74 $diffLines = [];
75
76 foreach ($lines as $line) {
77 if (preg_match('/^@@\s+-(?P<start>\d+)(?:,\s*(?P<startrange>\d+))?\s+\+(?P<end>\d+)(?:,\s*(?P<endrange>\d+))?\s+@@/', $line, $match)) {
78 $chunk = new Chunk(
79 (int) $match['start'],
80 isset($match['startrange']) ? max(1, (int) $match['startrange']) : 1,
81 (int) $match['end'],
82 isset($match['endrange']) ? max(1, (int) $match['endrange']) : 1
83 );
84
85 $chunks[] = $chunk;
86 $diffLines = [];
87
88 continue;
89 }
90
91 if (preg_match('/^(?P<type>[+ -])?(?P<line>.*)/', $line, $match)) {
92 $type = Line::UNCHANGED;
93
94 if ($match['type'] === '+') {
95 $type = Line::ADDED;
96 } elseif ($match['type'] === '-') {
97 $type = Line::REMOVED;
98 }
99
100 $diffLines[] = new Line($type, $match['line']);
101
102 if (null !== $chunk) {
103 $chunk->setLines($diffLines);
104 }
105 }
106 }
107
108 $diff->setChunks($chunks);
109 }
110 }
111