1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Parser; |
15
|
|
|
|
16
|
|
|
class StringIterator extends \ArrayIterator |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* StringIterator constructor. |
20
|
|
|
*/ |
21
|
44 |
|
public function __construct(string $string = '') |
22
|
|
|
{ |
23
|
44 |
|
parent::__construct(str_split($string)); |
24
|
44 |
|
} |
25
|
|
|
|
26
|
44 |
|
/** |
27
|
|
|
* Test if current character is equal to a value, or (if $value is an array) is one of the values in the array. |
28
|
44 |
|
* |
29
|
|
|
* @param string|array $value test if current character is equal to, or is in, $value |
30
|
|
|
* |
31
|
44 |
|
* @return bool true if current character is, or is one of, the values |
32
|
|
|
*/ |
33
|
44 |
|
public function is($value): bool |
34
|
|
|
{ |
35
|
|
|
if (is_array($value)) { |
36
|
5 |
|
return in_array($this->current(), $value); |
37
|
|
|
} |
38
|
5 |
|
|
39
|
5 |
|
return (string) $value === $this->current(); |
40
|
5 |
|
} |
41
|
5 |
|
|
42
|
|
|
/** |
43
|
|
|
* Test if current character is not equal to a value, or (if $value is an array) is not any of the values in the array. |
44
|
5 |
|
* |
45
|
|
|
* @param string|array $value test if current character is not equal to, or is not any of, $value |
46
|
|
|
* |
47
|
|
|
* @return bool true if current character is not, or is not one of, the values |
48
|
|
|
*/ |
49
|
|
|
public function isNot($value): bool |
50
|
15 |
|
{ |
51
|
|
|
return !$this->is($value); |
52
|
15 |
|
} |
53
|
|
|
|
54
|
|
|
public function getRemainingAsString(): string |
55
|
|
|
{ |
56
|
|
|
$string = ''; |
57
|
|
|
while ($this->valid()) { |
58
|
|
|
$string .= $this->current(); |
59
|
|
|
$this->next(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $string; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function __toString() |
69
|
|
|
{ |
70
|
|
|
return implode('', $this->getArrayCopy()); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|