Ticket #5320: strlen.diff
File strlen.diff, 2.0 KB (added by , 18 years ago) |
---|
-
wp-includes/formatting.php
94 94 95 95 96 96 function seems_utf8($Str) { # by bmorel at ssi dot fr 97 for ($i=0; $i<strlen($Str); $i++) { 97 $length = strlen($Str); 98 for ($i=0; $i < $length; $i++) { 98 99 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb 99 100 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb 100 101 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb … … 103 104 elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b 104 105 else return false; # Does not match any model 105 106 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? 106 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))107 if ((++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80)) 107 108 return false; 108 109 } 109 110 } … … 132 133 $unicode = ''; 133 134 $values = array(); 134 135 $num_octets = 1; 136 $unicode_length = 0; 135 137 136 for ($i = 0; $i < strlen( $utf8_string ); $i++ ) { 138 $string_length = strlen( $utf8_string ); 139 for ($i = 0; $i < $string_length; $i++ ) { 137 140 138 141 $value = ord( $utf8_string[ $i ] ); 139 142 140 143 if ( $value < 128 ) { 141 if ( $length && ( strlen($unicode) + 1 >$length ) )144 if ( $length && ( $unicode_length >= $length ) ) 142 145 break; 143 146 $unicode .= chr($value); 147 $unicode_length++; 144 148 } else { 145 149 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; 146 150 147 151 $values[] = $value; 148 152 149 if ( $length && ( (strlen($unicode) + ($num_octets * 3)) > $length ))153 if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length ) 150 154 break; 151 155 if ( count( $values ) == $num_octets ) { 152 156 if ($num_octets == 3) { 153 157 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); 158 $unicode_length += 9; 154 159 } else { 155 160 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); 161 $unicode_length += 6; 156 162 } 157 163 158 164 $values = array();