*/
public function compare($a, $b)
{
- return strcoll(Horde_String::lower($a[$this->key], true), Horde_String::lower($b[$this->key], true));
+ return strcoll(Horde_String::lower($a[$this->key], true, 'UTF-8'), Horde_String::lower($b[$this->key], true, 'UTF-8'));
}
/**
*/
public function reverseCompare($a, $b)
{
- return strcoll(Horde_String::lower($b[$this->key], true), Horde_String::lower($a[$this->key], true));
+ return strcoll(Horde_String::lower($b[$this->key], true, 'UTF-8'), Horde_String::lower($a[$this->key], true, 'UTF-8'));
}
/**
*/
public function compareKeys($a, $b)
{
- return strcoll(Horde_String::lower($a, true), Horde_String::lower($b, true));
+ return strcoll(Horde_String::lower($a, true, 'UTF-8'), Horde_String::lower($b, true, 'UTF-8'));
}
/**
*/
public function reverseCompareKeys($a, $b)
{
- return strcoll(Horde_String::lower($b, true), Horde_String::lower($a, true));
+ return strcoll(Horde_String::lower($b, true, 'UTF-8'), Horde_String::lower($a, true, 'UTF-8'));
}
}
class Horde_String
{
/**
- * Default charset.
- *
- * @var string
- */
- static protected $_charset = 'UTF-8';
-
- /**
* lower() cache.
*
* @var array
* @param mixed $input The data to be converted. If $input is an an array,
* the array's values get converted recursively.
* @param string $from The string's current charset.
- * @param string $to The charset to convert the string to. If not
- * specified, the global variable $_charset will
- * be used.
+ * @param string $to The charset to convert the string to.
*
* @return mixed The converted input data.
*/
if ($locale) {
if (Horde_Util::extensionExists('mbstring')) {
if (is_null($charset)) {
- $charset = self::$_charset;
+ throw new InvalidArgumentException('$charset argument must not be null');
}
$old_error = error_reporting(0);
$ret = mb_strtolower($string, self::_mbstringCharset($charset));
if ($locale) {
if (Horde_Util::extensionExists('mbstring')) {
if (is_null($charset)) {
- $charset = self::$_charset;
+ throw new InvalidArgumentException('$charset argument must not be null');
}
$old_error = error_reporting(0);
$ret = mb_strtoupper($string, self::_mbstringCharset($charset));
* @return string The string's part.
*/
static public function substr($string, $start, $length = null,
- $charset = null)
+ $charset = 'UTF-8')
{
if (is_null($length)) {
$length = self::length($string, $charset) - $start;
/* Try iconv. */
if (Horde_Util::extensionExists('iconv')) {
- if (is_null($charset)) {
- $charset = self::$_charset;
- }
-
$old_error = error_reporting(0);
$ret = iconv_substr($string, $start, $length, $charset);
error_reporting($old_error);
/* Try mbstring. */
if (Horde_Util::extensionExists('mbstring')) {
- if (is_null($charset)) {
- $charset = self::$_charset;
- }
$old_error = error_reporting(0);
$ret = mb_substr($string, $start, $length, self::_mbstringCharset($charset));
error_reporting($old_error);
*
* @return integer The string's length.
*/
- static public function length($string, $charset = null)
+ static public function length($string, $charset == 'UTF-8')
{
- if (is_null($charset)) {
- $charset = self::$_charset;
- }
$charset = self::lower($charset);
if ($charset == 'utf-8' || $charset == 'utf8') {
*
* @return integer The position of first occurrence.
*/
- static public function pos($haystack, $needle, $offset = 0,
- $charset = null)
+ static public function pos($haystack, $needle, $offset, $charset = 'UTF-8')
{
if (Horde_Util::extensionExists('mbstring')) {
- if (is_null($charset)) {
- $charset = self::$_charset;
- }
$track_errors = ini_set('track_errors', 1);
$old_error = error_reporting(0);
$ret = mb_strpos($haystack, $needle, $offset, self::_mbstringCharset($charset));