Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 991
Zeile 41... Zeile 41...
41
 
41
 
Zeile 42... Zeile 42...
42
    private ?int $nextNonSpaceCache = null;
42
    private ?int $nextNonSpaceCache = null;
Zeile -... Zeile 43...
-
 
43
 
-
 
44
    private bool $partiallyConsumedTab = false;
-
 
45
 
43
 
46
    /**
-
 
47
     * @var int|false
44
    private bool $partiallyConsumedTab = false;
48
     *
Zeile 45... Zeile 49...
45
 
49
     * @psalm-readonly
46
    /** @psalm-readonly */
50
     */
Zeile 47... Zeile 51...
47
    private bool $lineContainsTabs;
51
    private $lastTabPosition;
Zeile 59... Zeile 63...
59
    {
63
    {
60
        if (! \mb_check_encoding($line, 'UTF-8')) {
64
        if (! \mb_check_encoding($line, 'UTF-8')) {
61
            throw new UnexpectedEncodingException('Unexpected encoding - UTF-8 or ASCII was expected');
65
            throw new UnexpectedEncodingException('Unexpected encoding - UTF-8 or ASCII was expected');
62
        }
66
        }
Zeile 63... Zeile 67...
63
 
67
 
64
        $this->line             = $line;
68
        $this->line            = $line;
65
        $this->length           = \mb_strlen($line, 'UTF-8') ?: 0;
69
        $this->length          = \mb_strlen($line, 'UTF-8') ?: 0;
66
        $this->isMultibyte      = $this->length !== \strlen($line);
70
        $this->isMultibyte     = $this->length !== \strlen($line);
67
        $this->lineContainsTabs = \strpos($line, "\t") !== false;
71
        $this->lastTabPosition = $this->isMultibyte ? \mb_strrpos($line, "\t", 0, 'UTF-8') : \strrpos($line, "\t");
Zeile 68... Zeile 72...
68
    }
72
    }
69
 
73
 
70
    /**
74
    /**
Zeile 74... Zeile 78...
74
    {
78
    {
75
        if ($this->nextNonSpaceCache !== null) {
79
        if ($this->nextNonSpaceCache !== null) {
76
            return $this->nextNonSpaceCache;
80
            return $this->nextNonSpaceCache;
77
        }
81
        }
Zeile 78... Zeile 82...
78
 
82
 
79
        $c    = null;
83
        if ($this->currentPosition >= $this->length) {
-
 
84
            return $this->length;
-
 
85
        }
80
        $i    = $this->currentPosition;
86
 
Zeile 81... Zeile 87...
81
        $cols = $this->column;
87
        $cols = $this->column;
-
 
88
 
-
 
89
        for ($i = $this->currentPosition; $i < $this->length; $i++) {
-
 
90
            // This if-else was copied out of getCharacter() for performance reasons
-
 
91
            if ($this->isMultibyte) {
-
 
92
                $c = $this->charCache[$i] ??= \mb_substr($this->line, $i, 1, 'UTF-8');
-
 
93
            } else {
-
 
94
                $c = $this->line[$i];
82
 
95
            }
83
        while (($c = $this->getCharacter($i)) !== null) {
-
 
84
            if ($c === ' ') {
96
 
85
                $i++;
97
            if ($c === ' ') {
86
                $cols++;
-
 
87
            } elseif ($c === "\t") {
98
                $cols++;
88
                $i++;
99
            } elseif ($c === "\t") {
89
                $cols += 4 - ($cols % 4);
100
                $cols += 4 - ($cols % 4);
90
            } else {
101
            } else {
91
                break;
102
                break;
Zeile 92... Zeile -...
92
            }
-
 
93
        }
103
            }
Zeile 94... Zeile 104...
94
 
104
        }
95
        $nextNonSpace = $c === null ? $this->length : $i;
105
 
Zeile 96... Zeile 106...
96
        $this->indent = $cols - $this->column;
106
        $this->indent = $cols - $this->column;
97
 
107
 
98
        return $this->nextNonSpaceCache = $nextNonSpace;
108
        return $this->nextNonSpaceCache = $i;
99
    }
109
    }
100
 
110
 
101
    /**
111
    /**
-
 
112
     * Returns the next character which isn't a space (or tab)
-
 
113
     */
-
 
114
    public function getNextNonSpaceCharacter(): ?string
-
 
