From d10f9a825d70a9c477b8e4a41ec88ac119d3e345 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 5 Nov 2007 17:13:43 +0000 Subject: [PATCH] Improve performance of seems_utf8() and uf8_uri_encode(). fixes #5320 git-svn-id: http://svn.automattic.com/wordpress/trunk@6314 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 2c95dbe8e2..ae38869994 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -94,7 +94,8 @@ function wpautop($pee, $br = 1) { function seems_utf8($Str) { # by bmorel at ssi dot fr - for ($i=0; $i $length ) ) + if ( $length && ( $unicode_length >= $length ) ) break; $unicode .= chr($value); + $unicode_length++; } else { if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; $values[] = $value; - if ( $length && ( (strlen($unicode) + ($num_octets * 3)) > $length ) ) + if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length ) break; if ( count( $values ) == $num_octets ) { if ($num_octets == 3) { $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); + $unicode_length += 9; } else { $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); + $unicode_length += 6; } $values = array();