1 | <?php |
||
10 | class Source |
||
11 | { |
||
12 | /** @var string $str given string to deserialize */ |
||
13 | private $str; |
||
14 | |||
15 | /** @var int $length given string length */ |
||
16 | private $length; |
||
17 | |||
18 | /** @var int $current current position of parser */ |
||
19 | private $current; |
||
20 | |||
21 | /** |
||
22 | * constructor |
||
23 | * |
||
24 | * @param string $str parser input |
||
25 | * @throws \InvalidArgumentException |
||
26 | */ |
||
27 | 45 | public function __construct($str) |
|
36 | |||
37 | /** |
||
38 | * throw error with currnt position |
||
39 | * |
||
40 | * @return void |
||
41 | * @throws UnserializeFailedException |
||
42 | */ |
||
43 | 1 | public function triggerError() |
|
48 | |||
49 | /** |
||
50 | * return current character |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | 43 | public function peek() |
|
58 | |||
59 | /** |
||
60 | * consume given string if it is as expected |
||
61 | * |
||
62 | * @param string $expected expected string |
||
63 | * @param integer $length length of $expected |
||
64 | * @return void |
||
65 | * @throws UnserializeFailedException |
||
66 | */ |
||
67 | 22 | public function consume($expected, $length) |
|
74 | |||
75 | /** |
||
76 | * read givin length substring |
||
77 | * |
||
78 | * @param integer $length length to read |
||
79 | * @return string |
||
80 | * @throws UnserializeFailedException |
||
81 | */ |
||
82 | 19 | public function read($length) |
|
94 | |||
95 | /** |
||
96 | * return matching string for given regexp |
||
97 | * |
||
98 | * @param string $regexp Regular Expression for expected substring |
||
99 | * @return string |
||
100 | */ |
||
101 | 43 | public function match($regexp) |
|
111 | } |
||
112 |