73
73
final class Mbstring
74
74
{
75
75
public const MB_CASE_FOLD = \PHP_INT_MAX ;
76
-
76
+
77
77
private const SIMPLE_CASE_FOLD = [
78
78
['µ ' , 'ſ ' , "\xCD\x85" , 'ς ' , "\xCF\x90" , "\xCF\x91" , "\xCF\x95" , "\xCF\x96" , "\xCF\xB0" , "\xCF\xB1" , "\xCF\xB5" , "\xE1\xBA\x9B" , "\xE1\xBE\xBE" ],
79
79
['μ ' , 's ' , 'ι ' , 'σ ' , 'β ' , 'θ ' , 'φ ' , 'π ' , 'κ ' , 'ρ ' , 'ε ' , "\xE1\xB9\xA1" , 'ι ' ],
80
80
];
81
81
82
+ private const CHARACTERS = " \f\n\r\t\v\x00\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{0085}\u{180E}" ;
83
+
82
84
private static $ encodingList = ['ASCII ' , 'UTF-8 ' ];
83
85
private static $ language = 'neutral ' ;
84
86
private static $ internalEncoding = 'UTF-8 ' ;
85
- private const CHARACTERS = " \f\n\r\t\v\x00\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{0085}\u{180E}" ;
86
87
87
88
public static function mb_convert_encoding ($ s , $ toEncoding , $ fromEncoding = null )
88
89
{
@@ -1005,16 +1006,7 @@ private static function mb_internal_trim(string $regex, string $string, ?string
1005
1006
$ encoding = mb_internal_encoding ();
1006
1007
}
1007
1008
1008
- try {
1009
- $ validEncoding = @mb_check_encoding ('' , $ encoding );
1010
- } catch (\ValueError $ e ) {
1011
- throw new \ValueError (sprintf ('%s(): Argument #3 ($encoding) must be a valid encoding, "%s" given. ' , debug_backtrace ()[1 ]['function ' ], $ encoding ));
1012
- }
1013
-
1014
- // BC for PHP 7.3 and lower
1015
- if (!$ validEncoding ) {
1016
- throw new \ValueError (sprintf ('%s(): Argument #3 ($encoding) must be a valid encoding, "%s" given. ' , debug_backtrace ()[1 ]['function ' ], $ encoding ));
1017
- }
1009
+ self ::assertEncoding ($ encoding , debug_backtrace ()[1 ]['function ' ].'(): Argument #3 ($encoding) must be a valid encoding, "%s" given. ' );
1018
1010
1019
1011
if ('' === $ characters ) {
1020
1012
return null === $ encoding ? $ string : mb_convert_encoding ($ string , $ encoding );
@@ -1025,7 +1017,7 @@ private static function mb_internal_trim(string $regex, string $string, ?string
1025
1017
}
1026
1018
1027
1019
$ regexCharacter = preg_quote ($ characters ?? '' , '/ ' );
1028
- $ regex = sprintf ($ regex , $ regexCharacter , $ regexCharacter );
1020
+ $ regex = sprintf (' / ' . $ regex. ' / ' , $ regexCharacter , $ regexCharacter );
1029
1021
1030
1022
if ('ASCII ' === mb_detect_encoding ($ characters ) && 'ASCII ' === mb_detect_encoding ($ string ) && !empty (array_intersect (str_split (self ::CHARACTERS ), str_split ($ string )))) {
1031
1023
$ options = 'g ' ;
@@ -1034,15 +1026,15 @@ private static function mb_internal_trim(string $regex, string $string, ?string
1034
1026
}
1035
1027
1036
1028
try {
1037
- $ test = mb_ereg_replace ($ regex , "" , $ string , $ options );
1029
+ $ test = preg_replace ($ regex , "" , $ string , $ options );
1038
1030
1039
1031
if (null === $ test ) {
1040
1032
throw new \Exception ();
1041
1033
}
1042
1034
1043
1035
return $ test ;
1044
1036
} catch (\Exception $ e ) {
1045
- return preg_replace (sprintf ( ' /%s/ ' , $ regex) , "" , $ string );
1037
+ return preg_replace ($ regex , "" , $ string );
1046
1038
}
1047
1039
}
1048
1040
0 commit comments