summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2009-10-20 22:19:38 +0200
committerAndreas Gohr <andi@splitbrain.org>2009-10-20 22:19:38 +0200
commit8ec3f7bdbf7a5f702a3022332a6f6cb424d0981a (patch)
treed4359f84fefeb9706e92d17aa2050b5c46ffe607
parent4fa35cd99094962a8122c7ff3be6bd51146d366a (diff)
downloadrpg-8ec3f7bdbf7a5f702a3022332a6f6cb424d0981a.tar.gz
rpg-8ec3f7bdbf7a5f702a3022332a6f6cb424d0981a.tar.bz2
do not recalculate strlen in each loop in utf8 lib
Ignore-this: 2e2f6983f0c1b891825b0c1954b7727d darcs-hash:20091020201938-7ad00-7b5501c2acc9f5ac280e73d25e1cccbcb3237356.gz
-rw-r--r--inc/utf8.php18
1 files changed, 10 insertions, 8 deletions
diff --git a/inc/utf8.php b/inc/utf8.php
index 661e84bd8..a438783f7 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -78,13 +78,14 @@ if(!function_exists('utf8_strip')){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function utf8_strip($str){
- $ascii = '';
- for($i=0; $i<strlen($str); $i++){
- if(ord($str{$i}) <128){
- $ascii .= $str{$i};
+ $ascii = '';
+ $len = strlen($str);
+ for($i=0; $i<$len; $i++){
+ if(ord($str{$i}) <128){
+ $ascii .= $str{$i};
+ }
}
- }
- return $ascii;
+ return $ascii;
}
}
@@ -96,7 +97,8 @@ if(!function_exists('utf8_check')){
* @link http://www.php.net/manual/en/function.utf8-encode.php
*/
function utf8_check($Str) {
- for ($i=0; $i<strlen($Str); $i++) {
+ $len = strlen($Str);
+ for ($i=0; $i<$len; $i++) {
$b = ord($Str[$i]);
if ($b < 0x80) continue; # 0bbbbbbb
elseif (($b & 0xE0) == 0xC0) $n=1; # 110bbbbb
@@ -107,7 +109,7 @@ if(!function_exists('utf8_check')){
else return false; # Does not match any model
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
- if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
+ if ((++$i == $len) || ((ord($Str[$i]) & 0xC0) != 0x80))
return false;
}
}