PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / string / CodePointString.php
independent-analytics / vendor / symfony / string Last commit date
Exception 2 years ago Inflector 2 years ago Resources 2 years ago Slugger 2 years ago AbstractString.php 2 years ago AbstractUnicodeString.php 2 years ago ByteString.php 2 years ago CodePointString.php 2 years ago LazyString.php 2 years ago UnicodeString.php 2 years ago
CodePointString.php
216 lines
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 namespace IAWP_SCOPED\Symfony\Component\String;
12
13 use IAWP_SCOPED\Symfony\Component\String\Exception\ExceptionInterface;
14 use IAWP_SCOPED\Symfony\Component\String\Exception\InvalidArgumentException;
15 /**
16 * Represents a string of Unicode code points encoded as UTF-8.
17 *
18 * @author Nicolas Grekas <p@tchwork.com>
19 * @author Hugo Hamon <hugohamon@neuf.fr>
20 *
21 * @throws ExceptionInterface
22 * @internal
23 */
24 class CodePointString extends AbstractUnicodeString
25 {
26 public function __construct(string $string = '')
27 {
28 if ('' !== $string && !\preg_match('//u', $string)) {
29 throw new InvalidArgumentException('Invalid UTF-8 string.');
30 }
31 $this->string = $string;
32 }
33 public function append(string ...$suffix) : AbstractString
34 {
35 $str = clone $this;
36 $str->string .= 1 >= \count($suffix) ? $suffix[0] ?? '' : \implode('', $suffix);
37 if (!\preg_match('//u', $str->string)) {
38 throw new InvalidArgumentException('Invalid UTF-8 string.');
39 }
40 return $str;
41 }
42 public function chunk(int $length = 1) : array
43 {
44 if (1 > $length) {
45 throw new InvalidArgumentException('The chunk length must be greater than zero.');
46 }
47 if ('' === $this->string) {
48 return [];
49 }
50 $rx = '/(';
51 while (65535 < $length) {
52 $rx .= '.{65535}';
53 $length -= 65535;
54 }
55 $rx .= '.{' . $length . '})/us';
56 $str = clone $this;
57 $chunks = [];
58 foreach (\preg_split($rx, $this->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY) as $chunk) {
59 $str->string = $chunk;
60 $chunks[] = clone $str;
61 }
62 return $chunks;
63 }
64 public function codePointsAt(int $offset) : array
65 {
66 $str = $offset ? $this->slice($offset, 1) : $this;
67 return '' === $str->string ? [] : [\mb_ord($str->string, 'UTF-8')];
68 }
69 public function endsWith($suffix) : bool
70 {
71 if ($suffix instanceof AbstractString) {
72 $suffix = $suffix->string;
73 } elseif (\is_array($suffix) || $suffix instanceof \Traversable) {
74 return parent::endsWith($suffix);
75 } else {
76 $suffix = (string) $suffix;
77 }
78 if ('' === $suffix || !\preg_match('//u', $suffix)) {
79 return \false;
80 }
81 if ($this->ignoreCase) {
82 return \preg_match('{' . \preg_quote($suffix) . '$}iuD', $this->string);
83 }
84 return \strlen($this->string) >= \strlen($suffix) && 0 === \substr_compare($this->string, $suffix, -\strlen($suffix));
85 }
86 public function equalsTo($string) : bool
87 {
88 if ($string instanceof AbstractString) {
89 $string = $string->string;
90 } elseif (\is_array($string) || $string instanceof \Traversable) {
91 return parent::equalsTo($string);
92 } else {
93 $string = (string) $string;
94 }
95 if ('' !== $string && $this->ignoreCase) {
96 return \strlen($string) === \strlen($this->string) && 0 === \mb_stripos($this->string, $string, 0, 'UTF-8');
97 }
98 return $string === $this->string;
99 }
100 public function indexOf($needle, int $offset = 0) : ?int
101 {
102 if ($needle instanceof AbstractString) {
103 $needle = $needle->string;
104 } elseif (\is_array($needle) || $needle instanceof \Traversable) {
105 return parent::indexOf($needle, $offset);
106 } else {
107 $needle = (string) $needle;
108 }
109 if ('' === $needle) {
110 return null;
111 }
112 $i = $this->ignoreCase ? \mb_stripos($this->string, $needle, $offset, 'UTF-8') : \mb_strpos($this->string, $needle, $offset, 'UTF-8');
113 return \false === $i ? null : $i;
114 }
115 public function indexOfLast($needle, int $offset = 0) : ?int
116 {
117 if ($needle instanceof AbstractString) {
118 $needle = $needle->string;
119 } elseif (\is_array($needle) || $needle instanceof \Traversable) {
120 return parent::indexOfLast($needle, $offset);
121 } else {
122 $needle = (string) $needle;
123 }
124 if ('' === $needle) {
125 return null;
126 }
127 $i = $this->ignoreCase ? \mb_strripos($this->string, $needle, $offset, 'UTF-8') : \mb_strrpos($this->string, $needle, $offset, 'UTF-8');
128 return \false === $i ? null : $i;
129 }
130 public function length() : int
131 {
132 return \mb_strlen($this->string, 'UTF-8');
133 }
134 public function prepend(string ...$prefix) : AbstractString
135 {
136 $str = clone $this;
137 $str->string = (1 >= \count($prefix) ? $prefix[0] ?? '' : \implode('', $prefix)) . $this->string;
138 if (!\preg_match('//u', $str->string)) {
139 throw new InvalidArgumentException('Invalid UTF-8 string.');
140 }
141 return $str;
142 }
143 public function replace(string $from, string $to) : AbstractString
144 {
145 $str = clone $this;
146 if ('' === $from || !\preg_match('//u', $from)) {
147 return $str;
148 }
149 if ('' !== $to && !\preg_match('//u', $to)) {
150 throw new InvalidArgumentException('Invalid UTF-8 string.');
151 }
152 if ($this->ignoreCase) {
153 $str->string = \implode($to, \preg_split('{' . \preg_quote($from) . '}iuD', $this->string));
154 } else {
155 $str->string = \str_replace($from, $to, $this->string);
156 }
157 return $str;
158 }
159 public function slice(int $start = 0, int $length = null) : AbstractString
160 {
161 $str = clone $this;
162 $str->string = \mb_substr($this->string, $start, $length, 'UTF-8');
163 return $str;
164 }
165 public function splice(string $replacement, int $start = 0, int $length = null) : AbstractString
166 {
167 if (!\preg_match('//u', $replacement)) {
168 throw new InvalidArgumentException('Invalid UTF-8 string.');
169 }
170 $str = clone $this;
171 $start = $start ? \strlen(\mb_substr($this->string, 0, $start, 'UTF-8')) : 0;
172 $length = $length ? \strlen(\mb_substr($this->string, $start, $length, 'UTF-8')) : $length;
173 $str->string = \substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX);
174 return $str;
175 }
176 public function split(string $delimiter, int $limit = null, int $flags = null) : array
177 {
178 if (1 > ($limit = $limit ?? \PHP_INT_MAX)) {
179 throw new InvalidArgumentException('Split limit must be a positive integer.');
180 }
181 if ('' === $delimiter) {
182 throw new InvalidArgumentException('Split delimiter is empty.');
183 }
184 if (null !== $flags) {
185 return parent::split($delimiter . 'u', $limit, $flags);
186 }
187 if (!\preg_match('//u', $delimiter)) {
188 throw new InvalidArgumentException('Split delimiter is not a valid UTF-8 string.');
189 }
190 $str = clone $this;
191 $chunks = $this->ignoreCase ? \preg_split('{' . \preg_quote($delimiter) . '}iuD', $this->string, $limit) : \explode($delimiter, $this->string, $limit);
192 foreach ($chunks as &$chunk) {
193 $str->string = $chunk;
194 $chunk = clone $str;
195 }
196 return $chunks;
197 }
198 public function startsWith($prefix) : bool
199 {
200 if ($prefix instanceof AbstractString) {
201 $prefix = $prefix->string;
202 } elseif (\is_array($prefix) || $prefix instanceof \Traversable) {
203 return parent::startsWith($prefix);
204 } else {
205 $prefix = (string) $prefix;
206 }
207 if ('' === $prefix || !\preg_match('//u', $prefix)) {
208 return \false;
209 }
210 if ($this->ignoreCase) {
211 return 0 === \mb_stripos($this->string, $prefix, 0, 'UTF-8');
212 }
213 return 0 === \strncmp($this->string, $prefix, \strlen($prefix));
214 }
215 }
216