[pLog-svn] r5695 - plog/trunk/class/data/utf8
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Fri Jul 20 13:55:50 EDT 2007
Author: oscar
Date: 2007-07-20 13:55:49 -0400 (Fri, 20 Jul 2007)
New Revision: 5695
Modified:
plog/trunk/class/data/utf8/utf8_funcs.php
Log:
We don't need these two methods anymore, they're being provided by the php-utf8 library.
Modified: plog/trunk/class/data/utf8/utf8_funcs.php
===================================================================
--- plog/trunk/class/data/utf8/utf8_funcs.php 2007-07-19 22:00:26 UTC (rev 5694)
+++ plog/trunk/class/data/utf8/utf8_funcs.php 2007-07-20 17:55:49 UTC (rev 5695)
@@ -52,109 +52,8 @@
return $us;
}
-/**
- * mix utf8_substr(string $inputString, int $start_index, int $length = -1, bool $ignore_invalid_utf8_char = true)
- * @param $inputStr
- * @param $start start index, must be large than 0
- * @param $length. if $length <0, return all text begin from $start
- * @param $ignore_error whether ignore the invalid characters (in return string, these invalid chars will be replaced with '?') or not. default is true (ignore)
- * @return the substring, or false (empty string '')
- */
-function utf8_substr($inputStr, $start, $length = -1, $ignore_error = true)
-{
- if($start<0 || $length == 0)
- return false;
- //discard preg_split function. it consumes too much system resource when it tries to split a big string to pieces
- //$rawArr = preg_split('//',$inputStr,-1, PREG_SPLIT_NO_EMPTY);
- //find start
- $si = 0;
- $si_single = 0;
- while($si < $start)
- {
- $hm = utf8_isValidChar($inputStr, $si_single);
- if($hm == -1)
- {
- //ignore invalid character?
- if(!$ignore_error)
- return false;
- //array_shift is very slow
- //array_shift($rawArr);
- $si++;
- $si_single++;
- }
- else if($hm == 0)
- {
- //$start is bigger than the utf8_length of inputString
- return false;
- }
- else
- {
- //for($i=0; $i<$hm; $i++) array_shift($rawArr);
- $si++;
- $si_single += $hm;
- }
- }
- if($length < 0)
- //return implode('', $rawArr);
- return substr($inputStr, $si_single);
- $retArr = array();
- $li = 0;
- while($li < $length)
- {
- $hm = utf8_isValidChar($inputStr, $si_single);
- if($hm == -1)
- {
- if(!$ignore_error)
- return false;
- $retArr[] = '?';
- //array_shift($rawArr);
- $li++;
- $si_single++;
- }
- else if($hm == 0)
- {
- //end of string
- return implode('', $retArr);
- }
- else
- {
- //for($i=0; $i<$hm; $i++) $retArr[] = array_shift($rawArr);
- for($i=0; $i<$hm; $i++) $retArr[] = $inputStr{$si_single++};
- $li++;
- }
- }
- return implode('', $retArr);
-}
/**
- * int utf8_strlen(string $inputString, bool $ignore_invalid_utf8_char = true)
- * @return length of string encoded as utf8 ( how many utf8 characters )
- * -1 if given $ignore_error is false and there's invalid utf8 char in the inputString
- * @note if $ignore_error is true (the default value), every invalid utf8 character will be count as ONE utf8 char
- */
-function utf8_strlen($inputStr, $ignore_error = true)
-{
- //$rawArr = preg_split('//',$inputStr,-1, PREG_SPLIT_NO_EMPTY);
- $len = 0;
- $si_single = 0;
- while(($hm = utf8_isValidChar($inputStr, $si_single)) != 0)
- {
- if($hm == -1)
- {
- if(!$ignore_error)
- return -1;
- //array_shift($rawArr);
- $si_single++;
- }
- else
- //for($i=0; $i<$hm; $i++) array_shift($rawArr);
- $si_single += $hm;
- $len++;
- }
- return $len;
-}
-
-/**
* int utf8_proportion(string $inputString)
* @param $inputString
* @return percentage of valid utf8 chars of $inputString
More information about the pLog-svn
mailing list