Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/css-selector/Parser/Reader.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 | |
12 namespace 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 */ | |
24 class Reader | |
25 { | |
26 /** | |
27 * @var string | |
28 */ | |
29 private $source; | |
30 | |
31 /** | |
32 * @var int | |
33 */ | |
34 private $length; | |
35 | |
36 /** | |
37 * @var int | |
38 */ | |
39 private $position = 0; | |
40 | |
41 /** | |
42 * @param string $source | |
43 */ | |
44 public function __construct($source) | |
45 { | |
46 $this->source = $source; | |
47 $this->length = strlen($source); | |
48 } | |
49 | |
50 /** | |
51 * @return bool | |
52 */ | |
53 public function isEOF() | |
54 { | |
55 return $this->position >= $this->length; | |
56 } | |
57 | |
58 /** | |
59 * @return int | |
60 */ | |
61 public function getPosition() | |
62 { | |
63 return $this->position; | |
64 } | |
65 | |
66 /** | |
67 * @return int | |
68 */ | |
69 public function getRemainingLength() | |
70 { | |
71 return $this->length - $this->position; | |
72 } | |
73 | |
74 /** | |
75 * @param int $length | |
76 * @param int $offset | |
77 * | |
78 * @return string | |
79 */ | |
80 public function getSubstring($length, $offset = 0) | |
81 { | |
82 return substr($this->source, $this->position + $offset, $length); | |
83 } | |
84 | |
85 /** | |
86 * @param string $string | |
87 * | |
88 * @return int | |
89 */ | |
90 public function getOffset($string) | |
91 { | |
92 $position = strpos($this->source, $string, $this->position); | |
93 | |
94 return false === $position ? false : $position - $this->position; | |
95 } | |
96 | |
97 /** | |
98 * @param string $pattern | |
99 * | |
100 * @return array|false | |
101 */ | |
102 public function findPattern($pattern) | |
103 { | |
104 $source = substr($this->source, $this->position); | |
105 | |
106 if (preg_match($pattern, $source, $matches)) { | |
107 return $matches; | |
108 } | |
109 | |
110 return false; | |
111 } | |
112 | |
113 /** | |
114 * @param int $length | |
115 */ | |
116 public function moveForward($length) | |
117 { | |
118 $this->position += $length; | |
119 } | |
120 | |
121 public function moveToEnd() | |
122 { | |
123 $this->position = $this->length; | |
124 } | |
125 } |