summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2011-04-12 18:01:49 +0000
committerthomascube <thomas@roundcube.net>2011-04-12 18:01:49 +0000
commit12dac4911b91e80cf1d8c85ee8ad1ef191b630cb (patch)
treea18c6b812ec891b5e45903b4c158fd1e53983e70 /program
parentca18a90b1af9312b936e909c3e8c14e0e1571935 (diff)
Handle unicode strings when normalizing for search (#1487866)
Diffstat (limited to 'program')
-rw-r--r--program/include/rcube_addressbook.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/program/include/rcube_addressbook.php b/program/include/rcube_addressbook.php
index 9e8254ca4..8ec0abbf2 100644
--- a/program/include/rcube_addressbook.php
+++ b/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);
}
}