friendship ended with social-app. php is my new best friend
1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\CssSelector\Parser; 13 14/** 15 * CSS selector reader. 16 * 17 * This component is a port of the Python cssselect library, 18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. 19 * 20 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> 21 * 22 * @internal 23 */ 24class Reader 25{ 26 private int $length; 27 private int $position = 0; 28 29 public function __construct( 30 private string $source, 31 ) { 32 $this->length = \strlen($source); 33 } 34 35 public function isEOF(): bool 36 { 37 return $this->position >= $this->length; 38 } 39 40 public function getPosition(): int 41 { 42 return $this->position; 43 } 44 45 public function getRemainingLength(): int 46 { 47 return $this->length - $this->position; 48 } 49 50 public function getSubstring(int $length, int $offset = 0): string 51 { 52 return substr($this->source, $this->position + $offset, $length); 53 } 54 55 public function getOffset(string $string): int|false 56 { 57 $position = strpos($this->source, $string, $this->position); 58 59 return false === $position ? false : $position - $this->position; 60 } 61 62 public function findPattern(string $pattern): array|false 63 { 64 $source = substr($this->source, $this->position); 65 66 if (preg_match($pattern, $source, $matches)) { 67 return $matches; 68 } 69 70 return false; 71 } 72 73 public function moveForward(int $length): void 74 { 75 $this->position += $length; 76 } 77 78 public function moveToEnd(): void 79 { 80 $this->position = $this->length; 81 } 82}