Handle unicode strings when normalizing for search (#1487866)

release-0.6
thomascube 14 years ago
parent ca18a90b1a
commit 12dac4911b

@ -397,14 +397,24 @@ abstract class rcube_addressbook
*/
protected static function normalize_string($str)
{
$norm = strtolower(strtr(utf8_decode($str),
// split by words
$arr = explode(" ", preg_replace(
array('/[\s;\+\-\/]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/'),
array(' ', '\\1\\2', ' '),
$str));
foreach ($arr as $i => $part) {
if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ?
$arr[$i] = strtr(strtolower(strtr(utf8_decode($part),
'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ',
'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy'));
'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')),
array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u'));
}
else
$arr[$i] = strtolower($part);
}
return preg_replace(
array('/[\s;\+\-\/]+/i', '/(\d)\s+(\d)/', '/\s\w{1,3}\s/'),
array(' ', '\\1\\2', ' '),
$norm);
return join(" ", $arr);
}
}

Loading…
Cancel
Save