composer package updates
[openemr.git] / vendor / symfony / polyfill-mbstring / Mbstring.php
blob4bd326e5f6e89c2ca7df31ab3247fd0a63d8bc7c
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Polyfill\Mbstring;
14 /**
15 * Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
17 * Implemented:
18 * - mb_chr - Returns a specific character from its Unicode code point
19 * - mb_convert_encoding - Convert character encoding
20 * - mb_convert_variables - Convert character code in variable(s)
21 * - mb_decode_mimeheader - Decode string in MIME header field
22 * - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED
23 * - mb_decode_numericentity - Decode HTML numeric string reference to character
24 * - mb_encode_numericentity - Encode character to HTML numeric string reference
25 * - mb_convert_case - Perform case folding on a string
26 * - mb_detect_encoding - Detect character encoding
27 * - mb_get_info - Get internal settings of mbstring
28 * - mb_http_input - Detect HTTP input character encoding
29 * - mb_http_output - Set/Get HTTP output character encoding
30 * - mb_internal_encoding - Set/Get internal character encoding
31 * - mb_list_encodings - Returns an array of all supported encodings
32 * - mb_ord - Returns the Unicode code point of a character
33 * - mb_output_handler - Callback function converts character encoding in output buffer
34 * - mb_scrub - Replaces ill-formed byte sequences with substitute characters
35 * - mb_strlen - Get string length
36 * - mb_strpos - Find position of first occurrence of string in a string
37 * - mb_strrpos - Find position of last occurrence of a string in a string
38 * - mb_strtolower - Make a string lowercase
39 * - mb_strtoupper - Make a string uppercase
40 * - mb_substitute_character - Set/Get substitution character
41 * - mb_substr - Get part of string
42 * - mb_stripos - Finds position of first occurrence of a string within another, case insensitive
43 * - mb_stristr - Finds first occurrence of a string within another, case insensitive
44 * - mb_strrchr - Finds the last occurrence of a character in a string within another
45 * - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
46 * - mb_strripos - Finds position of last occurrence of a string within another, case insensitive
47 * - mb_strstr - Finds first occurrence of a string within anothers
48 * - mb_strwidth - Return width of string
49 * - mb_substr_count - Count the number of substring occurrences
51 * Not implemented:
52 * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
53 * - mb_ereg_* - Regular expression with multibyte support
54 * - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
55 * - mb_preferred_mime_name - Get MIME charset string
56 * - mb_regex_encoding - Returns current encoding for multibyte regex as string
57 * - mb_regex_set_options - Set/Get the default options for mbregex functions
58 * - mb_send_mail - Send encoded mail
59 * - mb_split - Split multibyte string using regular expression
60 * - mb_strcut - Get part of string
61 * - mb_strimwidth - Get truncated string with specified width
63 * @author Nicolas Grekas <p@tchwork.com>
65 * @internal
67 final class Mbstring
69 const MB_CASE_FOLD = PHP_INT_MAX;
71 private static $encodingList = array('ASCII', 'UTF-8');
72 private static $language = 'neutral';
73 private static $internalEncoding = 'UTF-8';
74 private static $caseFold = array(
75 array('µ','ſ',"\xCD\x85",'ς',"\xCF\x90","\xCF\x91","\xCF\x95","\xCF\x96","\xCF\xB0","\xCF\xB1","\xCF\xB5","\xE1\xBA\x9B","\xE1\xBE\xBE"),
76 array('μ','s','ι', 'σ','β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1",'ι'),
79 public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
81 if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) {
82 $fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
83 } else {
84 $fromEncoding = self::getEncoding($fromEncoding);
87 $toEncoding = self::getEncoding($toEncoding);
89 if ('BASE64' === $fromEncoding) {
90 $s = base64_decode($s);
91 $fromEncoding = $toEncoding;
94 if ('BASE64' === $toEncoding) {
95 return base64_encode($s);
98 if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
99 if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
100 $fromEncoding = 'Windows-1252';
102 if ('UTF-8' !== $fromEncoding) {
103 $s = iconv($fromEncoding, 'UTF-8//IGNORE', $s);
106 return preg_replace_callback('/[\x80-\xFF]+/', array(__CLASS__, 'html_encoding_callback'), $s);
109 if ('HTML-ENTITIES' === $fromEncoding) {
110 $s = html_entity_decode($s, ENT_COMPAT, 'UTF-8');
111 $fromEncoding = 'UTF-8';
114 return iconv($fromEncoding, $toEncoding.'//IGNORE', $s);
117 public static function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null)
119 $vars = array(&$a, &$b, &$c, &$d, &$e, &$f);
121 $ok = true;
122 array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) {
123 if (false === $v = Mbstring::mb_convert_encoding($v, $toEncoding, $fromEncoding)) {
124 $ok = false;
128 return $ok ? $fromEncoding : false;
131 public static function mb_decode_mimeheader($s)
133 return iconv_mime_decode($s, 2, self::$internalEncoding);
136 public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
138 trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING);
141 public static function mb_decode_numericentity($s, $convmap, $encoding = null)
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);
145 return null;
148 if (!\is_array($convmap) || !$convmap) {
149 return false;
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);
154 return ''; // Instead of null (cf. mb_encode_numericentity).
157 $s = (string) $s;
158 if ('' === $s) {
159 return '';
162 $encoding = self::getEncoding($encoding);
164 if ('UTF-8' === $encoding) {
165 $encoding = null;
166 if (!preg_match('//u', $s)) {
167 $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
169 } else {
170 $s = iconv($encoding, 'UTF-8//IGNORE', $s);
173 $cnt = floor(\count($convmap) / 4) * 4;
175 for ($i = 0; $i < $cnt; $i += 4) {
176 // collector_decode_htmlnumericentity ignores $convmap[$i + 3]
177 $convmap[$i] += $convmap[$i + 2];
178 $convmap[$i + 1] += $convmap[$i + 2];
181 $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) {
182 $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1];
183 for ($i = 0; $i < $cnt; $i += 4) {
184 if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
185 return Mbstring::mb_chr($c - $convmap[$i + 2]);
188 return $m[0];
189 }, $s);
191 if (null === $encoding) {
192 return $s;
195 return iconv('UTF-8', $encoding.'//IGNORE', $s);
198 public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false)
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);
202 return null;
205 if (!\is_array($convmap) || !$convmap) {
206 return false;
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);
211 return null; // Instead of '' (cf. mb_decode_numericentity).
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);
216 return null;
219 $s = (string) $s;
220 if ('' === $s) {
221 return '';
224 $encoding = self::getEncoding($encoding);
226 if ('UTF-8' === $encoding) {
227 $encoding = null;
228 if (!preg_match('//u', $s)) {
229 $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
231 } else {
232 $s = iconv($encoding, 'UTF-8//IGNORE', $s);
235 static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4);
237 $cnt = floor(\count($convmap) / 4) * 4;
238 $i = 0;
239 $len = \strlen($s);
240 $result = '';
242 while ($i < $len) {
243 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
244 $uchr = substr($s, $i, $ulen);
245 $i += $ulen;
246 $c = self::mb_ord($uchr);
248 for ($j = 0; $j < $cnt; $j += 4) {
249 if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
250 $cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3];
251 $result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';';
252 continue 2;
255 $result .= $uchr;
258 if (null === $encoding) {
259 return $result;
262 return iconv('UTF-8', $encoding.'//IGNORE', $result);
265 public static function mb_convert_case($s, $mode, $encoding = null)
267 $s = (string) $s;
268 if ('' === $s) {
269 return '';
272 $encoding = self::getEncoding($encoding);
274 if ('UTF-8' === $encoding) {
275 $encoding = null;
276 if (!preg_match('//u', $s)) {
277 $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
279 } else {
280 $s = iconv($encoding, 'UTF-8//IGNORE', $s);
283 if (MB_CASE_TITLE == $mode) {
284 $s = preg_replace_callback('/\b\p{Ll}/u', array(__CLASS__, 'title_case_upper'), $s);
285 $s = preg_replace_callback('/\B[\p{Lu}\p{Lt}]+/u', array(__CLASS__, 'title_case_lower'), $s);
286 } else {
287 if (MB_CASE_UPPER == $mode) {
288 static $upper = null;
289 if (null === $upper) {
290 $upper = self::getData('upperCase');
292 $map = $upper;
293 } else {
294 if (self::MB_CASE_FOLD === $mode) {
295 $s = str_replace(self::$caseFold[0], self::$caseFold[1], $s);
298 static $lower = null;
299 if (null === $lower) {
300 $lower = self::getData('lowerCase');
302 $map = $lower;
305 static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4);
307 $i = 0;
308 $len = \strlen($s);
310 while ($i < $len) {
311 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
312 $uchr = substr($s, $i, $ulen);
313 $i += $ulen;
315 if (isset($map[$uchr])) {
316 $uchr = $map[$uchr];
317 $nlen = \strlen($uchr);
319 if ($nlen == $ulen) {
320 $nlen = $i;
321 do {
322 $s[--$nlen] = $uchr[--$ulen];
323 } while ($ulen);
324 } else {
325 $s = substr_replace($s, $uchr, $i - $ulen, $ulen);
326 $len += $nlen - $ulen;
327 $i += $nlen - $ulen;
333 if (null === $encoding) {
334 return $s;
337 return iconv('UTF-8', $encoding.'//IGNORE', $s);
340 public static function mb_internal_encoding($encoding = null)
342 if (null === $encoding) {
343 return self::$internalEncoding;
346 $encoding = self::getEncoding($encoding);
348 if ('UTF-8' === $encoding || false !== @iconv($encoding, $encoding, ' ')) {
349 self::$internalEncoding = $encoding;
351 return true;
354 return false;
357 public static function mb_language($lang = null)
359 if (null === $lang) {
360 return self::$language;
363 switch ($lang = strtolower($lang)) {
364 case 'uni':
365 case 'neutral':
366 self::$language = $lang;
368 return true;
371 return false;
374 public static function mb_list_encodings()
376 return array('UTF-8');
379 public static function mb_encoding_aliases($encoding)
381 switch (strtoupper($encoding)) {
382 case 'UTF8':
383 case 'UTF-8':
384 return array('utf8');
387 return false;
390 public static function mb_check_encoding($var = null, $encoding = null)
392 if (null === $encoding) {
393 if (null === $var) {
394 return false;
396 $encoding = self::$internalEncoding;
399 return self::mb_detect_encoding($var, array($encoding)) || false !== @iconv($encoding, $encoding, $var);
402 public static function mb_detect_encoding($str, $encodingList = null, $strict = false)
404 if (null === $encodingList) {
405 $encodingList = self::$encodingList;
406 } else {
407 if (!\is_array($encodingList)) {
408 $encodingList = array_map('trim', explode(',', $encodingList));
410 $encodingList = array_map('strtoupper', $encodingList);
413 foreach ($encodingList as $enc) {
414 switch ($enc) {
415 case 'ASCII':
416 if (!preg_match('/[\x80-\xFF]/', $str)) {
417 return $enc;
419 break;
421 case 'UTF8':
422 case 'UTF-8':
423 if (preg_match('//u', $str)) {
424 return 'UTF-8';
426 break;
428 default:
429 if (0 === strncmp($enc, 'ISO-8859-', 9)) {
430 return $enc;
435 return false;
438 public static function mb_detect_order($encodingList = null)
440 if (null === $encodingList) {
441 return self::$encodingList;
444 if (!\is_array($encodingList)) {
445 $encodingList = array_map('trim', explode(',', $encodingList));
447 $encodingList = array_map('strtoupper', $encodingList);
449 foreach ($encodingList as $enc) {
450 switch ($enc) {
451 default:
452 if (strncmp($enc, 'ISO-8859-', 9)) {
453 return false;
455 case 'ASCII':
456 case 'UTF8':
457 case 'UTF-8':
461 self::$encodingList = $encodingList;
463 return true;
466 public static function mb_strlen($s, $encoding = null)
468 $encoding = self::getEncoding($encoding);
469 if ('CP850' === $encoding || 'ASCII' === $encoding) {
470 return \strlen($s);
473 return @iconv_strlen($s, $encoding);
476 public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
478 $encoding = self::getEncoding($encoding);
479 if ('CP850' === $encoding || 'ASCII' === $encoding) {
480 return strpos($haystack, $needle, $offset);
483 $needle = (string) $needle;
484 if ('' === $needle) {
485 trigger_error(__METHOD__.': Empty delimiter', E_USER_WARNING);
487 return false;
490 return iconv_strpos($haystack, $needle, $offset, $encoding);
493 public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
495 $encoding = self::getEncoding($encoding);
496 if ('CP850' === $encoding || 'ASCII' === $encoding) {
497 return strrpos($haystack, $needle, $offset);
500 if ($offset != (int) $offset) {
501 $offset = 0;
502 } elseif ($offset = (int) $offset) {
503 if ($offset < 0) {
504 $haystack = self::mb_substr($haystack, 0, $offset, $encoding);
505 $offset = 0;
506 } else {
507 $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
511 $pos = iconv_strrpos($haystack, $needle, $encoding);
513 return false !== $pos ? $offset + $pos : false;
516 public static function mb_strtolower($s, $encoding = null)
518 return self::mb_convert_case($s, MB_CASE_LOWER, $encoding);
521 public static function mb_strtoupper($s, $encoding = null)
523 return self::mb_convert_case($s, MB_CASE_UPPER, $encoding);
526 public static function mb_substitute_character($c = null)
528 if (0 === strcasecmp($c, 'none')) {
529 return true;
532 return null !== $c ? false : 'none';
535 public static function mb_substr($s, $start, $length = null, $encoding = null)
537 $encoding = self::getEncoding($encoding);
538 if ('CP850' === $encoding || 'ASCII' === $encoding) {
539 return substr($s, $start, null === $length ? 2147483647 : $length);
542 if ($start < 0) {
543 $start = iconv_strlen($s, $encoding) + $start;
544 if ($start < 0) {
545 $start = 0;
549 if (null === $length) {
550 $length = 2147483647;
551 } elseif ($length < 0) {
552 $length = iconv_strlen($s, $encoding) + $length - $start;
553 if ($length < 0) {
554 return '';
558 return (string) iconv_substr($s, $start, $length, $encoding);
561 public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
563 $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
564 $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
566 return self::mb_strpos($haystack, $needle, $offset, $encoding);
569 public static function mb_stristr($haystack, $needle, $part = false, $encoding = null)
571 $pos = self::mb_stripos($haystack, $needle, 0, $encoding);
573 return self::getSubpart($pos, $part, $haystack, $encoding);
576 public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null)
578 $encoding = self::getEncoding($encoding);
579 if ('CP850' === $encoding || 'ASCII' === $encoding) {
580 return strrchr($haystack, $needle, $part);
582 $needle = self::mb_substr($needle, 0, 1, $encoding);
583 $pos = iconv_strrpos($haystack, $needle, $encoding);
585 return self::getSubpart($pos, $part, $haystack, $encoding);
588 public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null)
590 $needle = self::mb_substr($needle, 0, 1, $encoding);
591 $pos = self::mb_strripos($haystack, $needle, $encoding);
593 return self::getSubpart($pos, $part, $haystack, $encoding);
596 public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
598 $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
599 $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
601 return self::mb_strrpos($haystack, $needle, $offset, $encoding);
604 public static function mb_strstr($haystack, $needle, $part = false, $encoding = null)
606 $pos = strpos($haystack, $needle);
607 if (false === $pos) {
608 return false;
610 if ($part) {
611 return substr($haystack, 0, $pos);
614 return substr($haystack, $pos);
617 public static function mb_get_info($type = 'all')
619 $info = array(
620 'internal_encoding' => self::$internalEncoding,
621 'http_output' => 'pass',
622 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)',
623 'func_overload' => 0,
624 'func_overload_list' => 'no overload',
625 'mail_charset' => 'UTF-8',
626 'mail_header_encoding' => 'BASE64',
627 'mail_body_encoding' => 'BASE64',
628 'illegal_chars' => 0,
629 'encoding_translation' => 'Off',
630 'language' => self::$language,
631 'detect_order' => self::$encodingList,
632 'substitute_character' => 'none',
633 'strict_detection' => 'Off',
636 if ('all' === $type) {
637 return $info;
639 if (isset($info[$type])) {
640 return $info[$type];
643 return false;
646 public static function mb_http_input($type = '')
648 return false;
651 public static function mb_http_output($encoding = null)
653 return null !== $encoding ? 'pass' === $encoding : 'pass';
656 public static function mb_strwidth($s, $encoding = null)
658 $encoding = self::getEncoding($encoding);
660 if ('UTF-8' !== $encoding) {
661 $s = iconv($encoding, 'UTF-8//IGNORE', $s);
664 $s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide);
666 return ($wide << 1) + iconv_strlen($s, 'UTF-8');
669 public static function mb_substr_count($haystack, $needle, $encoding = null)
671 return substr_count($haystack, $needle);
674 public static function mb_output_handler($contents, $status)
676 return $contents;
679 public static function mb_chr($code, $encoding = null)
681 if (0x80 > $code %= 0x200000) {
682 $s = \chr($code);
683 } elseif (0x800 > $code) {
684 $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F);
685 } elseif (0x10000 > $code) {
686 $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F);
687 } else {
688 $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F);
691 if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
692 $s = mb_convert_encoding($s, $encoding, 'UTF-8');
695 return $s;
698 public static function mb_ord($s, $encoding = null)
700 if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
701 $s = mb_convert_encoding($s, 'UTF-8', $encoding);
704 $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0;
705 if (0xF0 <= $code) {
706 return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80;
708 if (0xE0 <= $code) {
709 return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80;
711 if (0xC0 <= $code) {
712 return (($code - 0xC0) << 6) + $s[2] - 0x80;
715 return $code;
718 private static function getSubpart($pos, $part, $haystack, $encoding)
720 if (false === $pos) {
721 return false;
723 if ($part) {
724 return self::mb_substr($haystack, 0, $pos, $encoding);
727 return self::mb_substr($haystack, $pos, null, $encoding);
730 private static function html_encoding_callback(array $m)
732 $i = 1;
733 $entities = '';
734 $m = unpack('C*', htmlentities($m[0], ENT_COMPAT, 'UTF-8'));
736 while (isset($m[$i])) {
737 if (0x80 > $m[$i]) {
738 $entities .= \chr($m[$i++]);
739 continue;
741 if (0xF0 <= $m[$i]) {
742 $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
743 } elseif (0xE0 <= $m[$i]) {
744 $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
745 } else {
746 $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80;
749 $entities .= '&#'.$c.';';
752 return $entities;
755 private static function title_case_lower(array $s)
757 return self::mb_convert_case($s[0], MB_CASE_LOWER, 'UTF-8');
760 private static function title_case_upper(array $s)
762 return self::mb_convert_case($s[0], MB_CASE_UPPER, 'UTF-8');
765 private static function getData($file)
767 if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) {
768 return require $file;
771 return false;
774 private static function getEncoding($encoding)
776 if (null === $encoding) {
777 return self::$internalEncoding;
780 $encoding = strtoupper($encoding);
782 if ('8BIT' === $encoding || 'BINARY' === $encoding) {
783 return 'CP850';
785 if ('UTF8' === $encoding) {
786 return 'UTF-8';
789 return $encoding;