Ticket #236: TextHelperUTF8.patch

File TextHelperUTF8.patch, 1.3 kB (added by sasan, 14 months ago)

UTF8 in Text Helper

  • libs/kohana/helpers/text.php

     
    140140                } 
    141141 
    142142                $str = ''; 
    143                 $pool_size = utf8::strlen($pool); 
     143                $pool_size = class_exists('utf8', FALSE) ? utf8::strlen($pool) : strlen($pool); 
    144144 
    145145                for ($i = 0; $i < $length; $i++) 
    146146                { 
    147                         $str .= utf8::substr($pool, mt_rand(0, $pool_size - 1), 1); 
     147                        $str .= class_exists('utf8', FALSE) ? utf8::substr($pool, mt_rand(0, $pool_size - 1), 1) : substr($pool, mt_rand(0, $pool_size - 1), 1); 
    148148                } 
    149149 
    150150                return $str; 
     
    195195 
    196196                $regex = '!'.$regex.'!ui'; 
    197197 
    198                 if (utf8::strlen($replacement) == 1) 
     198        $strlen = class_exists('utf8', FALSE) ? utf8::strlen($replacement) : strlen($replacement); 
     199 
     200                if ($strlen == 1) 
    199201                { 
    200202                        $regex .= 'e'; 
    201                         return preg_replace($regex, 'str_repeat($replacement, utf8::strlen(\'$1\'))', $str); 
     203                        return preg_replace($regex, 'str_repeat($replacement, class_exists(\'utf8\', FALSE) ? utf8::strlen(\'$1\') : strlen(\'$1\'))', $str); 
    202204                } 
    203205 
    204206                return preg_replace($regex, $replacement, $str); 
     
    247249                return sprintf($format, $bytes / pow($mod, $power), $units[$power]); 
    248250        } 
    249251 
    250 } // End text 
    251  No newline at end of file 
     252} // End text