Ticket #9692: 9692.patch
File 9692.patch, 1.7 KB (added by , 15 years ago) |
---|
-
wp-includes/formatting.php
159 159 /** 160 160 * Checks to see if a string is utf8 encoded. 161 161 * 162 * @author bmorel at ssi dot fr 162 * NOTE: This function checks for 5-Byte sequences, UTF8 163 * has Bytes Sequences with a maximum length of 4. 163 164 * 165 * @author bmorel at ssi dot fr (modified) 164 166 * @since 1.2.1 165 167 * 166 168 * @param string $Str The string to be checked 167 169 * @return bool True if $Str fits a UTF-8 model, false otherwise. 168 170 */ 169 function seems_utf8( $Str) { # by bmorel at ssi dot fr170 $length = strlen($ Str);171 function seems_utf8(&$str) { 172 $length = strlen($str); 171 173 for ($i=0; $i < $length; $i++) { 172 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb 173 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb 174 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb 175 elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb 176 elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb 177 elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b 174 $c = ord($str[$i]); 175 if ($c < 0x80) $n = 0; # 0bbbbbbb 176 elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb 177 elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb 178 elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb 179 elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb 180 elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b 178 181 else return false; # Does not match any model 179 182 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? 180 if ((++$i == $length) || ((ord($ Str[$i]) & 0xC0) != 0x80))181 return false;183 if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) 184 return false; 182 185 } 183 186 } 184 187 return true;