PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.0
Independent Analytics – WordPress Analytics Plugin v2.15.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 5 days ago Resources 5 days ago Slugger 5 days ago AbstractString.php 5 days ago AbstractUnicodeString.php 5 days ago ByteString.php 5 days ago CodePointString.php 5 days ago LazyString.php 5 days ago UnicodeString.php 5 days ago
CodePointString.php
206 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 IAWPSCOPED\Symfony\Component\String;
12
13 use IAWPSCOPED\Symfony\Component\String\Exception\ExceptionInterface;
14 use IAWPSCOPED\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) : static
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(string|iterable|AbstractString $suffix) : bool
70 {
71 if ($suffix instanceof AbstractString) {
72 $suffix = $suffix->string;
73 } elseif (!\is_string($suffix)) {
74 return parent::endsWith($suffix);
75 }
76 if ('' === $suffix || !\preg_match('//u', $suffix)) {
77 return \false;
78 }
79 if ($this->ignoreCase) {
80 return \preg_match('{' . \preg_quote($suffix) . '$}iuD', $this->string);
81 }
82 return \strlen($this->string) >= \strlen($suffix) && 0 === \substr_compare($this->string, $suffix, -\strlen($suffix));
83 }
84 public function equalsTo(string|iterable|AbstractString $string) : bool
85 {
86 if ($string instanceof AbstractString) {
87 $string = $string->string;
88 } elseif (!\is_string($string)) {
89 return parent::equalsTo($string);
90 }
91 if ('' !== $string && $this->ignoreCase) {
92 return \strlen($string) === \strlen($this->string) && 0 === \mb_stripos($this->string, $string, 0, 'UTF-8');
93 }
94 return $string === $this->string;
95 }
96 public function indexOf(string|iterable|AbstractString $needle, int $offset = 0) : ?int
97 {
98 if ($needle instanceof AbstractString) {
99 $needle = $needle->string;
100 } elseif (!\is_string($needle)) {
101 return parent::indexOf($needle, $offset);
102 }
103 if ('' === $needle) {
104 return null;
105 }
106 $i = $this->ignoreCase ? \mb_stripos($this->string, $needle, $offset, 'UTF-8') : \mb_strpos($this->string, $needle, $offset, 'UTF-8');
107 return \false === $i ? null : $i;
108 }
109 public function indexOfLast(string|iterable|AbstractString $needle, int $offset = 0) : ?int
110 {
111 if ($needle instanceof AbstractString) {
112 $needle = $needle->string;
113 } elseif (!\is_string($needle)) {
114 return parent::indexOfLast($needle, $offset);
115 }
116 if ('' === $needle) {
117 return null;
118 }
119 $i = $this->ignoreCase ? \mb_strripos($this->string, $needle, $offset, 'UTF-8') : \mb_strrpos($this->string, $needle, $offset, 'UTF-8');
120 return \false === $i ? null : $i;
121 }
122 public function length() : int
123 {
124 return \mb_strlen($this->string, 'UTF-8');
125 }
126 public function prepend(string ...$prefix) : static
127 {
128 $str = clone $this;
129 $str->string = (1 >= \count($prefix) ? $prefix[0] ?? '' : \implode('', $prefix)) . $this->string;
130 if (!\preg_match('//u', $str->string)) {
131 throw new InvalidArgumentException('Invalid UTF-8 string.');
132 }
133 return $str;
134 }
135 public function replace(string $from, string $to) : static
136 {
137 $str = clone $this;
138 if ('' === $from || !\preg_match('//u', $from)) {
139 return $str;
140 }
141 if ('' !== $to && !\preg_match('//u', $to)) {
142 throw new InvalidArgumentException('Invalid UTF-8 string.');
143 }
144 if ($this->ignoreCase) {
145 $str->string = \implode($to, \preg_split('{' . \preg_quote($from) . '}iuD', $this->string));
146 } else {
147 $str->string = \str_replace($from, $to, $this->string);
148 }
149 return $str;
150 }
151 public function slice(int $start = 0, int $length = null) : static
152 {
153 $str = clone $this;
154 $str->string = \mb_substr($this->string, $start, $length, 'UTF-8');
155 return $str;
156 }
157 public function splice(string $replacement, int $start = 0, int $length = null) : static
158 {
159 if (!\preg_match('//u', $replacement)) {
160 throw new InvalidArgumentException('Invalid UTF-8 string.');
161 }
162 $str = clone $this;
163 $start = $start ? \strlen(\mb_substr($this->string, 0, $start, 'UTF-8')) : 0;
164 $length = $length ? \strlen(\mb_substr($this->string, $start, $length, 'UTF-8')) : $length;
165 $str->string = \substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX);
166 return $str;
167 }
168 public function split(string $delimiter, int $limit = null, int $flags = null) : array
169 {
170 if (1 > ($limit = $limit ?? \PHP_INT_MAX)) {
171 throw new InvalidArgumentException('Split limit must be a positive integer.');
172 }
173 if ('' === $delimiter) {
174 throw new InvalidArgumentException('Split delimiter is empty.');
175 }
176 if (null !== $flags) {
177 return parent::split($delimiter . 'u', $limit, $flags);
178 }
179 if (!\preg_match('//u', $delimiter)) {
180 throw new InvalidArgumentException('Split delimiter is not a valid UTF-8 string.');
181 }
182 $str = clone $this;
183 $chunks = $this->ignoreCase ? \preg_split('{' . \preg_quote($delimiter) . '}iuD', $this->string, $limit) : \explode($delimiter, $this->string, $limit);
184 foreach ($chunks as &$chunk) {
185 $str->string = $chunk;
186 $chunk = clone $str;
187 }
188 return $chunks;
189 }
190 public function startsWith(string|iterable|AbstractString $prefix) : bool
191 {
192 if ($prefix instanceof AbstractString) {
193 $prefix = $prefix->string;
194 } elseif (!\is_string($prefix)) {
195 return parent::startsWith($prefix);
196 }
197 if ('' === $prefix || !\preg_match('//u', $prefix)) {
198 return \false;
199 }
200 if ($this->ignoreCase) {
201 return 0 === \mb_stripos($this->string, $prefix, 0, 'UTF-8');
202 }
203 return 0 === \strncmp($this->string, $prefix, \strlen($prefix));
204 }
205 }
206