115
    {
-
 
116
        $index = $this->getNextNonSpacePosition();
-
 
117
        if ($index >= $this->length) {
-
 
118
            return null;
-
 
119
        }
-
 
120
 
102
     * Returns the next character which isn't a space (or tab)
121
        if ($this->isMultibyte) {
Zeile 103... Zeile 122...
103
     */
122
            return $this->charCache[$index] ??= \mb_substr($this->line, $index, 1, 'UTF-8');
104
    public function getNextNonSpaceCharacter(): ?string
123
        }
105
    {
124
 
Zeile 194... Zeile 213...
194
     * @param int  $characters       Number of characters to advance by
213
     * @param int  $characters       Number of characters to advance by
195
     * @param bool $advanceByColumns Whether to advance by columns instead of spaces
214
     * @param bool $advanceByColumns Whether to advance by columns instead of spaces
196
     */
215
     */
197
    public function advanceBy(int $characters, bool $advanceByColumns = false): void
216
    public function advanceBy(int $characters, bool $advanceByColumns = false): void
198
    {
217
    {
199
        $this->previousPosition = $this->currentPosition;
218
        $this->previousPosition  = $this->currentPosition;
200
 
-
 
201
        $this->nextNonSpaceCache = null;
219
        $this->nextNonSpaceCache = null;
Zeile -... Zeile 220...
-
 
220
 
-
 
221
        if ($this->currentPosition >= $this->length || $characters === 0) {
-
 
222
            return;
-
 
223
        }
202
 
224
 
-
 
225
        // Optimization to avoid tab handling logic if we have no tabs
-
 
226
        if ($this->lastTabPosition === false || $this->currentPosition > $this->lastTabPosition) {
203
        // Optimization to avoid tab handling logic if we have no tabs
227
            $length                     = \min($characters, $this->length - $this->currentPosition);
204
        if (! $this->lineContainsTabs) {
228
            $this->partiallyConsumedTab = false;
-
 
229
            $this->currentPosition     += $length;
Zeile 205... Zeile 230...
205
            $this->advanceWithoutTabCharacters($characters);
230
            $this->column              += $length;
206
 
231
 
Zeile 207... Zeile 232...
207
            return;
232
            return;
208
        }
233
        }
209
 
234
 
Zeile 210... Zeile -...
210
        $nextFewChars = $this->isMultibyte ?
-
 
211
            \mb_substr($this->line, $this->currentPosition, $characters, 'UTF-8') :
-
 
212
            \substr($this->line, $this->currentPosition, $characters);
-
 
213
 
-
 
214
        if ($nextFewChars === '') {
-
 
215
            return;
-
 
216
        }
-
 
217
 
-
 
218
        // Optimization to avoid tab handling logic if we have no tabs
-
 
219
        if (\strpos($nextFewChars, "\t") === false) {
-
 
220
            $this->advanceWithoutTabCharacters($characters);
-
 
221
 
235
        $nextFewChars = $this->isMultibyte ?
222
            return;
236
            \mb_substr($this->line, $this->currentPosition, $characters, 'UTF-8') :
223
        }
237
            \substr($this->line, $this->currentPosition, $characters);
224
 
238
 
225
        if ($characters === 1) {
239
        if ($characters === 1) {
Zeile 257... Zeile 271...
257
                break;
271
                break;
258
            }
272
            }
259
        }
273
        }
260
    }
274
    }
Zeile 261... Zeile -...
261
 
-
 
262
    private function advanceWithoutTabCharacters(int $characters): void
-
 
263
    {
-
 
264
        $length                     = \min($characters, $this->length - $this->currentPosition);
-
 
265
        $this->partiallyConsumedTab = false;
-
 
266
        $this->currentPosition     += $length;
-
 
267
        $this->column              += $length;
-
 
268
    }
-
 
269
 
275
 
270
    /**
276
    /**
271
     * Advances the cursor by a single space or tab, if present
277
     * Advances the cursor by a single space or tab, if present
272
     */
278
     */
273
    public function advanceBySpaceOrTab(): bool
279
    public function advanceBySpaceOrTab(): bool
Zeile 456... Zeile 462...
456
        return $this->currentPosition;
462
        return $this->currentPosition;
457
    }
463
    }
Zeile 458... Zeile 464...
458
 
464
 
459
    public function getPreviousText(): string
465
    public function getPreviousText(): string
-
 
466
    {
460
    {
467
        if ($this->isMultibyte) {
-
 
468
            return \mb_substr($this->line, $this->previousPosition, $this->currentPosition - $this->previousPosition, 'UTF-8');
-
 
469
        }
-
 
470
 
461
        return \mb_substr($this->line, $this->previousPosition, $this->currentPosition - $this->previousPosition, 'UTF-8');
471
        return \substr($this->line, $this->previousPosition, $this->currentPosition - $this->previousPosition);
Zeile 462... Zeile 472...
462
    }
472
    }
463
 
473
 
464
    public function getSubstring(int $start, ?int $length = null): string
474
    public function getSubstring(int $start, ?int $length = null): string