|
12 | 12 | use Exception; |
13 | 13 | use Toolkit\Stdlib\Str\Traits\StringCaseHelperTrait; |
14 | 14 | use Toolkit\Stdlib\Str\Traits\StringCheckHelperTrait; |
| 15 | +use Toolkit\Stdlib\Util\UUID; |
15 | 16 | use function array_map; |
16 | 17 | use function array_merge; |
17 | 18 | use function array_slice; |
|
24 | 25 | use function function_exists; |
25 | 26 | use function hash; |
26 | 27 | use function hex2bin; |
27 | | -use function html_entity_decode; |
28 | 28 | use function implode; |
29 | 29 | use function in_array; |
30 | 30 | use function is_int; |
|
50 | 50 | use function uniqid; |
51 | 51 | use function utf8_decode; |
52 | 52 | use function utf8_encode; |
53 | | -use const ENT_COMPAT; |
54 | 53 | use const PREG_SPLIT_NO_EMPTY; |
55 | 54 | use const STR_PAD_LEFT; |
56 | 55 | use const STR_PAD_RIGHT; |
@@ -101,122 +100,6 @@ public static function padRight($str, $padLen, string $padStr = ' '): string |
101 | 100 | return $padLen > 0 ? str_pad((string)$str, (int)$padLen, $padStr) : (string)$str; |
102 | 101 | } |
103 | 102 |
|
104 | | - //////////////////////////////////////////////////////////////////////// |
105 | | - /// Check Length |
106 | | - //////////////////////////////////////////////////////////////////////// |
107 | | - |
108 | | - /** |
109 | | - * from Symfony |
110 | | - * |
111 | | - * @param string $string |
112 | | - * @return int |
113 | | - */ |
114 | | - public static function len($string): int |
115 | | - { |
116 | | - $string = (string)$string; |
117 | | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
118 | | - return strlen($string); |
119 | | - } |
120 | | - |
121 | | - return mb_strwidth($string, $encoding); |
122 | | - } |
123 | | - |
124 | | - /** |
125 | | - * @param string $str |
126 | | - * @param string $encoding |
127 | | - * |
128 | | - * @return int |
129 | | - */ |
130 | | - public static function len2($str, string $encoding = 'UTF-8'): int |
131 | | - { |
132 | | - $str = (string)$str; |
133 | | - |
134 | | - return function_exists('mb_strlen') ? mb_strlen($str, $encoding) : strlen($str); |
135 | | - } |
136 | | - |
137 | | - /** |
138 | | - * @param string $str |
139 | | - * @param string $encoding |
140 | | - * |
141 | | - * @return int |
142 | | - */ |
143 | | - public static function strlen($str, string $encoding = 'UTF-8'): int |
144 | | - { |
145 | | - $str = html_entity_decode((string)$str, ENT_COMPAT, 'UTF-8'); |
146 | | - |
147 | | - return function_exists('mb_strlen') ? mb_strlen($str, $encoding) : strlen($str); |
148 | | - } |
149 | | - |
150 | | - /** |
151 | | - * @param string $string |
152 | | - * @return int |
153 | | - */ |
154 | | - public static function utf8Len($string): int |
155 | | - { |
156 | | - // strlen: one chinese is 3 char. |
157 | | - // mb_strlen: one chinese is 1 char. |
158 | | - // mb_strwidth: one chinese is 2 char. |
159 | | - return mb_strlen((string)$string, 'utf-8'); |
160 | | - } |
161 | | - |
162 | | - /** |
163 | | - * @param string $string |
164 | | - * @return int |
165 | | - */ |
166 | | - public static function utf8width($string): int |
167 | | - { |
168 | | - // strlen: one chinese is 3 char. |
169 | | - // mb_strlen: one chinese is 1 char. |
170 | | - // mb_strwidth: one chinese is 2 char. |
171 | | - return mb_strwidth((string)$string, 'utf-8'); |
172 | | - } |
173 | | - |
174 | | - /** |
175 | | - * 计算字符长度 |
176 | | - * @param string $str |
177 | | - * @return int |
178 | | - */ |
179 | | - public static function length(string $str): int |
180 | | - { |
181 | | - if ($str === '') { |
182 | | - return 0; |
183 | | - } |
184 | | - |
185 | | - if (function_exists('mb_strlen')) { |
186 | | - return mb_strlen($str, 'utf-8'); |
187 | | - } |
188 | | - |
189 | | - preg_match_all('/./u', $str, $arr); |
190 | | - |
191 | | - return count($arr[0]); |
192 | | - } |
193 | | - |
194 | | - /** |
195 | | - * @from web |
196 | | - * 可以统计中文字符串长度的函数 |
197 | | - * @param string $str 要计算长度的字符串 |
198 | | - * @internal param bool $type 计算长度类型,0(默认)表示一个中文算一个字符,1表示一个中文算两个字符 |
199 | | - * @return int |
200 | | - */ |
201 | | - public static function absLen(string $str): int |
202 | | - { |
203 | | - if (empty($str)) { |
204 | | - return 0; |
205 | | - } |
206 | | - |
207 | | - if (function_exists('mb_strwidth')) { |
208 | | - return mb_strwidth($str, 'utf-8'); |
209 | | - } |
210 | | - |
211 | | - if (function_exists('mb_strlen')) { |
212 | | - return mb_strlen($str, 'utf-8'); |
213 | | - } |
214 | | - |
215 | | - preg_match_all('/./u', $str, $ar); |
216 | | - |
217 | | - return count($ar[0]); |
218 | | - } |
219 | | - |
220 | 103 | //////////////////////////////////////////////////////////// |
221 | 104 | /// Security |
222 | 105 | //////////////////////////////////////////////////////////// |
@@ -283,10 +166,10 @@ public static function genUid(int $length = 7): string |
283 | 166 | * @param null $ns |
284 | 167 | * @return UUID |
285 | 168 | */ |
286 | | - // public static function genUUID($version = 1, $node = null, $ns = null) |
287 | | - // { |
288 | | - // return UUID::generate($version, $node, $ns); |
289 | | - // } |
| 169 | + public static function genUUID($version = 1, $node = null, $ns = null) |
| 170 | + { |
| 171 | + return UUID::generate($version, $node, $ns); |
| 172 | + } |
290 | 173 |
|
291 | 174 | //////////////////////////////////////////////////////////////////////// |
292 | 175 | /// Convert to array |
|
0 commit comments