/var/www/html_sp/wp-content/plugins/loco-translate/src/compat/MbstringExtension.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
 * Placeholder for missing PHP "mbstring" extension.
 * Just avoids fatal errors. Does not actually replace functionality.
 * 
 * If the mbstring library is missing any PO files that aren't UTF-8 encoded will result in parsing failures.
 */
abstract class Loco_compat_MbstringExtension {
    
    public static function 
mb_detect_encoding$str, ?array $encoding_list nullbool $strict false ):string {
        return ! 
$str || preg_match('//u',$str)
         ? 
'UTF-8' 
         
'ISO-8859-1'
         
;
    }

    public static function 
mb_list_encodings():array {
        return [
'UTF-8','ISO-8859-1'];
    }

    public static function 
mb_strlen$str, ?string $encoding null ):int {
        static 
$warned false;
        if( ! 
$warned && preg_match('/[\\x80-\\xFF]/',$str) ){
            
trigger_error('Character counts will be wrong without mbstring extension',E_USER_WARNING);
            
$warned true;
        }
        return 
strlen($str);
    }

    public static function 
mb_convert_encodingstring $strstring $to_encodingstring $from_encoding ){
        if( 
$to_encoding !== $from_encoding && '' !== $str ){
            
// loco_convert_utf8 no longer uses mb_convert_encoding for UTF8->latin1
            
if( '' === $from_encoding || 'ISO-8859-1' === $from_encoding || 'cp1252' === $from_encoding ){
                if( 
'' === $to_encoding || 'UTF-8' === $to_encoding || 'US-ASCII' === $to_encoding ){
                    if( 
function_exists('loco_fix_utf8') ) {
                        return 
loco_fix_utf8$str );
                    }
                }
            }
            
trigger_error('Unable to convert from '.$from_encoding.' to '.$to_encoding.' without mbstring'E_USER_NOTICE );
        }
        return 
$str;
    }
    
    public static function 
mb_strtolowerstring $str ):string {
        return 
strtolower($str);
    }

}


// @codeCoverageIgnoreStart

if( ! function_exists('mb_detect_encoding') ){
    function 
mb_detect_encodingstring $str '', array $encoding_list = [], bool $strict false ):string {
        return 
Loco_compat_MbstringExtension::mb_detect_encoding$str$encoding_list$strict );
    }
}

if( ! 
function_exists('mb_list_encodings') ){
    function 
mb_list_encodings():array {
        return 
Loco_compat_MbstringExtension::mb_list_encodings();
    }
}

if( ! 
function_exists('mb_strlen') ){
    function 
mb_strlenstring $str, ?string $encoding null ):int {
        return 
Loco_compat_MbstringExtension::mb_strlen$str$encoding );
    }
}

if( ! 
function_exists('mb_convert_encoding') ){
    function 
mb_convert_encodingstring $strstring $to_encoding, ?string $from_encoding null ){
        return 
Loco_compat_MbstringExtension::mb_convert_encoding$str$to_encoding, (string) $from_encoding );
    }
}

if( ! 
function_exists('mb_encoding_aliases') ){
    function 
mb_encoding_aliases(){
        return 
false;
    }
}

if( ! 
function_exists('mb_strtolower') ){
    function 
mb_strtolower$str ){
        return 
Loco_compat_MbstringExtension::mb_strtolower($str);
    }
}