@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (\PHP_VERSION_ID < 80000) { |
4 | - class UnhandledMatchError extends Error |
|
5 | - { |
|
6 | - } |
|
4 | + class UnhandledMatchError extends Error |
|
5 | + { |
|
6 | + } |
|
7 | 7 | } |
@@ -20,96 +20,96 @@ |
||
20 | 20 | */ |
21 | 21 | final class Php80 |
22 | 22 | { |
23 | - public static function fdiv(float $dividend, float $divisor): float |
|
24 | - { |
|
25 | - return @($dividend / $divisor); |
|
26 | - } |
|
27 | - |
|
28 | - public static function get_debug_type($value): string |
|
29 | - { |
|
30 | - switch (true) { |
|
31 | - case null === $value: return 'null'; |
|
32 | - case \is_bool($value): return 'bool'; |
|
33 | - case \is_string($value): return 'string'; |
|
34 | - case \is_array($value): return 'array'; |
|
35 | - case \is_int($value): return 'int'; |
|
36 | - case \is_float($value): return 'float'; |
|
37 | - case \is_object($value): break; |
|
38 | - case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; |
|
39 | - default: |
|
40 | - if (null === $type = @get_resource_type($value)) { |
|
41 | - return 'unknown'; |
|
42 | - } |
|
43 | - |
|
44 | - if ('Unknown' === $type) { |
|
45 | - $type = 'closed'; |
|
46 | - } |
|
47 | - |
|
48 | - return "resource ($type)"; |
|
49 | - } |
|
50 | - |
|
51 | - $class = \get_class($value); |
|
52 | - |
|
53 | - if (false === strpos($class, '@')) { |
|
54 | - return $class; |
|
55 | - } |
|
56 | - |
|
57 | - return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; |
|
58 | - } |
|
59 | - |
|
60 | - public static function get_resource_id($res): int |
|
61 | - { |
|
62 | - if (!\is_resource($res) && null === @get_resource_type($res)) { |
|
63 | - throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
|
64 | - } |
|
65 | - |
|
66 | - return (int) $res; |
|
67 | - } |
|
68 | - |
|
69 | - public static function preg_last_error_msg(): string |
|
70 | - { |
|
71 | - switch (preg_last_error()) { |
|
72 | - case \PREG_INTERNAL_ERROR: |
|
73 | - return 'Internal error'; |
|
74 | - case \PREG_BAD_UTF8_ERROR: |
|
75 | - return 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
76 | - case \PREG_BAD_UTF8_OFFSET_ERROR: |
|
77 | - return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; |
|
78 | - case \PREG_BACKTRACK_LIMIT_ERROR: |
|
79 | - return 'Backtrack limit exhausted'; |
|
80 | - case \PREG_RECURSION_LIMIT_ERROR: |
|
81 | - return 'Recursion limit exhausted'; |
|
82 | - case \PREG_JIT_STACKLIMIT_ERROR: |
|
83 | - return 'JIT stack limit exhausted'; |
|
84 | - case \PREG_NO_ERROR: |
|
85 | - return 'No error'; |
|
86 | - default: |
|
87 | - return 'Unknown error'; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - public static function str_contains(string $haystack, string $needle): bool |
|
92 | - { |
|
93 | - return '' === $needle || false !== strpos($haystack, $needle); |
|
94 | - } |
|
95 | - |
|
96 | - public static function str_starts_with(string $haystack, string $needle): bool |
|
97 | - { |
|
98 | - return 0 === strncmp($haystack, $needle, \strlen($needle)); |
|
99 | - } |
|
100 | - |
|
101 | - public static function str_ends_with(string $haystack, string $needle): bool |
|
102 | - { |
|
103 | - if ('' === $needle || $needle === $haystack) { |
|
104 | - return true; |
|
105 | - } |
|
106 | - |
|
107 | - if ('' === $haystack) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - |
|
111 | - $needleLength = \strlen($needle); |
|
112 | - |
|
113 | - return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength); |
|
114 | - } |
|
23 | + public static function fdiv(float $dividend, float $divisor): float |
|
24 | + { |
|
25 | + return @($dividend / $divisor); |
|
26 | + } |
|
27 | + |
|
28 | + public static function get_debug_type($value): string |
|
29 | + { |
|
30 | + switch (true) { |
|
31 | + case null === $value: return 'null'; |
|
32 | + case \is_bool($value): return 'bool'; |
|
33 | + case \is_string($value): return 'string'; |
|
34 | + case \is_array($value): return 'array'; |
|
35 | + case \is_int($value): return 'int'; |
|
36 | + case \is_float($value): return 'float'; |
|
37 | + case \is_object($value): break; |
|
38 | + case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; |
|
39 | + default: |
|
40 | + if (null === $type = @get_resource_type($value)) { |
|
41 | + return 'unknown'; |
|
42 | + } |
|
43 | + |
|
44 | + if ('Unknown' === $type) { |
|
45 | + $type = 'closed'; |
|
46 | + } |
|
47 | + |
|
48 | + return "resource ($type)"; |
|
49 | + } |
|
50 | + |
|
51 | + $class = \get_class($value); |
|
52 | + |
|
53 | + if (false === strpos($class, '@')) { |
|
54 | + return $class; |
|
55 | + } |
|
56 | + |
|
57 | + return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; |
|
58 | + } |
|
59 | + |
|
60 | + public static function get_resource_id($res): int |
|
61 | + { |
|
62 | + if (!\is_resource($res) && null === @get_resource_type($res)) { |
|
63 | + throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
|
64 | + } |
|
65 | + |
|
66 | + return (int) $res; |
|
67 | + } |
|
68 | + |
|
69 | + public static function preg_last_error_msg(): string |
|
70 | + { |
|
71 | + switch (preg_last_error()) { |
|
72 | + case \PREG_INTERNAL_ERROR: |
|
73 | + return 'Internal error'; |
|
74 | + case \PREG_BAD_UTF8_ERROR: |
|
75 | + return 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
76 | + case \PREG_BAD_UTF8_OFFSET_ERROR: |
|
77 | + return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; |
|
78 | + case \PREG_BACKTRACK_LIMIT_ERROR: |
|
79 | + return 'Backtrack limit exhausted'; |
|
80 | + case \PREG_RECURSION_LIMIT_ERROR: |
|
81 | + return 'Recursion limit exhausted'; |
|
82 | + case \PREG_JIT_STACKLIMIT_ERROR: |
|
83 | + return 'JIT stack limit exhausted'; |
|
84 | + case \PREG_NO_ERROR: |
|
85 | + return 'No error'; |
|
86 | + default: |
|
87 | + return 'Unknown error'; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + public static function str_contains(string $haystack, string $needle): bool |
|
92 | + { |
|
93 | + return '' === $needle || false !== strpos($haystack, $needle); |
|
94 | + } |
|
95 | + |
|
96 | + public static function str_starts_with(string $haystack, string $needle): bool |
|
97 | + { |
|
98 | + return 0 === strncmp($haystack, $needle, \strlen($needle)); |
|
99 | + } |
|
100 | + |
|
101 | + public static function str_ends_with(string $haystack, string $needle): bool |
|
102 | + { |
|
103 | + if ('' === $needle || $needle === $haystack) { |
|
104 | + return true; |
|
105 | + } |
|
106 | + |
|
107 | + if ('' === $haystack) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + |
|
111 | + $needleLength = \strlen($needle); |
|
112 | + |
|
113 | + return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength); |
|
114 | + } |
|
115 | 115 | } |
@@ -12,136 +12,136 @@ |
||
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | 14 | if (\PHP_VERSION_ID >= 80000) { |
15 | - return require __DIR__.'/bootstrap80.php'; |
|
15 | + return require __DIR__.'/bootstrap80.php'; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | if (!function_exists('mb_convert_encoding')) { |
19 | - function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } |
|
19 | + function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } |
|
20 | 20 | } |
21 | 21 | if (!function_exists('mb_decode_mimeheader')) { |
22 | - function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } |
|
22 | + function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } |
|
23 | 23 | } |
24 | 24 | if (!function_exists('mb_encode_mimeheader')) { |
25 | - function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } |
|
25 | + function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } |
|
26 | 26 | } |
27 | 27 | if (!function_exists('mb_decode_numericentity')) { |
28 | - function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } |
|
28 | + function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } |
|
29 | 29 | } |
30 | 30 | if (!function_exists('mb_encode_numericentity')) { |
31 | - function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } |
|
31 | + function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } |
|
32 | 32 | } |
33 | 33 | if (!function_exists('mb_convert_case')) { |
34 | - function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } |
|
34 | + function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } |
|
35 | 35 | } |
36 | 36 | if (!function_exists('mb_internal_encoding')) { |
37 | - function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } |
|
37 | + function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } |
|
38 | 38 | } |
39 | 39 | if (!function_exists('mb_language')) { |
40 | - function mb_language($language = null) { return p\Mbstring::mb_language($language); } |
|
40 | + function mb_language($language = null) { return p\Mbstring::mb_language($language); } |
|
41 | 41 | } |
42 | 42 | if (!function_exists('mb_list_encodings')) { |
43 | - function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } |
|
43 | + function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } |
|
44 | 44 | } |
45 | 45 | if (!function_exists('mb_encoding_aliases')) { |
46 | - function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } |
|
46 | + function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } |
|
47 | 47 | } |
48 | 48 | if (!function_exists('mb_check_encoding')) { |
49 | - function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
49 | + function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
50 | 50 | } |
51 | 51 | if (!function_exists('mb_detect_encoding')) { |
52 | - function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } |
|
52 | + function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } |
|
53 | 53 | } |
54 | 54 | if (!function_exists('mb_detect_order')) { |
55 | - function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } |
|
55 | + function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } |
|
56 | 56 | } |
57 | 57 | if (!function_exists('mb_parse_str')) { |
58 | - function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } |
|
58 | + function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } |
|
59 | 59 | } |
60 | 60 | if (!function_exists('mb_strlen')) { |
61 | - function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } |
|
61 | + function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } |
|
62 | 62 | } |
63 | 63 | if (!function_exists('mb_strpos')) { |
64 | - function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } |
|
64 | + function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } |
|
65 | 65 | } |
66 | 66 | if (!function_exists('mb_strtolower')) { |
67 | - function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } |
|
67 | + function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } |
|
68 | 68 | } |
69 | 69 | if (!function_exists('mb_strtoupper')) { |
70 | - function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } |
|
70 | + function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } |
|
71 | 71 | } |
72 | 72 | if (!function_exists('mb_substitute_character')) { |
73 | - function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
73 | + function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
74 | 74 | } |
75 | 75 | if (!function_exists('mb_substr')) { |
76 | - function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } |
|
76 | + function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } |
|
77 | 77 | } |
78 | 78 | if (!function_exists('mb_stripos')) { |
79 | - function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } |
|
79 | + function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } |
|
80 | 80 | } |
81 | 81 | if (!function_exists('mb_stristr')) { |
82 | - function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } |
|
82 | + function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } |
|
83 | 83 | } |
84 | 84 | if (!function_exists('mb_strrchr')) { |
85 | - function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } |
|
85 | + function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } |
|
86 | 86 | } |
87 | 87 | if (!function_exists('mb_strrichr')) { |
88 | - function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } |
|
88 | + function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } |
|
89 | 89 | } |
90 | 90 | if (!function_exists('mb_strripos')) { |
91 | - function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } |
|
91 | + function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } |
|
92 | 92 | } |
93 | 93 | if (!function_exists('mb_strrpos')) { |
94 | - function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } |
|
94 | + function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } |
|
95 | 95 | } |
96 | 96 | if (!function_exists('mb_strstr')) { |
97 | - function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } |
|
97 | + function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } |
|
98 | 98 | } |
99 | 99 | if (!function_exists('mb_get_info')) { |
100 | - function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } |
|
100 | + function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } |
|
101 | 101 | } |
102 | 102 | if (!function_exists('mb_http_output')) { |
103 | - function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } |
|
103 | + function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } |
|
104 | 104 | } |
105 | 105 | if (!function_exists('mb_strwidth')) { |
106 | - function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } |
|
106 | + function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } |
|
107 | 107 | } |
108 | 108 | if (!function_exists('mb_substr_count')) { |
109 | - function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } |
|
109 | + function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } |
|
110 | 110 | } |
111 | 111 | if (!function_exists('mb_output_handler')) { |
112 | - function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } |
|
112 | + function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } |
|
113 | 113 | } |
114 | 114 | if (!function_exists('mb_http_input')) { |
115 | - function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } |
|
115 | + function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | if (!function_exists('mb_convert_variables')) { |
119 | - function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } |
|
119 | + function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | if (!function_exists('mb_ord')) { |
123 | - function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } |
|
123 | + function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } |
|
124 | 124 | } |
125 | 125 | if (!function_exists('mb_chr')) { |
126 | - function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } |
|
126 | + function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } |
|
127 | 127 | } |
128 | 128 | if (!function_exists('mb_scrub')) { |
129 | - function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } |
|
129 | + function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } |
|
130 | 130 | } |
131 | 131 | if (!function_exists('mb_str_split')) { |
132 | - function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } |
|
132 | + function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | if (extension_loaded('mbstring')) { |
136 | - return; |
|
136 | + return; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | if (!defined('MB_CASE_UPPER')) { |
140 | - define('MB_CASE_UPPER', 0); |
|
140 | + define('MB_CASE_UPPER', 0); |
|
141 | 141 | } |
142 | 142 | if (!defined('MB_CASE_LOWER')) { |
143 | - define('MB_CASE_LOWER', 1); |
|
143 | + define('MB_CASE_LOWER', 1); |
|
144 | 144 | } |
145 | 145 | if (!defined('MB_CASE_TITLE')) { |
146 | - define('MB_CASE_TITLE', 2); |
|
146 | + define('MB_CASE_TITLE', 2); |
|
147 | 147 | } |
@@ -67,807 +67,807 @@ |
||
67 | 67 | */ |
68 | 68 | final class Mbstring |
69 | 69 | { |
70 | - public const MB_CASE_FOLD = \PHP_INT_MAX; |
|
71 | - |
|
72 | - private const CASE_FOLD = [ |
|
73 | - ['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"], |
|
74 | - ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'], |
|
75 | - ]; |
|
76 | - |
|
77 | - private static $encodingList = ['ASCII', 'UTF-8']; |
|
78 | - private static $language = 'neutral'; |
|
79 | - private static $internalEncoding = 'UTF-8'; |
|
80 | - |
|
81 | - public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) |
|
82 | - { |
|
83 | - if (\is_array($fromEncoding) || ($fromEncoding !== null && false !== strpos($fromEncoding, ','))) { |
|
84 | - $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); |
|
85 | - } else { |
|
86 | - $fromEncoding = self::getEncoding($fromEncoding); |
|
87 | - } |
|
88 | - |
|
89 | - $toEncoding = self::getEncoding($toEncoding); |
|
90 | - |
|
91 | - if ('BASE64' === $fromEncoding) { |
|
92 | - $s = base64_decode($s); |
|
93 | - $fromEncoding = $toEncoding; |
|
94 | - } |
|
95 | - |
|
96 | - if ('BASE64' === $toEncoding) { |
|
97 | - return base64_encode($s); |
|
98 | - } |
|
99 | - |
|
100 | - if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) { |
|
101 | - if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) { |
|
102 | - $fromEncoding = 'Windows-1252'; |
|
103 | - } |
|
104 | - if ('UTF-8' !== $fromEncoding) { |
|
105 | - $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s); |
|
106 | - } |
|
107 | - |
|
108 | - return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s); |
|
109 | - } |
|
110 | - |
|
111 | - if ('HTML-ENTITIES' === $fromEncoding) { |
|
112 | - $s = html_entity_decode($s, \ENT_COMPAT, 'UTF-8'); |
|
113 | - $fromEncoding = 'UTF-8'; |
|
114 | - } |
|
115 | - |
|
116 | - return \iconv($fromEncoding, $toEncoding.'//IGNORE', $s); |
|
117 | - } |
|
118 | - |
|
119 | - public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars) |
|
120 | - { |
|
121 | - $ok = true; |
|
122 | - array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) { |
|
123 | - if (false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) { |
|
124 | - $ok = false; |
|
125 | - } |
|
126 | - }); |
|
127 | - |
|
128 | - return $ok ? $fromEncoding : false; |
|
129 | - } |
|
130 | - |
|
131 | - public static function mb_decode_mimeheader($s) |
|
132 | - { |
|
133 | - return \iconv_mime_decode($s, 2, self::$internalEncoding); |
|
134 | - } |
|
135 | - |
|
136 | - public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null) |
|
137 | - { |
|
138 | - trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING); |
|
139 | - } |
|
140 | - |
|
141 | - public static function mb_decode_numericentity($s, $convmap, $encoding = null) |
|
142 | - { |
|
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 | - |
|
146 | - return null; |
|
147 | - } |
|
148 | - |
|
149 | - if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - if (null !== $encoding && !is_scalar($encoding)) { |
|
154 | - trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
155 | - |
|
156 | - return ''; // Instead of null (cf. mb_encode_numericentity). |
|
157 | - } |
|
158 | - |
|
159 | - $s = (string) $s; |
|
160 | - if ('' === $s) { |
|
161 | - return ''; |
|
162 | - } |
|
163 | - |
|
164 | - $encoding = self::getEncoding($encoding); |
|
165 | - |
|
166 | - if ('UTF-8' === $encoding) { |
|
167 | - $encoding = null; |
|
168 | - if (!preg_match('//u', $s)) { |
|
169 | - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
170 | - } |
|
171 | - } else { |
|
172 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
173 | - } |
|
174 | - |
|
175 | - $cnt = floor(\count($convmap) / 4) * 4; |
|
176 | - |
|
177 | - for ($i = 0; $i < $cnt; $i += 4) { |
|
178 | - // collector_decode_htmlnumericentity ignores $convmap[$i + 3] |
|
179 | - $convmap[$i] += $convmap[$i + 2]; |
|
180 | - $convmap[$i + 1] += $convmap[$i + 2]; |
|
181 | - } |
|
182 | - |
|
183 | - $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) { |
|
184 | - $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1]; |
|
185 | - for ($i = 0; $i < $cnt; $i += 4) { |
|
186 | - if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { |
|
187 | - return self::mb_chr($c - $convmap[$i + 2]); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - return $m[0]; |
|
192 | - }, $s); |
|
193 | - |
|
194 | - if (null === $encoding) { |
|
195 | - return $s; |
|
196 | - } |
|
197 | - |
|
198 | - return \iconv('UTF-8', $encoding.'//IGNORE', $s); |
|
199 | - } |
|
200 | - |
|
201 | - public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) |
|
202 | - { |
|
203 | - if (null !== $s && !is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) { |
|
204 | - trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
205 | - |
|
206 | - return null; |
|
207 | - } |
|
208 | - |
|
209 | - if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { |
|
210 | - return false; |
|
211 | - } |
|
212 | - |
|
213 | - if (null !== $encoding && !is_scalar($encoding)) { |
|
214 | - trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
215 | - |
|
216 | - return null; // Instead of '' (cf. mb_decode_numericentity). |
|
217 | - } |
|
218 | - |
|
219 | - if (null !== $is_hex && !is_scalar($is_hex)) { |
|
220 | - trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', \E_USER_WARNING); |
|
221 | - |
|
222 | - return null; |
|
223 | - } |
|
224 | - |
|
225 | - $s = (string) $s; |
|
226 | - if ('' === $s) { |
|
227 | - return ''; |
|
228 | - } |
|
229 | - |
|
230 | - $encoding = self::getEncoding($encoding); |
|
231 | - |
|
232 | - if ('UTF-8' === $encoding) { |
|
233 | - $encoding = null; |
|
234 | - if (!preg_match('//u', $s)) { |
|
235 | - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
236 | - } |
|
237 | - } else { |
|
238 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
239 | - } |
|
240 | - |
|
241 | - static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4]; |
|
242 | - |
|
243 | - $cnt = floor(\count($convmap) / 4) * 4; |
|
244 | - $i = 0; |
|
245 | - $len = \strlen($s); |
|
246 | - $result = ''; |
|
247 | - |
|
248 | - while ($i < $len) { |
|
249 | - $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
|
250 | - $uchr = substr($s, $i, $ulen); |
|
251 | - $i += $ulen; |
|
252 | - $c = self::mb_ord($uchr); |
|
253 | - |
|
254 | - for ($j = 0; $j < $cnt; $j += 4) { |
|
255 | - if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) { |
|
256 | - $cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3]; |
|
257 | - $result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';'; |
|
258 | - continue 2; |
|
259 | - } |
|
260 | - } |
|
261 | - $result .= $uchr; |
|
262 | - } |
|
263 | - |
|
264 | - if (null === $encoding) { |
|
265 | - return $result; |
|
266 | - } |
|
267 | - |
|
268 | - return \iconv('UTF-8', $encoding.'//IGNORE', $result); |
|
269 | - } |
|
270 | - |
|
271 | - public static function mb_convert_case($s, $mode, $encoding = null) |
|
272 | - { |
|
273 | - $s = (string) $s; |
|
274 | - if ('' === $s) { |
|
275 | - return ''; |
|
276 | - } |
|
277 | - |
|
278 | - $encoding = self::getEncoding($encoding); |
|
279 | - |
|
280 | - if ('UTF-8' === $encoding) { |
|
281 | - $encoding = null; |
|
282 | - if (!preg_match('//u', $s)) { |
|
283 | - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
284 | - } |
|
285 | - } else { |
|
286 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
287 | - } |
|
288 | - |
|
289 | - if (\MB_CASE_TITLE == $mode) { |
|
290 | - static $titleRegexp = null; |
|
291 | - if (null === $titleRegexp) { |
|
292 | - $titleRegexp = self::getData('titleCaseRegexp'); |
|
293 | - } |
|
294 | - $s = preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s); |
|
295 | - } else { |
|
296 | - if (\MB_CASE_UPPER == $mode) { |
|
297 | - static $upper = null; |
|
298 | - if (null === $upper) { |
|
299 | - $upper = self::getData('upperCase'); |
|
300 | - } |
|
301 | - $map = $upper; |
|
302 | - } else { |
|
303 | - if (self::MB_CASE_FOLD === $mode) { |
|
304 | - $s = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s); |
|
305 | - } |
|
306 | - |
|
307 | - static $lower = null; |
|
308 | - if (null === $lower) { |
|
309 | - $lower = self::getData('lowerCase'); |
|
310 | - } |
|
311 | - $map = $lower; |
|
312 | - } |
|
313 | - |
|
314 | - static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4]; |
|
315 | - |
|
316 | - $i = 0; |
|
317 | - $len = \strlen($s); |
|
318 | - |
|
319 | - while ($i < $len) { |
|
320 | - $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
|
321 | - $uchr = substr($s, $i, $ulen); |
|
322 | - $i += $ulen; |
|
323 | - |
|
324 | - if (isset($map[$uchr])) { |
|
325 | - $uchr = $map[$uchr]; |
|
326 | - $nlen = \strlen($uchr); |
|
327 | - |
|
328 | - if ($nlen == $ulen) { |
|
329 | - $nlen = $i; |
|
330 | - do { |
|
331 | - $s[--$nlen] = $uchr[--$ulen]; |
|
332 | - } while ($ulen); |
|
333 | - } else { |
|
334 | - $s = substr_replace($s, $uchr, $i - $ulen, $ulen); |
|
335 | - $len += $nlen - $ulen; |
|
336 | - $i += $nlen - $ulen; |
|
337 | - } |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - if (null === $encoding) { |
|
343 | - return $s; |
|
344 | - } |
|
345 | - |
|
346 | - return \iconv('UTF-8', $encoding.'//IGNORE', $s); |
|
347 | - } |
|
348 | - |
|
349 | - public static function mb_internal_encoding($encoding = null) |
|
350 | - { |
|
351 | - if (null === $encoding) { |
|
352 | - return self::$internalEncoding; |
|
353 | - } |
|
354 | - |
|
355 | - $normalizedEncoding = self::getEncoding($encoding); |
|
356 | - |
|
357 | - if ('UTF-8' === $normalizedEncoding || false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) { |
|
358 | - self::$internalEncoding = $normalizedEncoding; |
|
359 | - |
|
360 | - return true; |
|
361 | - } |
|
362 | - |
|
363 | - if (80000 > \PHP_VERSION_ID) { |
|
364 | - return false; |
|
365 | - } |
|
366 | - |
|
367 | - throw new \ValueError(sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
|
368 | - } |
|
369 | - |
|
370 | - public static function mb_language($lang = null) |
|
371 | - { |
|
372 | - if (null === $lang) { |
|
373 | - return self::$language; |
|
374 | - } |
|
375 | - |
|
376 | - switch ($normalizedLang = strtolower($lang)) { |
|
377 | - case 'uni': |
|
378 | - case 'neutral': |
|
379 | - self::$language = $normalizedLang; |
|
380 | - |
|
381 | - return true; |
|
382 | - } |
|
383 | - |
|
384 | - if (80000 > \PHP_VERSION_ID) { |
|
385 | - return false; |
|
386 | - } |
|
387 | - |
|
388 | - throw new \ValueError(sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang)); |
|
389 | - } |
|
390 | - |
|
391 | - public static function mb_list_encodings() |
|
392 | - { |
|
393 | - return ['UTF-8']; |
|
394 | - } |
|
395 | - |
|
396 | - public static function mb_encoding_aliases($encoding) |
|
397 | - { |
|
398 | - switch (strtoupper($encoding)) { |
|
399 | - case 'UTF8': |
|
400 | - case 'UTF-8': |
|
401 | - return ['utf8']; |
|
402 | - } |
|
403 | - |
|
404 | - return false; |
|
405 | - } |
|
406 | - |
|
407 | - public static function mb_check_encoding($var = null, $encoding = null) |
|
408 | - { |
|
409 | - if (null === $encoding) { |
|
410 | - if (null === $var) { |
|
411 | - return false; |
|
412 | - } |
|
413 | - $encoding = self::$internalEncoding; |
|
414 | - } |
|
415 | - |
|
416 | - return self::mb_detect_encoding($var, [$encoding]) || false !== @\iconv($encoding, $encoding, $var); |
|
417 | - } |
|
418 | - |
|
419 | - public static function mb_detect_encoding($str, $encodingList = null, $strict = false) |
|
420 | - { |
|
421 | - if (null === $encodingList) { |
|
422 | - $encodingList = self::$encodingList; |
|
423 | - } else { |
|
424 | - if (!\is_array($encodingList)) { |
|
425 | - $encodingList = array_map('trim', explode(',', $encodingList)); |
|
426 | - } |
|
427 | - $encodingList = array_map('strtoupper', $encodingList); |
|
428 | - } |
|
429 | - |
|
430 | - foreach ($encodingList as $enc) { |
|
431 | - switch ($enc) { |
|
432 | - case 'ASCII': |
|
433 | - if (!preg_match('/[\x80-\xFF]/', $str)) { |
|
434 | - return $enc; |
|
435 | - } |
|
436 | - break; |
|
437 | - |
|
438 | - case 'UTF8': |
|
439 | - case 'UTF-8': |
|
440 | - if (preg_match('//u', $str)) { |
|
441 | - return 'UTF-8'; |
|
442 | - } |
|
443 | - break; |
|
444 | - |
|
445 | - default: |
|
446 | - if (0 === strncmp($enc, 'ISO-8859-', 9)) { |
|
447 | - return $enc; |
|
448 | - } |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - return false; |
|
453 | - } |
|
454 | - |
|
455 | - public static function mb_detect_order($encodingList = null) |
|
456 | - { |
|
457 | - if (null === $encodingList) { |
|
458 | - return self::$encodingList; |
|
459 | - } |
|
460 | - |
|
461 | - if (!\is_array($encodingList)) { |
|
462 | - $encodingList = array_map('trim', explode(',', $encodingList)); |
|
463 | - } |
|
464 | - $encodingList = array_map('strtoupper', $encodingList); |
|
465 | - |
|
466 | - foreach ($encodingList as $enc) { |
|
467 | - switch ($enc) { |
|
468 | - default: |
|
469 | - if (strncmp($enc, 'ISO-8859-', 9)) { |
|
470 | - return false; |
|
471 | - } |
|
472 | - // no break |
|
473 | - case 'ASCII': |
|
474 | - case 'UTF8': |
|
475 | - case 'UTF-8': |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - self::$encodingList = $encodingList; |
|
480 | - |
|
481 | - return true; |
|
482 | - } |
|
483 | - |
|
484 | - public static function mb_strlen($s, $encoding = null) |
|
485 | - { |
|
486 | - $encoding = self::getEncoding($encoding); |
|
487 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
488 | - return \strlen($s); |
|
489 | - } |
|
490 | - |
|
491 | - return @\iconv_strlen($s, $encoding); |
|
492 | - } |
|
493 | - |
|
494 | - public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) |
|
495 | - { |
|
496 | - $encoding = self::getEncoding($encoding); |
|
497 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
498 | - return strpos($haystack, $needle, $offset); |
|
499 | - } |
|
500 | - |
|
501 | - $needle = (string) $needle; |
|
502 | - if ('' === $needle) { |
|
503 | - if (80000 > \PHP_VERSION_ID) { |
|
504 | - trigger_error(__METHOD__.': Empty delimiter', \E_USER_WARNING); |
|
505 | - |
|
506 | - return false; |
|
507 | - } |
|
508 | - |
|
509 | - return 0; |
|
510 | - } |
|
511 | - |
|
512 | - return \iconv_strpos($haystack, $needle, $offset, $encoding); |
|
513 | - } |
|
514 | - |
|
515 | - public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) |
|
516 | - { |
|
517 | - $encoding = self::getEncoding($encoding); |
|
518 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
519 | - return strrpos($haystack, $needle, $offset); |
|
520 | - } |
|
521 | - |
|
522 | - if ($offset != (int) $offset) { |
|
523 | - $offset = 0; |
|
524 | - } elseif ($offset = (int) $offset) { |
|
525 | - if ($offset < 0) { |
|
526 | - if (0 > $offset += self::mb_strlen($needle)) { |
|
527 | - $haystack = self::mb_substr($haystack, 0, $offset, $encoding); |
|
528 | - } |
|
529 | - $offset = 0; |
|
530 | - } else { |
|
531 | - $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding); |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - $pos = '' !== $needle || 80000 > \PHP_VERSION_ID |
|
536 | - ? \iconv_strrpos($haystack, $needle, $encoding) |
|
537 | - : self::mb_strlen($haystack, $encoding); |
|
538 | - |
|
539 | - return false !== $pos ? $offset + $pos : false; |
|
540 | - } |
|
541 | - |
|
542 | - public static function mb_str_split($string, $split_length = 1, $encoding = null) |
|
543 | - { |
|
544 | - if (null !== $string && !is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) { |
|
545 | - trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', \E_USER_WARNING); |
|
546 | - |
|
547 | - return null; |
|
548 | - } |
|
549 | - |
|
550 | - if (1 > $split_length = (int) $split_length) { |
|
551 | - if (80000 > \PHP_VERSION_ID) { |
|
552 | - trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING); |
|
553 | - return false; |
|
554 | - } |
|
555 | - |
|
556 | - throw new \ValueError('Argument #2 ($length) must be greater than 0'); |
|
557 | - } |
|
558 | - |
|
559 | - if (null === $encoding) { |
|
560 | - $encoding = mb_internal_encoding(); |
|
561 | - } |
|
562 | - |
|
563 | - if ('UTF-8' === $encoding = self::getEncoding($encoding)) { |
|
564 | - $rx = '/('; |
|
565 | - while (65535 < $split_length) { |
|
566 | - $rx .= '.{65535}'; |
|
567 | - $split_length -= 65535; |
|
568 | - } |
|
569 | - $rx .= '.{'.$split_length.'})/us'; |
|
570 | - |
|
571 | - return preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY); |
|
572 | - } |
|
573 | - |
|
574 | - $result = []; |
|
575 | - $length = mb_strlen($string, $encoding); |
|
576 | - |
|
577 | - for ($i = 0; $i < $length; $i += $split_length) { |
|
578 | - $result[] = mb_substr($string, $i, $split_length, $encoding); |
|
579 | - } |
|
580 | - |
|
581 | - return $result; |
|
582 | - } |
|
583 | - |
|
584 | - public static function mb_strtolower($s, $encoding = null) |
|
585 | - { |
|
586 | - return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding); |
|
587 | - } |
|
588 | - |
|
589 | - public static function mb_strtoupper($s, $encoding = null) |
|
590 | - { |
|
591 | - return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding); |
|
592 | - } |
|
593 | - |
|
594 | - public static function mb_substitute_character($c = null) |
|
595 | - { |
|
596 | - if (null === $c) { |
|
597 | - return 'none'; |
|
598 | - } |
|
599 | - if (0 === strcasecmp($c, 'none')) { |
|
600 | - return true; |
|
601 | - } |
|
602 | - if (80000 > \PHP_VERSION_ID) { |
|
603 | - return false; |
|
604 | - } |
|
605 | - if (\is_int($c) || 'long' === $c || 'entity' === $c) { |
|
606 | - return false; |
|
607 | - } |
|
608 | - |
|
609 | - throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); |
|
610 | - } |
|
611 | - |
|
612 | - public static function mb_substr($s, $start, $length = null, $encoding = null) |
|
613 | - { |
|
614 | - $encoding = self::getEncoding($encoding); |
|
615 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
616 | - return (string) substr($s, $start, null === $length ? 2147483647 : $length); |
|
617 | - } |
|
618 | - |
|
619 | - if ($start < 0) { |
|
620 | - $start = \iconv_strlen($s, $encoding) + $start; |
|
621 | - if ($start < 0) { |
|
622 | - $start = 0; |
|
623 | - } |
|
624 | - } |
|
625 | - |
|
626 | - if (null === $length) { |
|
627 | - $length = 2147483647; |
|
628 | - } elseif ($length < 0) { |
|
629 | - $length = \iconv_strlen($s, $encoding) + $length - $start; |
|
630 | - if ($length < 0) { |
|
631 | - return ''; |
|
632 | - } |
|
633 | - } |
|
634 | - |
|
635 | - return (string) \iconv_substr($s, $start, $length, $encoding); |
|
636 | - } |
|
637 | - |
|
638 | - public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) |
|
639 | - { |
|
640 | - $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); |
|
641 | - $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); |
|
642 | - |
|
643 | - return self::mb_strpos($haystack, $needle, $offset, $encoding); |
|
644 | - } |
|
645 | - |
|
646 | - public static function mb_stristr($haystack, $needle, $part = false, $encoding = null) |
|
647 | - { |
|
648 | - $pos = self::mb_stripos($haystack, $needle, 0, $encoding); |
|
649 | - |
|
650 | - return self::getSubpart($pos, $part, $haystack, $encoding); |
|
651 | - } |
|
652 | - |
|
653 | - public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null) |
|
654 | - { |
|
655 | - $encoding = self::getEncoding($encoding); |
|
656 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
657 | - $pos = strrpos($haystack, $needle); |
|
658 | - } else { |
|
659 | - $needle = self::mb_substr($needle, 0, 1, $encoding); |
|
660 | - $pos = \iconv_strrpos($haystack, $needle, $encoding); |
|
661 | - } |
|
662 | - |
|
663 | - return self::getSubpart($pos, $part, $haystack, $encoding); |
|
664 | - } |
|
665 | - |
|
666 | - public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null) |
|
667 | - { |
|
668 | - $needle = self::mb_substr($needle, 0, 1, $encoding); |
|
669 | - $pos = self::mb_strripos($haystack, $needle, $encoding); |
|
670 | - |
|
671 | - return self::getSubpart($pos, $part, $haystack, $encoding); |
|
672 | - } |
|
673 | - |
|
674 | - public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) |
|
675 | - { |
|
676 | - $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); |
|
677 | - $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); |
|
678 | - |
|
679 | - return self::mb_strrpos($haystack, $needle, $offset, $encoding); |
|
680 | - } |
|
681 | - |
|
682 | - public static function mb_strstr($haystack, $needle, $part = false, $encoding = null) |
|
683 | - { |
|
684 | - $pos = strpos($haystack, $needle); |
|
685 | - if (false === $pos) { |
|
686 | - return false; |
|
687 | - } |
|
688 | - if ($part) { |
|
689 | - return substr($haystack, 0, $pos); |
|
690 | - } |
|
691 | - |
|
692 | - return substr($haystack, $pos); |
|
693 | - } |
|
694 | - |
|
695 | - public static function mb_get_info($type = 'all') |
|
696 | - { |
|
697 | - $info = [ |
|
698 | - 'internal_encoding' => self::$internalEncoding, |
|
699 | - 'http_output' => 'pass', |
|
700 | - 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)', |
|
701 | - 'func_overload' => 0, |
|
702 | - 'func_overload_list' => 'no overload', |
|
703 | - 'mail_charset' => 'UTF-8', |
|
704 | - 'mail_header_encoding' => 'BASE64', |
|
705 | - 'mail_body_encoding' => 'BASE64', |
|
706 | - 'illegal_chars' => 0, |
|
707 | - 'encoding_translation' => 'Off', |
|
708 | - 'language' => self::$language, |
|
709 | - 'detect_order' => self::$encodingList, |
|
710 | - 'substitute_character' => 'none', |
|
711 | - 'strict_detection' => 'Off', |
|
712 | - ]; |
|
713 | - |
|
714 | - if ('all' === $type) { |
|
715 | - return $info; |
|
716 | - } |
|
717 | - if (isset($info[$type])) { |
|
718 | - return $info[$type]; |
|
719 | - } |
|
720 | - |
|
721 | - return false; |
|
722 | - } |
|
723 | - |
|
724 | - public static function mb_http_input($type = '') |
|
725 | - { |
|
726 | - return false; |
|
727 | - } |
|
728 | - |
|
729 | - public static function mb_http_output($encoding = null) |
|
730 | - { |
|
731 | - return null !== $encoding ? 'pass' === $encoding : 'pass'; |
|
732 | - } |
|
733 | - |
|
734 | - public static function mb_strwidth($s, $encoding = null) |
|
735 | - { |
|
736 | - $encoding = self::getEncoding($encoding); |
|
737 | - |
|
738 | - if ('UTF-8' !== $encoding) { |
|
739 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
740 | - } |
|
741 | - |
|
742 | - $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); |
|
743 | - |
|
744 | - return ($wide << 1) + \iconv_strlen($s, 'UTF-8'); |
|
745 | - } |
|
746 | - |
|
747 | - public static function mb_substr_count($haystack, $needle, $encoding = null) |
|
748 | - { |
|
749 | - return substr_count($haystack, $needle); |
|
750 | - } |
|
751 | - |
|
752 | - public static function mb_output_handler($contents, $status) |
|
753 | - { |
|
754 | - return $contents; |
|
755 | - } |
|
756 | - |
|
757 | - public static function mb_chr($code, $encoding = null) |
|
758 | - { |
|
759 | - if (0x80 > $code %= 0x200000) { |
|
760 | - $s = \chr($code); |
|
761 | - } elseif (0x800 > $code) { |
|
762 | - $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); |
|
763 | - } elseif (0x10000 > $code) { |
|
764 | - $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
765 | - } else { |
|
766 | - $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
767 | - } |
|
768 | - |
|
769 | - if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
|
770 | - $s = mb_convert_encoding($s, $encoding, 'UTF-8'); |
|
771 | - } |
|
772 | - |
|
773 | - return $s; |
|
774 | - } |
|
775 | - |
|
776 | - public static function mb_ord($s, $encoding = null) |
|
777 | - { |
|
778 | - if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
|
779 | - $s = mb_convert_encoding($s, 'UTF-8', $encoding); |
|
780 | - } |
|
781 | - |
|
782 | - if (1 === \strlen($s)) { |
|
783 | - return \ord($s); |
|
784 | - } |
|
785 | - |
|
786 | - $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; |
|
787 | - if (0xF0 <= $code) { |
|
788 | - return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; |
|
789 | - } |
|
790 | - if (0xE0 <= $code) { |
|
791 | - return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; |
|
792 | - } |
|
793 | - if (0xC0 <= $code) { |
|
794 | - return (($code - 0xC0) << 6) + $s[2] - 0x80; |
|
795 | - } |
|
796 | - |
|
797 | - return $code; |
|
798 | - } |
|
799 | - |
|
800 | - private static function getSubpart($pos, $part, $haystack, $encoding) |
|
801 | - { |
|
802 | - if (false === $pos) { |
|
803 | - return false; |
|
804 | - } |
|
805 | - if ($part) { |
|
806 | - return self::mb_substr($haystack, 0, $pos, $encoding); |
|
807 | - } |
|
808 | - |
|
809 | - return self::mb_substr($haystack, $pos, null, $encoding); |
|
810 | - } |
|
811 | - |
|
812 | - private static function html_encoding_callback(array $m) |
|
813 | - { |
|
814 | - $i = 1; |
|
815 | - $entities = ''; |
|
816 | - $m = unpack('C*', htmlentities($m[0], \ENT_COMPAT, 'UTF-8')); |
|
817 | - |
|
818 | - while (isset($m[$i])) { |
|
819 | - if (0x80 > $m[$i]) { |
|
820 | - $entities .= \chr($m[$i++]); |
|
821 | - continue; |
|
822 | - } |
|
823 | - if (0xF0 <= $m[$i]) { |
|
824 | - $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
|
825 | - } elseif (0xE0 <= $m[$i]) { |
|
826 | - $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
|
827 | - } else { |
|
828 | - $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; |
|
829 | - } |
|
830 | - |
|
831 | - $entities .= '&#'.$c.';'; |
|
832 | - } |
|
833 | - |
|
834 | - return $entities; |
|
835 | - } |
|
836 | - |
|
837 | - private static function title_case(array $s) |
|
838 | - { |
|
839 | - return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8').self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8'); |
|
840 | - } |
|
841 | - |
|
842 | - private static function getData($file) |
|
843 | - { |
|
844 | - if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) { |
|
845 | - return require $file; |
|
846 | - } |
|
847 | - |
|
848 | - return false; |
|
849 | - } |
|
850 | - |
|
851 | - private static function getEncoding($encoding) |
|
852 | - { |
|
853 | - if (null === $encoding) { |
|
854 | - return self::$internalEncoding; |
|
855 | - } |
|
856 | - |
|
857 | - if ('UTF-8' === $encoding) { |
|
858 | - return 'UTF-8'; |
|
859 | - } |
|
860 | - |
|
861 | - $encoding = strtoupper($encoding); |
|
862 | - |
|
863 | - if ('8BIT' === $encoding || 'BINARY' === $encoding) { |
|
864 | - return 'CP850'; |
|
865 | - } |
|
866 | - |
|
867 | - if ('UTF8' === $encoding) { |
|
868 | - return 'UTF-8'; |
|
869 | - } |
|
870 | - |
|
871 | - return $encoding; |
|
872 | - } |
|
70 | + public const MB_CASE_FOLD = \PHP_INT_MAX; |
|
71 | + |
|
72 | + private const CASE_FOLD = [ |
|
73 | + ['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"], |
|
74 | + ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'], |
|
75 | + ]; |
|
76 | + |
|
77 | + private static $encodingList = ['ASCII', 'UTF-8']; |
|
78 | + private static $language = 'neutral'; |
|
79 | + private static $internalEncoding = 'UTF-8'; |
|
80 | + |
|
81 | + public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) |
|
82 | + { |
|
83 | + if (\is_array($fromEncoding) || ($fromEncoding !== null && false !== strpos($fromEncoding, ','))) { |
|
84 | + $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); |
|
85 | + } else { |
|
86 | + $fromEncoding = self::getEncoding($fromEncoding); |
|
87 | + } |
|
88 | + |
|
89 | + $toEncoding = self::getEncoding($toEncoding); |
|
90 | + |
|
91 | + if ('BASE64' === $fromEncoding) { |
|
92 | + $s = base64_decode($s); |
|
93 | + $fromEncoding = $toEncoding; |
|
94 | + } |
|
95 | + |
|
96 | + if ('BASE64' === $toEncoding) { |
|
97 | + return base64_encode($s); |
|
98 | + } |
|
99 | + |
|
100 | + if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) { |
|
101 | + if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) { |
|
102 | + $fromEncoding = 'Windows-1252'; |
|
103 | + } |
|
104 | + if ('UTF-8' !== $fromEncoding) { |
|
105 | + $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s); |
|
106 | + } |
|
107 | + |
|
108 | + return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s); |
|
109 | + } |
|
110 | + |
|
111 | + if ('HTML-ENTITIES' === $fromEncoding) { |
|
112 | + $s = html_entity_decode($s, \ENT_COMPAT, 'UTF-8'); |
|
113 | + $fromEncoding = 'UTF-8'; |
|
114 | + } |
|
115 | + |
|
116 | + return \iconv($fromEncoding, $toEncoding.'//IGNORE', $s); |
|
117 | + } |
|
118 | + |
|
119 | + public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars) |
|
120 | + { |
|
121 | + $ok = true; |
|
122 | + array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) { |
|
123 | + if (false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) { |
|
124 | + $ok = false; |
|
125 | + } |
|
126 | + }); |
|
127 | + |
|
128 | + return $ok ? $fromEncoding : false; |
|
129 | + } |
|
130 | + |
|
131 | + public static function mb_decode_mimeheader($s) |
|
132 | + { |
|
133 | + return \iconv_mime_decode($s, 2, self::$internalEncoding); |
|
134 | + } |
|
135 | + |
|
136 | + public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null) |
|
137 | + { |
|
138 | + trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING); |
|
139 | + } |
|
140 | + |
|
141 | + public static function mb_decode_numericentity($s, $convmap, $encoding = null) |
|
142 | + { |
|
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 | + |
|
146 | + return null; |
|
147 | + } |
|
148 | + |
|
149 | + if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + if (null !== $encoding && !is_scalar($encoding)) { |
|
154 | + trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
155 | + |
|
156 | + return ''; // Instead of null (cf. mb_encode_numericentity). |
|
157 | + } |
|
158 | + |
|
159 | + $s = (string) $s; |
|
160 | + if ('' === $s) { |
|
161 | + return ''; |
|
162 | + } |
|
163 | + |
|
164 | + $encoding = self::getEncoding($encoding); |
|
165 | + |
|
166 | + if ('UTF-8' === $encoding) { |
|
167 | + $encoding = null; |
|
168 | + if (!preg_match('//u', $s)) { |
|
169 | + $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
170 | + } |
|
171 | + } else { |
|
172 | + $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
173 | + } |
|
174 | + |
|
175 | + $cnt = floor(\count($convmap) / 4) * 4; |
|
176 | + |
|
177 | + for ($i = 0; $i < $cnt; $i += 4) { |
|
178 | + // collector_decode_htmlnumericentity ignores $convmap[$i + 3] |
|
179 | + $convmap[$i] += $convmap[$i + 2]; |
|
180 | + $convmap[$i + 1] += $convmap[$i + 2]; |
|
181 | + } |
|
182 | + |
|
183 | + $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) { |
|
184 | + $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1]; |
|
185 | + for ($i = 0; $i < $cnt; $i += 4) { |
|
186 | + if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { |
|
187 | + return self::mb_chr($c - $convmap[$i + 2]); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + return $m[0]; |
|
192 | + }, $s); |
|
193 | + |
|
194 | + if (null === $encoding) { |
|
195 | + return $s; |
|
196 | + } |
|
197 | + |
|
198 | + return \iconv('UTF-8', $encoding.'//IGNORE', $s); |
|
199 | + } |
|
200 | + |
|
201 | + public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) |
|
202 | + { |
|
203 | + if (null !== $s && !is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) { |
|
204 | + trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
205 | + |
|
206 | + return null; |
|
207 | + } |
|
208 | + |
|
209 | + if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { |
|
210 | + return false; |
|
211 | + } |
|
212 | + |
|
213 | + if (null !== $encoding && !is_scalar($encoding)) { |
|
214 | + trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
215 | + |
|
216 | + return null; // Instead of '' (cf. mb_decode_numericentity). |
|
217 | + } |
|
218 | + |
|
219 | + if (null !== $is_hex && !is_scalar($is_hex)) { |
|
220 | + trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', \E_USER_WARNING); |
|
221 | + |
|
222 | + return null; |
|
223 | + } |
|
224 | + |
|
225 | + $s = (string) $s; |
|
226 | + if ('' === $s) { |
|
227 | + return ''; |
|
228 | + } |
|
229 | + |
|
230 | + $encoding = self::getEncoding($encoding); |
|
231 | + |
|
232 | + if ('UTF-8' === $encoding) { |
|
233 | + $encoding = null; |
|
234 | + if (!preg_match('//u', $s)) { |
|
235 | + $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
236 | + } |
|
237 | + } else { |
|
238 | + $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
239 | + } |
|
240 | + |
|
241 | + static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4]; |
|
242 | + |
|
243 | + $cnt = floor(\count($convmap) / 4) * 4; |
|
244 | + $i = 0; |
|
245 | + $len = \strlen($s); |
|
246 | + $result = ''; |
|
247 | + |
|
248 | + while ($i < $len) { |
|
249 | + $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
|
250 | + $uchr = substr($s, $i, $ulen); |
|
251 | + $i += $ulen; |
|
252 | + $c = self::mb_ord($uchr); |
|
253 | + |
|
254 | + for ($j = 0; $j < $cnt; $j += 4) { |
|
255 | + if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) { |
|
256 | + $cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3]; |
|
257 | + $result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';'; |
|
258 | + continue 2; |
|
259 | + } |
|
260 | + } |
|
261 | + $result .= $uchr; |
|
262 | + } |
|
263 | + |
|
264 | + if (null === $encoding) { |
|
265 | + return $result; |
|
266 | + } |
|
267 | + |
|
268 | + return \iconv('UTF-8', $encoding.'//IGNORE', $result); |
|
269 | + } |
|
270 | + |
|
271 | + public static function mb_convert_case($s, $mode, $encoding = null) |
|
272 | + { |
|
273 | + $s = (string) $s; |
|
274 | + if ('' === $s) { |
|
275 | + return ''; |
|
276 | + } |
|
277 | + |
|
278 | + $encoding = self::getEncoding($encoding); |
|
279 | + |
|
280 | + if ('UTF-8' === $encoding) { |
|
281 | + $encoding = null; |
|
282 | + if (!preg_match('//u', $s)) { |
|
283 | + $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
284 | + } |
|
285 | + } else { |
|
286 | + $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
287 | + } |
|
288 | + |
|
289 | + if (\MB_CASE_TITLE == $mode) { |
|
290 | + static $titleRegexp = null; |
|
291 | + if (null === $titleRegexp) { |
|
292 | + $titleRegexp = self::getData('titleCaseRegexp'); |
|
293 | + } |
|
294 | + $s = preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s); |
|
295 | + } else { |
|
296 | + if (\MB_CASE_UPPER == $mode) { |
|
297 | + static $upper = null; |
|
298 | + if (null === $upper) { |
|
299 | + $upper = self::getData('upperCase'); |
|
300 | + } |
|
301 | + $map = $upper; |
|
302 | + } else { |
|
303 | + if (self::MB_CASE_FOLD === $mode) { |
|
304 | + $s = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s); |
|
305 | + } |
|
306 | + |
|
307 | + static $lower = null; |
|
308 | + if (null === $lower) { |
|
309 | + $lower = self::getData('lowerCase'); |
|
310 | + } |
|
311 | + $map = $lower; |
|
312 | + } |
|
313 | + |
|
314 | + static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4]; |
|
315 | + |
|
316 | + $i = 0; |
|
317 | + $len = \strlen($s); |
|
318 | + |
|
319 | + while ($i < $len) { |
|
320 | + $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
|
321 | + $uchr = substr($s, $i, $ulen); |
|
322 | + $i += $ulen; |
|
323 | + |
|
324 | + if (isset($map[$uchr])) { |
|
325 | + $uchr = $map[$uchr]; |
|
326 | + $nlen = \strlen($uchr); |
|
327 | + |
|
328 | + if ($nlen == $ulen) { |
|
329 | + $nlen = $i; |
|
330 | + do { |
|
331 | + $s[--$nlen] = $uchr[--$ulen]; |
|
332 | + } while ($ulen); |
|
333 | + } else { |
|
334 | + $s = substr_replace($s, $uchr, $i - $ulen, $ulen); |
|
335 | + $len += $nlen - $ulen; |
|
336 | + $i += $nlen - $ulen; |
|
337 | + } |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + if (null === $encoding) { |
|
343 | + return $s; |
|
344 | + } |
|
345 | + |
|
346 | + return \iconv('UTF-8', $encoding.'//IGNORE', $s); |
|
347 | + } |
|
348 | + |
|
349 | + public static function mb_internal_encoding($encoding = null) |
|
350 | + { |
|
351 | + if (null === $encoding) { |
|
352 | + return self::$internalEncoding; |
|
353 | + } |
|
354 | + |
|
355 | + $normalizedEncoding = self::getEncoding($encoding); |
|
356 | + |
|
357 | + if ('UTF-8' === $normalizedEncoding || false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) { |
|
358 | + self::$internalEncoding = $normalizedEncoding; |
|
359 | + |
|
360 | + return true; |
|
361 | + } |
|
362 | + |
|
363 | + if (80000 > \PHP_VERSION_ID) { |
|
364 | + return false; |
|
365 | + } |
|
366 | + |
|
367 | + throw new \ValueError(sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
|
368 | + } |
|
369 | + |
|
370 | + public static function mb_language($lang = null) |
|
371 | + { |
|
372 | + if (null === $lang) { |
|
373 | + return self::$language; |
|
374 | + } |
|
375 | + |
|
376 | + switch ($normalizedLang = strtolower($lang)) { |
|
377 | + case 'uni': |
|
378 | + case 'neutral': |
|
379 | + self::$language = $normalizedLang; |
|
380 | + |
|
381 | + return true; |
|
382 | + } |
|
383 | + |
|
384 | + if (80000 > \PHP_VERSION_ID) { |
|
385 | + return false; |
|
386 | + } |
|
387 | + |
|
388 | + throw new \ValueError(sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang)); |
|
389 | + } |
|
390 | + |
|
391 | + public static function mb_list_encodings() |
|
392 | + { |
|
393 | + return ['UTF-8']; |
|
394 | + } |
|
395 | + |
|
396 | + public static function mb_encoding_aliases($encoding) |
|
397 | + { |
|
398 | + switch (strtoupper($encoding)) { |
|
399 | + case 'UTF8': |
|
400 | + case 'UTF-8': |
|
401 | + return ['utf8']; |
|
402 | + } |
|
403 | + |
|
404 | + return false; |
|
405 | + } |
|
406 | + |
|
407 | + public static function mb_check_encoding($var = null, $encoding = null) |
|
408 | + { |
|
409 | + if (null === $encoding) { |
|
410 | + if (null === $var) { |
|
411 | + return false; |
|
412 | + } |
|
413 | + $encoding = self::$internalEncoding; |
|
414 | + } |
|
415 | + |
|
416 | + return self::mb_detect_encoding($var, [$encoding]) || false !== @\iconv($encoding, $encoding, $var); |
|
417 | + } |
|
418 | + |
|
419 | + public static function mb_detect_encoding($str, $encodingList = null, $strict = false) |
|
420 | + { |
|
421 | + if (null === $encodingList) { |
|
422 | + $encodingList = self::$encodingList; |
|
423 | + } else { |
|
424 | + if (!\is_array($encodingList)) { |
|
425 | + $encodingList = array_map('trim', explode(',', $encodingList)); |
|
426 | + } |
|
427 | + $encodingList = array_map('strtoupper', $encodingList); |
|
428 | + } |
|
429 | + |
|
430 | + foreach ($encodingList as $enc) { |
|
431 | + switch ($enc) { |
|
432 | + case 'ASCII': |
|
433 | + if (!preg_match('/[\x80-\xFF]/', $str)) { |
|
434 | + return $enc; |
|
435 | + } |
|
436 | + break; |
|
437 | + |
|
438 | + case 'UTF8': |
|
439 | + case 'UTF-8': |
|
440 | + if (preg_match('//u', $str)) { |
|
441 | + return 'UTF-8'; |
|
442 | + } |
|
443 | + break; |
|
444 | + |
|
445 | + default: |
|
446 | + if (0 === strncmp($enc, 'ISO-8859-', 9)) { |
|
447 | + return $enc; |
|
448 | + } |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + return false; |
|
453 | + } |
|
454 | + |
|
455 | + public static function mb_detect_order($encodingList = null) |
|
456 | + { |
|
457 | + if (null === $encodingList) { |
|
458 | + return self::$encodingList; |
|
459 | + } |
|
460 | + |
|
461 | + if (!\is_array($encodingList)) { |
|
462 | + $encodingList = array_map('trim', explode(',', $encodingList)); |
|
463 | + } |
|
464 | + $encodingList = array_map('strtoupper', $encodingList); |
|
465 | + |
|
466 | + foreach ($encodingList as $enc) { |
|
467 | + switch ($enc) { |
|
468 | + default: |
|
469 | + if (strncmp($enc, 'ISO-8859-', 9)) { |
|
470 | + return false; |
|
471 | + } |
|
472 | + // no break |
|
473 | + case 'ASCII': |
|
474 | + case 'UTF8': |
|
475 | + case 'UTF-8': |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + self::$encodingList = $encodingList; |
|
480 | + |
|
481 | + return true; |
|
482 | + } |
|
483 | + |
|
484 | + public static function mb_strlen($s, $encoding = null) |
|
485 | + { |
|
486 | + $encoding = self::getEncoding($encoding); |
|
487 | + if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
488 | + return \strlen($s); |
|
489 | + } |
|
490 | + |
|
491 | + return @\iconv_strlen($s, $encoding); |
|
492 | + } |
|
493 | + |
|
494 | + public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) |
|
495 | + { |
|
496 | + $encoding = self::getEncoding($encoding); |
|
497 | + if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
498 | + return strpos($haystack, $needle, $offset); |
|
499 | + } |
|
500 | + |
|
501 | + $needle = (string) $needle; |
|
502 | + if ('' === $needle) { |
|
503 | + if (80000 > \PHP_VERSION_ID) { |
|
504 | + trigger_error(__METHOD__.': Empty delimiter', \E_USER_WARNING); |
|
505 | + |
|
506 | + return false; |
|
507 | + } |
|
508 | + |
|
509 | + return 0; |
|
510 | + } |
|
511 | + |
|
512 | + return \iconv_strpos($haystack, $needle, $offset, $encoding); |
|
513 | + } |
|
514 | + |
|
515 | + public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) |
|
516 | + { |
|
517 | + $encoding = self::getEncoding($encoding); |
|
518 | + if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
519 | + return strrpos($haystack, $needle, $offset); |
|
520 | + } |
|
521 | + |
|
522 | + if ($offset != (int) $offset) { |
|
523 | + $offset = 0; |
|
524 | + } elseif ($offset = (int) $offset) { |
|
525 | + if ($offset < 0) { |
|
526 | + if (0 > $offset += self::mb_strlen($needle)) { |
|
527 | + $haystack = self::mb_substr($haystack, 0, $offset, $encoding); |
|
528 | + } |
|
529 | + $offset = 0; |
|
530 | + } else { |
|
531 | + $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding); |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + $pos = '' !== $needle || 80000 > \PHP_VERSION_ID |
|
536 | + ? \iconv_strrpos($haystack, $needle, $encoding) |
|
537 | + : self::mb_strlen($haystack, $encoding); |
|
538 | + |
|
539 | + return false !== $pos ? $offset + $pos : false; |
|
540 | + } |
|
541 | + |
|
542 | + public static function mb_str_split($string, $split_length = 1, $encoding = null) |
|
543 | + { |
|
544 | + if (null !== $string && !is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) { |
|
545 | + trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', \E_USER_WARNING); |
|
546 | + |
|
547 | + return null; |
|
548 | + } |
|
549 | + |
|
550 | + if (1 > $split_length = (int) $split_length) { |
|
551 | + if (80000 > \PHP_VERSION_ID) { |
|
552 | + trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING); |
|
553 | + return false; |
|
554 | + } |
|
555 | + |
|
556 | + throw new \ValueError('Argument #2 ($length) must be greater than 0'); |
|
557 | + } |
|
558 | + |
|
559 | + if (null === $encoding) { |
|
560 | + $encoding = mb_internal_encoding(); |
|
561 | + } |
|
562 | + |
|
563 | + if ('UTF-8' === $encoding = self::getEncoding($encoding)) { |
|
564 | + $rx = '/('; |
|
565 | + while (65535 < $split_length) { |
|
566 | + $rx .= '.{65535}'; |
|
567 | + $split_length -= 65535; |
|
568 | + } |
|
569 | + $rx .= '.{'.$split_length.'})/us'; |
|
570 | + |
|
571 | + return preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY); |
|
572 | + } |
|
573 | + |
|
574 | + $result = []; |
|
575 | + $length = mb_strlen($string, $encoding); |
|
576 | + |
|
577 | + for ($i = 0; $i < $length; $i += $split_length) { |
|
578 | + $result[] = mb_substr($string, $i, $split_length, $encoding); |
|
579 | + } |
|
580 | + |
|
581 | + return $result; |
|
582 | + } |
|
583 | + |
|
584 | + public static function mb_strtolower($s, $encoding = null) |
|
585 | + { |
|
586 | + return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding); |
|
587 | + } |
|
588 | + |
|
589 | + public static function mb_strtoupper($s, $encoding = null) |
|
590 | + { |
|
591 | + return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding); |
|
592 | + } |
|
593 | + |
|
594 | + public static function mb_substitute_character($c = null) |
|
595 | + { |
|
596 | + if (null === $c) { |
|
597 | + return 'none'; |
|
598 | + } |
|
599 | + if (0 === strcasecmp($c, 'none')) { |
|
600 | + return true; |
|
601 | + } |
|
602 | + if (80000 > \PHP_VERSION_ID) { |
|
603 | + return false; |
|
604 | + } |
|
605 | + if (\is_int($c) || 'long' === $c || 'entity' === $c) { |
|
606 | + return false; |
|
607 | + } |
|
608 | + |
|
609 | + throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); |
|
610 | + } |
|
611 | + |
|
612 | + public static function mb_substr($s, $start, $length = null, $encoding = null) |
|
613 | + { |
|
614 | + $encoding = self::getEncoding($encoding); |
|
615 | + if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
616 | + return (string) substr($s, $start, null === $length ? 2147483647 : $length); |
|
617 | + } |
|
618 | + |
|
619 | + if ($start < 0) { |
|
620 | + $start = \iconv_strlen($s, $encoding) + $start; |
|
621 | + if ($start < 0) { |
|
622 | + $start = 0; |
|
623 | + } |
|
624 | + } |
|
625 | + |
|
626 | + if (null === $length) { |
|
627 | + $length = 2147483647; |
|
628 | + } elseif ($length < 0) { |
|
629 | + $length = \iconv_strlen($s, $encoding) + $length - $start; |
|
630 | + if ($length < 0) { |
|
631 | + return ''; |
|
632 | + } |
|
633 | + } |
|
634 | + |
|
635 | + return (string) \iconv_substr($s, $start, $length, $encoding); |
|
636 | + } |
|
637 | + |
|
638 | + public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) |
|
639 | + { |
|
640 | + $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); |
|
641 | + $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); |
|
642 | + |
|
643 | + return self::mb_strpos($haystack, $needle, $offset, $encoding); |
|
644 | + } |
|
645 | + |
|
646 | + public static function mb_stristr($haystack, $needle, $part = false, $encoding = null) |
|
647 | + { |
|
648 | + $pos = self::mb_stripos($haystack, $needle, 0, $encoding); |
|
649 | + |
|
650 | + return self::getSubpart($pos, $part, $haystack, $encoding); |
|
651 | + } |
|
652 | + |
|
653 | + public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null) |
|
654 | + { |
|
655 | + $encoding = self::getEncoding($encoding); |
|
656 | + if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
657 | + $pos = strrpos($haystack, $needle); |
|
658 | + } else { |
|
659 | + $needle = self::mb_substr($needle, 0, 1, $encoding); |
|
660 | + $pos = \iconv_strrpos($haystack, $needle, $encoding); |
|
661 | + } |
|
662 | + |
|
663 | + return self::getSubpart($pos, $part, $haystack, $encoding); |
|
664 | + } |
|
665 | + |
|
666 | + public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null) |
|
667 | + { |
|
668 | + $needle = self::mb_substr($needle, 0, 1, $encoding); |
|
669 | + $pos = self::mb_strripos($haystack, $needle, $encoding); |
|
670 | + |
|
671 | + return self::getSubpart($pos, $part, $haystack, $encoding); |
|
672 | + } |
|
673 | + |
|
674 | + public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) |
|
675 | + { |
|
676 | + $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); |
|
677 | + $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); |
|
678 | + |
|
679 | + return self::mb_strrpos($haystack, $needle, $offset, $encoding); |
|
680 | + } |
|
681 | + |
|
682 | + public static function mb_strstr($haystack, $needle, $part = false, $encoding = null) |
|
683 | + { |
|
684 | + $pos = strpos($haystack, $needle); |
|
685 | + if (false === $pos) { |
|
686 | + return false; |
|
687 | + } |
|
688 | + if ($part) { |
|
689 | + return substr($haystack, 0, $pos); |
|
690 | + } |
|
691 | + |
|
692 | + return substr($haystack, $pos); |
|
693 | + } |
|
694 | + |
|
695 | + public static function mb_get_info($type = 'all') |
|
696 | + { |
|
697 | + $info = [ |
|
698 | + 'internal_encoding' => self::$internalEncoding, |
|
699 | + 'http_output' => 'pass', |
|
700 | + 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)', |
|
701 | + 'func_overload' => 0, |
|
702 | + 'func_overload_list' => 'no overload', |
|
703 | + 'mail_charset' => 'UTF-8', |
|
704 | + 'mail_header_encoding' => 'BASE64', |
|
705 | + 'mail_body_encoding' => 'BASE64', |
|
706 | + 'illegal_chars' => 0, |
|
707 | + 'encoding_translation' => 'Off', |
|
708 | + 'language' => self::$language, |
|
709 | + 'detect_order' => self::$encodingList, |
|
710 | + 'substitute_character' => 'none', |
|
711 | + 'strict_detection' => 'Off', |
|
712 | + ]; |
|
713 | + |
|
714 | + if ('all' === $type) { |
|
715 | + return $info; |
|
716 | + } |
|
717 | + if (isset($info[$type])) { |
|
718 | + return $info[$type]; |
|
719 | + } |
|
720 | + |
|
721 | + return false; |
|
722 | + } |
|
723 | + |
|
724 | + public static function mb_http_input($type = '') |
|
725 | + { |
|
726 | + return false; |
|
727 | + } |
|
728 | + |
|
729 | + public static function mb_http_output($encoding = null) |
|
730 | + { |
|
731 | + return null !== $encoding ? 'pass' === $encoding : 'pass'; |
|
732 | + } |
|
733 | + |
|
734 | + public static function mb_strwidth($s, $encoding = null) |
|
735 | + { |
|
736 | + $encoding = self::getEncoding($encoding); |
|
737 | + |
|
738 | + if ('UTF-8' !== $encoding) { |
|
739 | + $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
740 | + } |
|
741 | + |
|
742 | + $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); |
|
743 | + |
|
744 | + return ($wide << 1) + \iconv_strlen($s, 'UTF-8'); |
|
745 | + } |
|
746 | + |
|
747 | + public static function mb_substr_count($haystack, $needle, $encoding = null) |
|
748 | + { |
|
749 | + return substr_count($haystack, $needle); |
|
750 | + } |
|
751 | + |
|
752 | + public static function mb_output_handler($contents, $status) |
|
753 | + { |
|
754 | + return $contents; |
|
755 | + } |
|
756 | + |
|
757 | + public static function mb_chr($code, $encoding = null) |
|
758 | + { |
|
759 | + if (0x80 > $code %= 0x200000) { |
|
760 | + $s = \chr($code); |
|
761 | + } elseif (0x800 > $code) { |
|
762 | + $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); |
|
763 | + } elseif (0x10000 > $code) { |
|
764 | + $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
765 | + } else { |
|
766 | + $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
767 | + } |
|
768 | + |
|
769 | + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
|
770 | + $s = mb_convert_encoding($s, $encoding, 'UTF-8'); |
|
771 | + } |
|
772 | + |
|
773 | + return $s; |
|
774 | + } |
|
775 | + |
|
776 | + public static function mb_ord($s, $encoding = null) |
|
777 | + { |
|
778 | + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
|
779 | + $s = mb_convert_encoding($s, 'UTF-8', $encoding); |
|
780 | + } |
|
781 | + |
|
782 | + if (1 === \strlen($s)) { |
|
783 | + return \ord($s); |
|
784 | + } |
|
785 | + |
|
786 | + $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; |
|
787 | + if (0xF0 <= $code) { |
|
788 | + return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; |
|
789 | + } |
|
790 | + if (0xE0 <= $code) { |
|
791 | + return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; |
|
792 | + } |
|
793 | + if (0xC0 <= $code) { |
|
794 | + return (($code - 0xC0) << 6) + $s[2] - 0x80; |
|
795 | + } |
|
796 | + |
|
797 | + return $code; |
|
798 | + } |
|
799 | + |
|
800 | + private static function getSubpart($pos, $part, $haystack, $encoding) |
|
801 | + { |
|
802 | + if (false === $pos) { |
|
803 | + return false; |
|
804 | + } |
|
805 | + if ($part) { |
|
806 | + return self::mb_substr($haystack, 0, $pos, $encoding); |
|
807 | + } |
|
808 | + |
|
809 | + return self::mb_substr($haystack, $pos, null, $encoding); |
|
810 | + } |
|
811 | + |
|
812 | + private static function html_encoding_callback(array $m) |
|
813 | + { |
|
814 | + $i = 1; |
|
815 | + $entities = ''; |
|
816 | + $m = unpack('C*', htmlentities($m[0], \ENT_COMPAT, 'UTF-8')); |
|
817 | + |
|
818 | + while (isset($m[$i])) { |
|
819 | + if (0x80 > $m[$i]) { |
|
820 | + $entities .= \chr($m[$i++]); |
|
821 | + continue; |
|
822 | + } |
|
823 | + if (0xF0 <= $m[$i]) { |
|
824 | + $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
|
825 | + } elseif (0xE0 <= $m[$i]) { |
|
826 | + $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
|
827 | + } else { |
|
828 | + $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; |
|
829 | + } |
|
830 | + |
|
831 | + $entities .= '&#'.$c.';'; |
|
832 | + } |
|
833 | + |
|
834 | + return $entities; |
|
835 | + } |
|
836 | + |
|
837 | + private static function title_case(array $s) |
|
838 | + { |
|
839 | + return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8').self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8'); |
|
840 | + } |
|
841 | + |
|
842 | + private static function getData($file) |
|
843 | + { |
|
844 | + if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) { |
|
845 | + return require $file; |
|
846 | + } |
|
847 | + |
|
848 | + return false; |
|
849 | + } |
|
850 | + |
|
851 | + private static function getEncoding($encoding) |
|
852 | + { |
|
853 | + if (null === $encoding) { |
|
854 | + return self::$internalEncoding; |
|
855 | + } |
|
856 | + |
|
857 | + if ('UTF-8' === $encoding) { |
|
858 | + return 'UTF-8'; |
|
859 | + } |
|
860 | + |
|
861 | + $encoding = strtoupper($encoding); |
|
862 | + |
|
863 | + if ('8BIT' === $encoding || 'BINARY' === $encoding) { |
|
864 | + return 'CP850'; |
|
865 | + } |
|
866 | + |
|
867 | + if ('UTF8' === $encoding) { |
|
868 | + return 'UTF-8'; |
|
869 | + } |
|
870 | + |
|
871 | + return $encoding; |
|
872 | + } |
|
873 | 873 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | private const CASE_FOLD = [ |
73 | 73 | ['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"], |
74 | - ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'], |
|
74 | + ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'], |
|
75 | 75 | ]; |
76 | 76 | |
77 | 77 | private static $encodingList = ['ASCII', 'UTF-8']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars) |
120 | 120 | { |
121 | 121 | $ok = true; |
122 | - array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) { |
|
122 | + array_walk_recursive($vars, function(&$v) use (&$ok, $toEncoding, $fromEncoding) { |
|
123 | 123 | if (false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) { |
124 | 124 | $ok = false; |
125 | 125 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | if (null !== $encoding && !is_scalar($encoding)) { |
154 | 154 | trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
155 | 155 | |
156 | - return ''; // Instead of null (cf. mb_encode_numericentity). |
|
156 | + return ''; // Instead of null (cf. mb_encode_numericentity). |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | $s = (string) $s; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $convmap[$i + 1] += $convmap[$i + 2]; |
181 | 181 | } |
182 | 182 | |
183 | - $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) { |
|
183 | + $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function(array $m) use ($cnt, $convmap) { |
|
184 | 184 | $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1]; |
185 | 185 | for ($i = 0; $i < $cnt; $i += 4) { |
186 | 186 | if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | if (null !== $encoding && !is_scalar($encoding)) { |
214 | 214 | trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
215 | 215 | |
216 | - return null; // Instead of '' (cf. mb_decode_numericentity). |
|
216 | + return null; // Instead of '' (cf. mb_decode_numericentity). |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | if (null !== $is_hex && !is_scalar($is_hex)) { |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -return array ( |
|
3 | +return array( |
|
4 | 4 | 'a' => 'A', |
5 | 5 | 'b' => 'B', |
6 | 6 | 'c' => 'C', |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -return array ( |
|
3 | +return array( |
|
4 | 4 | 'A' => 'a', |
5 | 5 | 'B' => 'b', |
6 | 6 | 'C' => 'c', |
@@ -12,132 +12,132 @@ |
||
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | 14 | if (!function_exists('mb_convert_encoding')) { |
15 | - function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } |
|
15 | + function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } |
|
16 | 16 | } |
17 | 17 | if (!function_exists('mb_decode_mimeheader')) { |
18 | - function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); } |
|
18 | + function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); } |
|
19 | 19 | } |
20 | 20 | if (!function_exists('mb_encode_mimeheader')) { |
21 | - function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); } |
|
21 | + function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); } |
|
22 | 22 | } |
23 | 23 | if (!function_exists('mb_decode_numericentity')) { |
24 | - function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); } |
|
24 | + function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); } |
|
25 | 25 | } |
26 | 26 | if (!function_exists('mb_encode_numericentity')) { |
27 | - function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); } |
|
27 | + function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); } |
|
28 | 28 | } |
29 | 29 | if (!function_exists('mb_convert_case')) { |
30 | - function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); } |
|
30 | + function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); } |
|
31 | 31 | } |
32 | 32 | if (!function_exists('mb_internal_encoding')) { |
33 | - function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } |
|
33 | + function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } |
|
34 | 34 | } |
35 | 35 | if (!function_exists('mb_language')) { |
36 | - function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); } |
|
36 | + function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); } |
|
37 | 37 | } |
38 | 38 | if (!function_exists('mb_list_encodings')) { |
39 | - function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } |
|
39 | + function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } |
|
40 | 40 | } |
41 | 41 | if (!function_exists('mb_encoding_aliases')) { |
42 | - function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); } |
|
42 | + function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); } |
|
43 | 43 | } |
44 | 44 | if (!function_exists('mb_check_encoding')) { |
45 | - function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
45 | + function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
46 | 46 | } |
47 | 47 | if (!function_exists('mb_detect_encoding')) { |
48 | - function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } |
|
48 | + function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } |
|
49 | 49 | } |
50 | 50 | if (!function_exists('mb_detect_order')) { |
51 | - function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } |
|
51 | + function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } |
|
52 | 52 | } |
53 | 53 | if (!function_exists('mb_parse_str')) { |
54 | - function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; } |
|
54 | + function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; } |
|
55 | 55 | } |
56 | 56 | if (!function_exists('mb_strlen')) { |
57 | - function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); } |
|
57 | + function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); } |
|
58 | 58 | } |
59 | 59 | if (!function_exists('mb_strpos')) { |
60 | - function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
60 | + function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
61 | 61 | } |
62 | 62 | if (!function_exists('mb_strtolower')) { |
63 | - function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); } |
|
63 | + function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); } |
|
64 | 64 | } |
65 | 65 | if (!function_exists('mb_strtoupper')) { |
66 | - function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); } |
|
66 | + function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); } |
|
67 | 67 | } |
68 | 68 | if (!function_exists('mb_substitute_character')) { |
69 | - function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
69 | + function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
70 | 70 | } |
71 | 71 | if (!function_exists('mb_substr')) { |
72 | - function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); } |
|
72 | + function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); } |
|
73 | 73 | } |
74 | 74 | if (!function_exists('mb_stripos')) { |
75 | - function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
75 | + function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
76 | 76 | } |
77 | 77 | if (!function_exists('mb_stristr')) { |
78 | - function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
78 | + function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
79 | 79 | } |
80 | 80 | if (!function_exists('mb_strrchr')) { |
81 | - function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
81 | + function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
82 | 82 | } |
83 | 83 | if (!function_exists('mb_strrichr')) { |
84 | - function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
84 | + function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
85 | 85 | } |
86 | 86 | if (!function_exists('mb_strripos')) { |
87 | - function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
87 | + function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
88 | 88 | } |
89 | 89 | if (!function_exists('mb_strrpos')) { |
90 | - function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
90 | + function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
91 | 91 | } |
92 | 92 | if (!function_exists('mb_strstr')) { |
93 | - function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
93 | + function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
94 | 94 | } |
95 | 95 | if (!function_exists('mb_get_info')) { |
96 | - function mb_get_info(?string $type = 'all'): array|string|int|false { return p\Mbstring::mb_get_info((string) $type); } |
|
96 | + function mb_get_info(?string $type = 'all'): array|string|int|false { return p\Mbstring::mb_get_info((string) $type); } |
|
97 | 97 | } |
98 | 98 | if (!function_exists('mb_http_output')) { |
99 | - function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } |
|
99 | + function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } |
|
100 | 100 | } |
101 | 101 | if (!function_exists('mb_strwidth')) { |
102 | - function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); } |
|
102 | + function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); } |
|
103 | 103 | } |
104 | 104 | if (!function_exists('mb_substr_count')) { |
105 | - function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); } |
|
105 | + function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); } |
|
106 | 106 | } |
107 | 107 | if (!function_exists('mb_output_handler')) { |
108 | - function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); } |
|
108 | + function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); } |
|
109 | 109 | } |
110 | 110 | if (!function_exists('mb_http_input')) { |
111 | - function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } |
|
111 | + function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | if (!function_exists('mb_convert_variables')) { |
115 | - function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } |
|
115 | + function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | if (!function_exists('mb_ord')) { |
119 | - function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); } |
|
119 | + function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); } |
|
120 | 120 | } |
121 | 121 | if (!function_exists('mb_chr')) { |
122 | - function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } |
|
122 | + function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } |
|
123 | 123 | } |
124 | 124 | if (!function_exists('mb_scrub')) { |
125 | - function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); } |
|
125 | + function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); } |
|
126 | 126 | } |
127 | 127 | if (!function_exists('mb_str_split')) { |
128 | - function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); } |
|
128 | + function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); } |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | if (extension_loaded('mbstring')) { |
132 | - return; |
|
132 | + return; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | if (!defined('MB_CASE_UPPER')) { |
136 | - define('MB_CASE_UPPER', 0); |
|
136 | + define('MB_CASE_UPPER', 0); |
|
137 | 137 | } |
138 | 138 | if (!defined('MB_CASE_LOWER')) { |
139 | - define('MB_CASE_LOWER', 1); |
|
139 | + define('MB_CASE_LOWER', 1); |
|
140 | 140 | } |
141 | 141 | if (!defined('MB_CASE_TITLE')) { |
142 | - define('MB_CASE_TITLE', 2); |
|
142 | + define('MB_CASE_TITLE', 2); |
|
143 | 143 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | 14 | if (!function_exists('mb_convert_encoding')) { |
15 | - function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } |
|
15 | + function mb_convert_encoding(array | string | null $string, ?string $to_encoding, array | string | null $from_encoding = null): array | string | false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } |
|
16 | 16 | } |
17 | 17 | if (!function_exists('mb_decode_mimeheader')) { |
18 | 18 | function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); } |
31 | 31 | } |
32 | 32 | if (!function_exists('mb_internal_encoding')) { |
33 | - function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } |
|
33 | + function mb_internal_encoding(?string $encoding = null): string | bool { return p\Mbstring::mb_internal_encoding($encoding); } |
|
34 | 34 | } |
35 | 35 | if (!function_exists('mb_language')) { |
36 | - function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); } |
|
36 | + function mb_language(?string $language = null): string | bool { return p\Mbstring::mb_language($language); } |
|
37 | 37 | } |
38 | 38 | if (!function_exists('mb_list_encodings')) { |
39 | 39 | function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); } |
43 | 43 | } |
44 | 44 | if (!function_exists('mb_check_encoding')) { |
45 | - function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
45 | + function mb_check_encoding(array | string | null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
46 | 46 | } |
47 | 47 | if (!function_exists('mb_detect_encoding')) { |
48 | - function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } |
|
48 | + function mb_detect_encoding(?string $string, array | string | null $encodings = null, ?bool $strict = false): string | false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } |
|
49 | 49 | } |
50 | 50 | if (!function_exists('mb_detect_order')) { |
51 | - function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } |
|
51 | + function mb_detect_order(array | string | null $encoding = null): array | bool { return p\Mbstring::mb_detect_order($encoding); } |
|
52 | 52 | } |
53 | 53 | if (!function_exists('mb_parse_str')) { |
54 | 54 | function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); } |
58 | 58 | } |
59 | 59 | if (!function_exists('mb_strpos')) { |
60 | - function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
60 | + function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int | false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
61 | 61 | } |
62 | 62 | if (!function_exists('mb_strtolower')) { |
63 | 63 | function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); } |
@@ -66,37 +66,37 @@ discard block |
||
66 | 66 | function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); } |
67 | 67 | } |
68 | 68 | if (!function_exists('mb_substitute_character')) { |
69 | - function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
69 | + function mb_substitute_character(string | int | null $substitute_character = null): string | int | bool { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
70 | 70 | } |
71 | 71 | if (!function_exists('mb_substr')) { |
72 | 72 | function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); } |
73 | 73 | } |
74 | 74 | if (!function_exists('mb_stripos')) { |
75 | - function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
75 | + function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int | false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
76 | 76 | } |
77 | 77 | if (!function_exists('mb_stristr')) { |
78 | - function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
78 | + function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string | false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
79 | 79 | } |
80 | 80 | if (!function_exists('mb_strrchr')) { |
81 | - function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
81 | + function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string | false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
82 | 82 | } |
83 | 83 | if (!function_exists('mb_strrichr')) { |
84 | - function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
84 | + function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string | false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
85 | 85 | } |
86 | 86 | if (!function_exists('mb_strripos')) { |
87 | - function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
87 | + function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int | false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
88 | 88 | } |
89 | 89 | if (!function_exists('mb_strrpos')) { |
90 | - function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
90 | + function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int | false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
91 | 91 | } |
92 | 92 | if (!function_exists('mb_strstr')) { |
93 | - function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
93 | + function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string | false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
94 | 94 | } |
95 | 95 | if (!function_exists('mb_get_info')) { |
96 | - function mb_get_info(?string $type = 'all'): array|string|int|false { return p\Mbstring::mb_get_info((string) $type); } |
|
96 | + function mb_get_info(?string $type = 'all'): array | string | int | false { return p\Mbstring::mb_get_info((string) $type); } |
|
97 | 97 | } |
98 | 98 | if (!function_exists('mb_http_output')) { |
99 | - function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } |
|
99 | + function mb_http_output(?string $encoding = null): string | bool { return p\Mbstring::mb_http_output($encoding); } |
|
100 | 100 | } |
101 | 101 | if (!function_exists('mb_strwidth')) { |
102 | 102 | function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); } |
@@ -108,18 +108,18 @@ discard block |
||
108 | 108 | function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); } |
109 | 109 | } |
110 | 110 | if (!function_exists('mb_http_input')) { |
111 | - function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } |
|
111 | + function mb_http_input(?string $type = null): array | string | false { return p\Mbstring::mb_http_input($type); } |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | if (!function_exists('mb_convert_variables')) { |
115 | - function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } |
|
115 | + function mb_convert_variables(?string $to_encoding, array | string | null $from_encoding, mixed &$var, mixed &...$vars): string | false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | if (!function_exists('mb_ord')) { |
119 | - function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); } |
|
119 | + function mb_ord(?string $string, ?string $encoding = null): int | false { return p\Mbstring::mb_ord((string) $string, $encoding); } |
|
120 | 120 | } |
121 | 121 | if (!function_exists('mb_chr')) { |
122 | - function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } |
|
122 | + function mb_chr(?int $codepoint, ?string $encoding = null): string | false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } |
|
123 | 123 | } |
124 | 124 | if (!function_exists('mb_scrub')) { |
125 | 125 | function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); } |
@@ -12,39 +12,39 @@ |
||
12 | 12 | use Symfony\Polyfill\Ctype as p; |
13 | 13 | |
14 | 14 | if (\PHP_VERSION_ID >= 80000) { |
15 | - return require __DIR__.'/bootstrap80.php'; |
|
15 | + return require __DIR__.'/bootstrap80.php'; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | if (!function_exists('ctype_alnum')) { |
19 | - function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } |
|
19 | + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } |
|
20 | 20 | } |
21 | 21 | if (!function_exists('ctype_alpha')) { |
22 | - function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } |
|
22 | + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } |
|
23 | 23 | } |
24 | 24 | if (!function_exists('ctype_cntrl')) { |
25 | - function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } |
|
25 | + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } |
|
26 | 26 | } |
27 | 27 | if (!function_exists('ctype_digit')) { |
28 | - function ctype_digit($text) { return p\Ctype::ctype_digit($text); } |
|
28 | + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } |
|
29 | 29 | } |
30 | 30 | if (!function_exists('ctype_graph')) { |
31 | - function ctype_graph($text) { return p\Ctype::ctype_graph($text); } |
|
31 | + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } |
|
32 | 32 | } |
33 | 33 | if (!function_exists('ctype_lower')) { |
34 | - function ctype_lower($text) { return p\Ctype::ctype_lower($text); } |
|
34 | + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } |
|
35 | 35 | } |
36 | 36 | if (!function_exists('ctype_print')) { |
37 | - function ctype_print($text) { return p\Ctype::ctype_print($text); } |
|
37 | + function ctype_print($text) { return p\Ctype::ctype_print($text); } |
|
38 | 38 | } |
39 | 39 | if (!function_exists('ctype_punct')) { |
40 | - function ctype_punct($text) { return p\Ctype::ctype_punct($text); } |
|
40 | + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } |
|
41 | 41 | } |
42 | 42 | if (!function_exists('ctype_space')) { |
43 | - function ctype_space($text) { return p\Ctype::ctype_space($text); } |
|
43 | + function ctype_space($text) { return p\Ctype::ctype_space($text); } |
|
44 | 44 | } |
45 | 45 | if (!function_exists('ctype_upper')) { |
46 | - function ctype_upper($text) { return p\Ctype::ctype_upper($text); } |
|
46 | + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } |
|
47 | 47 | } |
48 | 48 | if (!function_exists('ctype_xdigit')) { |
49 | - function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } |
|
49 | + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } |
|
50 | 50 | } |
@@ -20,213 +20,213 @@ |
||
20 | 20 | */ |
21 | 21 | final class Ctype |
22 | 22 | { |
23 | - /** |
|
24 | - * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. |
|
25 | - * |
|
26 | - * @see https://php.net/ctype-alnum |
|
27 | - * |
|
28 | - * @param mixed $text |
|
29 | - * |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public static function ctype_alnum($text) |
|
33 | - { |
|
34 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
35 | - |
|
36 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Returns TRUE if every character in text is a letter, FALSE otherwise. |
|
41 | - * |
|
42 | - * @see https://php.net/ctype-alpha |
|
43 | - * |
|
44 | - * @param mixed $text |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function ctype_alpha($text) |
|
49 | - { |
|
50 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
51 | - |
|
52 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. |
|
57 | - * |
|
58 | - * @see https://php.net/ctype-cntrl |
|
59 | - * |
|
60 | - * @param mixed $text |
|
61 | - * |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public static function ctype_cntrl($text) |
|
65 | - { |
|
66 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
67 | - |
|
68 | - return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. |
|
73 | - * |
|
74 | - * @see https://php.net/ctype-digit |
|
75 | - * |
|
76 | - * @param mixed $text |
|
77 | - * |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public static function ctype_digit($text) |
|
81 | - { |
|
82 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
83 | - |
|
84 | - return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. |
|
89 | - * |
|
90 | - * @see https://php.net/ctype-graph |
|
91 | - * |
|
92 | - * @param mixed $text |
|
93 | - * |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - public static function ctype_graph($text) |
|
97 | - { |
|
98 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
99 | - |
|
100 | - return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Returns TRUE if every character in text is a lowercase letter. |
|
105 | - * |
|
106 | - * @see https://php.net/ctype-lower |
|
107 | - * |
|
108 | - * @param mixed $text |
|
109 | - * |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public static function ctype_lower($text) |
|
113 | - { |
|
114 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
115 | - |
|
116 | - return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all. |
|
121 | - * |
|
122 | - * @see https://php.net/ctype-print |
|
123 | - * |
|
124 | - * @param mixed $text |
|
125 | - * |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - public static function ctype_print($text) |
|
129 | - { |
|
130 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
131 | - |
|
132 | - return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. |
|
137 | - * |
|
138 | - * @see https://php.net/ctype-punct |
|
139 | - * |
|
140 | - * @param mixed $text |
|
141 | - * |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - public static function ctype_punct($text) |
|
145 | - { |
|
146 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
147 | - |
|
148 | - return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. |
|
153 | - * |
|
154 | - * @see https://php.net/ctype-space |
|
155 | - * |
|
156 | - * @param mixed $text |
|
157 | - * |
|
158 | - * @return bool |
|
159 | - */ |
|
160 | - public static function ctype_space($text) |
|
161 | - { |
|
162 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
163 | - |
|
164 | - return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns TRUE if every character in text is an uppercase letter. |
|
169 | - * |
|
170 | - * @see https://php.net/ctype-upper |
|
171 | - * |
|
172 | - * @param mixed $text |
|
173 | - * |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function ctype_upper($text) |
|
177 | - { |
|
178 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
179 | - |
|
180 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise. |
|
185 | - * |
|
186 | - * @see https://php.net/ctype-xdigit |
|
187 | - * |
|
188 | - * @param mixed $text |
|
189 | - * |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - public static function ctype_xdigit($text) |
|
193 | - { |
|
194 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
195 | - |
|
196 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Converts integers to their char versions according to normal ctype behaviour, if needed. |
|
201 | - * |
|
202 | - * If an integer between -128 and 255 inclusive is provided, |
|
203 | - * it is interpreted as the ASCII value of a single character |
|
204 | - * (negative values have 256 added in order to allow characters in the Extended ASCII range). |
|
205 | - * Any other integer is interpreted as a string containing the decimal digits of the integer. |
|
206 | - * |
|
207 | - * @param mixed $int |
|
208 | - * @param string $function |
|
209 | - * |
|
210 | - * @return mixed |
|
211 | - */ |
|
212 | - private static function convert_int_to_char_for_ctype($int, $function) |
|
213 | - { |
|
214 | - if (!\is_int($int)) { |
|
215 | - return $int; |
|
216 | - } |
|
217 | - |
|
218 | - if ($int < -128 || $int > 255) { |
|
219 | - return (string) $int; |
|
220 | - } |
|
221 | - |
|
222 | - if (\PHP_VERSION_ID >= 80100) { |
|
223 | - @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); |
|
224 | - } |
|
225 | - |
|
226 | - if ($int < 0) { |
|
227 | - $int += 256; |
|
228 | - } |
|
229 | - |
|
230 | - return \chr($int); |
|
231 | - } |
|
23 | + /** |
|
24 | + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. |
|
25 | + * |
|
26 | + * @see https://php.net/ctype-alnum |
|
27 | + * |
|
28 | + * @param mixed $text |
|
29 | + * |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public static function ctype_alnum($text) |
|
33 | + { |
|
34 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
35 | + |
|
36 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Returns TRUE if every character in text is a letter, FALSE otherwise. |
|
41 | + * |
|
42 | + * @see https://php.net/ctype-alpha |
|
43 | + * |
|
44 | + * @param mixed $text |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function ctype_alpha($text) |
|
49 | + { |
|
50 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
51 | + |
|
52 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. |
|
57 | + * |
|
58 | + * @see https://php.net/ctype-cntrl |
|
59 | + * |
|
60 | + * @param mixed $text |
|
61 | + * |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public static function ctype_cntrl($text) |
|
65 | + { |
|
66 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
67 | + |
|
68 | + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. |
|
73 | + * |
|
74 | + * @see https://php.net/ctype-digit |
|
75 | + * |
|
76 | + * @param mixed $text |
|
77 | + * |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public static function ctype_digit($text) |
|
81 | + { |
|
82 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
83 | + |
|
84 | + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. |
|
89 | + * |
|
90 | + * @see https://php.net/ctype-graph |
|
91 | + * |
|
92 | + * @param mixed $text |
|
93 | + * |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + public static function ctype_graph($text) |
|
97 | + { |
|
98 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
99 | + |
|
100 | + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Returns TRUE if every character in text is a lowercase letter. |
|
105 | + * |
|
106 | + * @see https://php.net/ctype-lower |
|
107 | + * |
|
108 | + * @param mixed $text |
|
109 | + * |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public static function ctype_lower($text) |
|
113 | + { |
|
114 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
115 | + |
|
116 | + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all. |
|
121 | + * |
|
122 | + * @see https://php.net/ctype-print |
|
123 | + * |
|
124 | + * @param mixed $text |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + public static function ctype_print($text) |
|
129 | + { |
|
130 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
131 | + |
|
132 | + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. |
|
137 | + * |
|
138 | + * @see https://php.net/ctype-punct |
|
139 | + * |
|
140 | + * @param mixed $text |
|
141 | + * |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + public static function ctype_punct($text) |
|
145 | + { |
|
146 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
147 | + |
|
148 | + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. |
|
153 | + * |
|
154 | + * @see https://php.net/ctype-space |
|
155 | + * |
|
156 | + * @param mixed $text |
|
157 | + * |
|
158 | + * @return bool |
|
159 | + */ |
|
160 | + public static function ctype_space($text) |
|
161 | + { |
|
162 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
163 | + |
|
164 | + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns TRUE if every character in text is an uppercase letter. |
|
169 | + * |
|
170 | + * @see https://php.net/ctype-upper |
|
171 | + * |
|
172 | + * @param mixed $text |
|
173 | + * |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function ctype_upper($text) |
|
177 | + { |
|
178 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
179 | + |
|
180 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise. |
|
185 | + * |
|
186 | + * @see https://php.net/ctype-xdigit |
|
187 | + * |
|
188 | + * @param mixed $text |
|
189 | + * |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + public static function ctype_xdigit($text) |
|
193 | + { |
|
194 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
195 | + |
|
196 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Converts integers to their char versions according to normal ctype behaviour, if needed. |
|
201 | + * |
|
202 | + * If an integer between -128 and 255 inclusive is provided, |
|
203 | + * it is interpreted as the ASCII value of a single character |
|
204 | + * (negative values have 256 added in order to allow characters in the Extended ASCII range). |
|
205 | + * Any other integer is interpreted as a string containing the decimal digits of the integer. |
|
206 | + * |
|
207 | + * @param mixed $int |
|
208 | + * @param string $function |
|
209 | + * |
|
210 | + * @return mixed |
|
211 | + */ |
|
212 | + private static function convert_int_to_char_for_ctype($int, $function) |
|
213 | + { |
|
214 | + if (!\is_int($int)) { |
|
215 | + return $int; |
|
216 | + } |
|
217 | + |
|
218 | + if ($int < -128 || $int > 255) { |
|
219 | + return (string) $int; |
|
220 | + } |
|
221 | + |
|
222 | + if (\PHP_VERSION_ID >= 80100) { |
|
223 | + @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); |
|
224 | + } |
|
225 | + |
|
226 | + if ($int < 0) { |
|
227 | + $int += 256; |
|
228 | + } |
|
229 | + |
|
230 | + return \chr($int); |
|
231 | + } |
|
232 | 232 | } |