diff options
| author | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-04-12 18:01:49 +0000 |
|---|---|---|
| committer | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-04-12 18:01:49 +0000 |
| commit | 2fbb073c0f3e5e067969e5a9250876148e3d9b28 (patch) | |
| tree | 3e8c5910e0e12d07fe7b8dc8b91f82101943e75a /roundcubemail/program/include | |
| parent | 2bbfd23e16e949cce9a4ccdf887ec710a575545d (diff) | |
Handle unicode strings when normalizing for search (#1487866)
git-svn-id: https://svn.roundcube.net/trunk@4648 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include')
| -rw-r--r-- | roundcubemail/program/include/rcube_addressbook.php | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/roundcubemail/program/include/rcube_addressbook.php b/roundcubemail/program/include/rcube_addressbook.php index 9e8254ca4..8ec0abbf2 100644 --- a/roundcubemail/program/include/rcube_addressbook.php +++ b/roundcubemail/program/include/rcube_addressbook.php @@ -397,14 +397,24 @@ abstract class rcube_addressbook */ protected static function normalize_string($str) { - $norm = strtolower(strtr(utf8_decode($str), - 'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', - 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')); - - return preg_replace( - array('/[\s;\+\-\/]+/i', '/(\d)\s+(\d)/', '/\s\w{1,3}\s/'), + // split by words + $arr = explode(" ", preg_replace( + array('/[\s;\+\-\/]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/'), array(' ', '\\1\\2', ' '), - $norm); + $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')), + array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); + } + else + $arr[$i] = strtolower($part); + } + + return join(" ", $arr); } } |
