Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/polyfill-mbstring/Mbstring.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
76 array('μ','s','ι', 'σ','β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1",'ι'), | 76 array('μ','s','ι', 'σ','β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1",'ι'), |
77 ); | 77 ); |
78 | 78 |
79 public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) | 79 public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) |
80 { | 80 { |
81 if (is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) { | 81 if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) { |
82 $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); | 82 $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); |
83 } else { | 83 } else { |
84 $fromEncoding = self::getEncoding($fromEncoding); | 84 $fromEncoding = self::getEncoding($fromEncoding); |
85 } | 85 } |
86 | 86 |
138 trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING); | 138 trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING); |
139 } | 139 } |
140 | 140 |
141 public static function mb_decode_numericentity($s, $convmap, $encoding = null) | 141 public static function mb_decode_numericentity($s, $convmap, $encoding = null) |
142 { | 142 { |
143 if (null !== $s && !is_scalar($s) && !(is_object($s) && method_exists($s, '__toString'))) { | 143 if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { |
144 trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.gettype($s).' given', E_USER_WARNING); | 144 trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.gettype($s).' given', E_USER_WARNING); |
145 return null; | 145 return null; |
146 } | 146 } |
147 | 147 |
148 if (!is_array($convmap) || !$convmap) { | 148 if (!\is_array($convmap) || !$convmap) { |
149 return false; | 149 return false; |
150 } | 150 } |
151 | 151 |
152 if (null !== $encoding && !is_scalar($encoding)) { | 152 if (null !== $encoding && !\is_scalar($encoding)) { |
153 trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.gettype($s).' given', E_USER_WARNING); | 153 trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.gettype($s).' given', E_USER_WARNING); |
154 return ''; // Instead of null (cf. mb_encode_numericentity). | 154 return ''; // Instead of null (cf. mb_encode_numericentity). |
155 } | 155 } |
156 | 156 |
157 $s = (string) $s; | 157 $s = (string) $s; |
168 } | 168 } |
169 } else { | 169 } else { |
170 $s = iconv($encoding, 'UTF-8//IGNORE', $s); | 170 $s = iconv($encoding, 'UTF-8//IGNORE', $s); |
171 } | 171 } |
172 | 172 |
173 $cnt = floor(count($convmap) / 4) * 4; | 173 $cnt = floor(\count($convmap) / 4) * 4; |
174 | 174 |
175 for ($i = 0; $i < $cnt; $i += 4) { | 175 for ($i = 0; $i < $cnt; $i += 4) { |
176 // collector_decode_htmlnumericentity ignores $convmap[$i + 3] | 176 // collector_decode_htmlnumericentity ignores $convmap[$i + 3] |
177 $convmap[$i] += $convmap[$i + 2]; | 177 $convmap[$i] += $convmap[$i + 2]; |
178 $convmap[$i + 1] += $convmap[$i + 2]; | 178 $convmap[$i + 1] += $convmap[$i + 2]; |
195 return iconv('UTF-8', $encoding.'//IGNORE', $s); | 195 return iconv('UTF-8', $encoding.'//IGNORE', $s); |
196 } | 196 } |
197 | 197 |
198 public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) | 198 public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) |
199 { | 199 { |
200 if (null !== $s && !is_scalar($s) && !(is_object($s) && method_exists($s, '__toString'))) { | 200 if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { |
201 trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.gettype($s).' given', E_USER_WARNING); | 201 trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.gettype($s).' given', E_USER_WARNING); |
202 return null; | 202 return null; |
203 } | 203 } |
204 | 204 |
205 if (!is_array($convmap) || !$convmap) { | 205 if (!\is_array($convmap) || !$convmap) { |
206 return false; | 206 return false; |
207 } | 207 } |
208 | 208 |
209 if (null !== $encoding && !is_scalar($encoding)) { | 209 if (null !== $encoding && !\is_scalar($encoding)) { |
210 trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.gettype($s).' given', E_USER_WARNING); | 210 trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.gettype($s).' given', E_USER_WARNING); |
211 return null; // Instead of '' (cf. mb_decode_numericentity). | 211 return null; // Instead of '' (cf. mb_decode_numericentity). |
212 } | 212 } |
213 | 213 |
214 if (null !== $is_hex && !is_scalar($is_hex)) { | 214 if (null !== $is_hex && !\is_scalar($is_hex)) { |
215 trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.gettype($s).' given', E_USER_WARNING); | 215 trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.gettype($s).' given', E_USER_WARNING); |
216 return null; | 216 return null; |
217 } | 217 } |
218 | 218 |
219 $s = (string) $s; | 219 $s = (string) $s; |
232 $s = iconv($encoding, 'UTF-8//IGNORE', $s); | 232 $s = iconv($encoding, 'UTF-8//IGNORE', $s); |
233 } | 233 } |
234 | 234 |
235 static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); | 235 static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); |
236 | 236 |
237 $cnt = floor(count($convmap) / 4) * 4; | 237 $cnt = floor(\count($convmap) / 4) * 4; |
238 $i = 0; | 238 $i = 0; |
239 $len = strlen($s); | 239 $len = \strlen($s); |
240 $result = ''; | 240 $result = ''; |
241 | 241 |
242 while ($i < $len) { | 242 while ($i < $len) { |
243 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; | 243 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
244 $uchr = substr($s, $i, $ulen); | 244 $uchr = substr($s, $i, $ulen); |
303 } | 303 } |
304 | 304 |
305 static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); | 305 static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); |
306 | 306 |
307 $i = 0; | 307 $i = 0; |
308 $len = strlen($s); | 308 $len = \strlen($s); |
309 | 309 |
310 while ($i < $len) { | 310 while ($i < $len) { |
311 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; | 311 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
312 $uchr = substr($s, $i, $ulen); | 312 $uchr = substr($s, $i, $ulen); |
313 $i += $ulen; | 313 $i += $ulen; |
314 | 314 |
315 if (isset($map[$uchr])) { | 315 if (isset($map[$uchr])) { |
316 $uchr = $map[$uchr]; | 316 $uchr = $map[$uchr]; |
317 $nlen = strlen($uchr); | 317 $nlen = \strlen($uchr); |
318 | 318 |
319 if ($nlen == $ulen) { | 319 if ($nlen == $ulen) { |
320 $nlen = $i; | 320 $nlen = $i; |
321 do { | 321 do { |
322 $s[--$nlen] = $uchr[--$ulen]; | 322 $s[--$nlen] = $uchr[--$ulen]; |
402 public static function mb_detect_encoding($str, $encodingList = null, $strict = false) | 402 public static function mb_detect_encoding($str, $encodingList = null, $strict = false) |
403 { | 403 { |
404 if (null === $encodingList) { | 404 if (null === $encodingList) { |
405 $encodingList = self::$encodingList; | 405 $encodingList = self::$encodingList; |
406 } else { | 406 } else { |
407 if (!is_array($encodingList)) { | 407 if (!\is_array($encodingList)) { |
408 $encodingList = array_map('trim', explode(',', $encodingList)); | 408 $encodingList = array_map('trim', explode(',', $encodingList)); |
409 } | 409 } |
410 $encodingList = array_map('strtoupper', $encodingList); | 410 $encodingList = array_map('strtoupper', $encodingList); |
411 } | 411 } |
412 | 412 |
439 { | 439 { |
440 if (null === $encodingList) { | 440 if (null === $encodingList) { |
441 return self::$encodingList; | 441 return self::$encodingList; |
442 } | 442 } |
443 | 443 |
444 if (!is_array($encodingList)) { | 444 if (!\is_array($encodingList)) { |
445 $encodingList = array_map('trim', explode(',', $encodingList)); | 445 $encodingList = array_map('trim', explode(',', $encodingList)); |
446 } | 446 } |
447 $encodingList = array_map('strtoupper', $encodingList); | 447 $encodingList = array_map('strtoupper', $encodingList); |
448 | 448 |
449 foreach ($encodingList as $enc) { | 449 foreach ($encodingList as $enc) { |
465 | 465 |
466 public static function mb_strlen($s, $encoding = null) | 466 public static function mb_strlen($s, $encoding = null) |
467 { | 467 { |
468 $encoding = self::getEncoding($encoding); | 468 $encoding = self::getEncoding($encoding); |
469 if ('CP850' === $encoding || 'ASCII' === $encoding) { | 469 if ('CP850' === $encoding || 'ASCII' === $encoding) { |
470 return strlen($s); | 470 return \strlen($s); |
471 } | 471 } |
472 | 472 |
473 return @iconv_strlen($s, $encoding); | 473 return @iconv_strlen($s, $encoding); |
474 } | 474 } |
475 | 475 |
677 } | 677 } |
678 | 678 |
679 public static function mb_chr($code, $encoding = null) | 679 public static function mb_chr($code, $encoding = null) |
680 { | 680 { |
681 if (0x80 > $code %= 0x200000) { | 681 if (0x80 > $code %= 0x200000) { |
682 $s = chr($code); | 682 $s = \chr($code); |
683 } elseif (0x800 > $code) { | 683 } elseif (0x800 > $code) { |
684 $s = chr(0xC0 | $code >> 6).chr(0x80 | $code & 0x3F); | 684 $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); |
685 } elseif (0x10000 > $code) { | 685 } elseif (0x10000 > $code) { |
686 $s = chr(0xE0 | $code >> 12).chr(0x80 | $code >> 6 & 0x3F).chr(0x80 | $code & 0x3F); | 686 $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
687 } else { | 687 } else { |
688 $s = chr(0xF0 | $code >> 18).chr(0x80 | $code >> 12 & 0x3F).chr(0x80 | $code >> 6 & 0x3F).chr(0x80 | $code & 0x3F); | 688 $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
689 } | 689 } |
690 | 690 |
691 if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { | 691 if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
692 $s = mb_convert_encoding($s, $encoding, 'UTF-8'); | 692 $s = mb_convert_encoding($s, $encoding, 'UTF-8'); |
693 } | 693 } |
733 $entities = ''; | 733 $entities = ''; |
734 $m = unpack('C*', htmlentities($m[0], ENT_COMPAT, 'UTF-8')); | 734 $m = unpack('C*', htmlentities($m[0], ENT_COMPAT, 'UTF-8')); |
735 | 735 |
736 while (isset($m[$i])) { | 736 while (isset($m[$i])) { |
737 if (0x80 > $m[$i]) { | 737 if (0x80 > $m[$i]) { |
738 $entities .= chr($m[$i++]); | 738 $entities .= \chr($m[$i++]); |
739 continue; | 739 continue; |
740 } | 740 } |
741 if (0xF0 <= $m[$i]) { | 741 if (0xF0 <= $m[$i]) { |
742 $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; | 742 $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
743 } elseif (0xE0 <= $m[$i]) { | 743 } elseif (0xE0 <= $m[$i]) { |