Merge pull request #622 from ayushchd/ord_multibyte

Fix multibyte ord issue
This commit is contained in:
Michal Čihař 2013-08-21 07:02:34 -07:00
commit b2f5ac5131
4 changed files with 46 additions and 5 deletions

View File

@ -88,7 +88,8 @@ class PMA_String
public function isSqlIdentifier($c, $dot_is_valid = false)
{
return ($this->isAlnum($c)
|| ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249
|| ($ord_c = $this->ord($c)) && $ord_c >= 192 && $ord_c != 215 &&
$ord_c != 249
|| $c == '_'
|| $c == '$'
|| ($dot_is_valid != false && $c == '.'));
@ -147,7 +148,19 @@ class PMA_String
return $this->_byte->strtolower($string);
}
/**
/**
* Get the ordinal value of a string
*
* @param string $string the string for which ord is required
*
* @return string the ord value
*/
public function ord($string)
{
return $this->_byte->ord($string);
}
/**
* Checks if a character is an alphanumeric one
*
* @param string $c character to check for

View File

@ -72,5 +72,21 @@ class PMA_StringMB implements PMA_StringByte
{
return mb_strtolower($string);
}
/**
* Get the ordinal value of a multibyte string
* (Adapted from http://www.php.net/manual/en/function.ord.php#72463)
*
* @param string $string the string for which ord is required
*
* @return string the ord value
*/
public function ord($string)
{
$str = mb_convert_encoding($string, "UCS-4BE", "UTF-8");
$substr = mb_substr($str, 0, 1, "UCS-4BE");
$val = unpack("N", $substr);
return $val[1];
}
}
?>

View File

@ -71,5 +71,17 @@ class PMA_StringNative implements PMA_StringByte
{
return strtolower($string);
}
/**
* Get the ordinal value of a string
*
* @param string $string the string for which ord is required
*
* @return string the ord value
*/
public function ord($string)
{
return ord($string);
}
};
?>

View File

@ -139,9 +139,9 @@ class PMA_String_Test extends PHPUnit_Framework_TestCase
array(true, 'a'),
array(true, '.', true),
array(false, '.'),
array(true, chr(192)),
array(false, chr(215)),
array(false, chr(249)),
array(true, 'À'),
array(false, '×'),
array(false, 'ù'),
array(true, '_'),
array(true, '$')
);