@@ -40,23 +40,25 @@ public function validate($value, Constraint $constraint)
40
40
$ charset = 'UTF-8 ' ;
41
41
}
42
42
43
- if (function_exists ('iconv_strlen ' )) {
44
- $ length = @iconv_strlen ($ stringValue , $ constraint ->charset );
45
- $ invalidCharset = false === $ length ;
43
+ if ('UTF-8 ' === $ charset ) {
44
+ if (!preg_match ('//u ' , $ stringValue )) {
45
+ $ invalidCharset = true ;
46
+ } elseif (function_exists ('utf8_decode ' )) {
47
+ $ length = strlen (utf8_decode ($ stringValue ));
48
+ } else {
49
+ preg_replace ('/./u ' , '' , $ stringValue , -1 , $ length );
50
+ }
46
51
} elseif (function_exists ('mb_strlen ' )) {
47
- if (mb_check_encoding ($ stringValue , $ constraint ->charset )) {
52
+ if (@ mb_check_encoding ($ stringValue , $ constraint ->charset )) {
48
53
$ length = mb_strlen ($ stringValue , $ constraint ->charset );
49
54
} else {
50
55
$ invalidCharset = true ;
51
56
}
52
- } elseif ('UTF-8 ' !== $ charset ) {
53
- $ length = strlen ($ stringValue );
54
- } elseif (!preg_match ('//u ' , $ stringValue )) {
55
- $ invalidCharset = true ;
56
- } elseif (function_exists ('utf8_decode ' )) {
57
- $ length = strlen (utf8_decode ($ stringValue ));
57
+ } elseif (function_exists ('iconv_strlen ' )) {
58
+ $ length = @iconv_strlen ($ stringValue , $ constraint ->charset );
59
+ $ invalidCharset = false === $ length ;
58
60
} else {
59
- preg_replace ( ' /./u ' , '' , $ stringValue , - 1 , $ length );
61
+ $ length = strlen ( $ stringValue );
60
62
}
61
63
62
64
if ($ invalidCharset ) {
0 commit comments