iconv() is more efficient than mb_convert_encoding()
This commit is contained in:
parent
316f86e03c
commit
80e3c46f3a
|
@ -482,7 +482,7 @@ class PHPExcel_Shared_String
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert string from one encoding to another. First try iconv, then mbstring, or no convertion
|
* Convert string from one encoding to another. First try mbstring, then iconv, finally strlen
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param string $to Encoding to convert to, e.g. 'UTF-8'
|
* @param string $to Encoding to convert to, e.g. 'UTF-8'
|
||||||
|
@ -491,14 +491,14 @@ class PHPExcel_Shared_String
|
||||||
*/
|
*/
|
||||||
public static function ConvertEncoding($value, $to, $from)
|
public static function ConvertEncoding($value, $to, $from)
|
||||||
{
|
{
|
||||||
if (self::getIsIconvEnabled()) {
|
|
||||||
return iconv($from, $to, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::getIsMbstringEnabled()) {
|
if (self::getIsMbstringEnabled()) {
|
||||||
return mb_convert_encoding($value, $to, $from);
|
return mb_convert_encoding($value, $to, $from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self::getIsIconvEnabled()) {
|
||||||
|
return iconv($from, $to, $value);
|
||||||
|
}
|
||||||
|
|
||||||
if($from == 'UTF-16LE'){
|
if($from == 'UTF-16LE'){
|
||||||
return self::utf16_decode($value, false);
|
return self::utf16_decode($value, false);
|
||||||
}else if($from == 'UTF-16BE'){
|
}else if($from == 'UTF-16BE'){
|
||||||
|
@ -548,20 +548,20 @@ class PHPExcel_Shared_String
|
||||||
*/
|
*/
|
||||||
public static function CountCharacters($value, $enc = 'UTF-8')
|
public static function CountCharacters($value, $enc = 'UTF-8')
|
||||||
{
|
{
|
||||||
if (self::getIsIconvEnabled()) {
|
|
||||||
return iconv_strlen($value, $enc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::getIsMbstringEnabled()) {
|
if (self::getIsMbstringEnabled()) {
|
||||||
return mb_strlen($value, $enc);
|
return mb_strlen($value, $enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self::getIsIconvEnabled()) {
|
||||||
|
return iconv_strlen($value, $enc);
|
||||||
|
}
|
||||||
|
|
||||||
// else strlen
|
// else strlen
|
||||||
return strlen($value);
|
return strlen($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a substring of a UTF-8 encoded string
|
* Get a substring of a UTF-8 encoded string. First try mbstring, then iconv, finally strlen
|
||||||
*
|
*
|
||||||
* @param string $pValue UTF-8 encoded string
|
* @param string $pValue UTF-8 encoded string
|
||||||
* @param int $start Start offset
|
* @param int $start Start offset
|
||||||
|
@ -570,14 +570,14 @@ class PHPExcel_Shared_String
|
||||||
*/
|
*/
|
||||||
public static function Substring($pValue = '', $pStart = 0, $pLength = 0)
|
public static function Substring($pValue = '', $pStart = 0, $pLength = 0)
|
||||||
{
|
{
|
||||||
if (self::getIsIconvEnabled()) {
|
|
||||||
return iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::getIsMbstringEnabled()) {
|
if (self::getIsMbstringEnabled()) {
|
||||||
return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
|
return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self::getIsIconvEnabled()) {
|
||||||
|
return iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
// else substr
|
// else substr
|
||||||
return substr($pValue, $pStart, $pLength);
|
return substr($pValue, $pStart, $pLength);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue