Changeset 12dac491 in github


Ignore:
Timestamp:
Apr 12, 2011 2:01:49 PM (2 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
3d8b54e
Parents:
ca18a90
Message:

Handle unicode strings when normalizing for search (#1487866)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_addressbook.php

    r360bd3e r12dac491  
    398398    protected static function normalize_string($str) 
    399399    { 
    400         $norm = strtolower(strtr(utf8_decode($str), 
    401             'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', 
    402             'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')); 
    403  
    404         return preg_replace( 
    405             array('/[\s;\+\-\/]+/i', '/(\d)\s+(\d)/', '/\s\w{1,3}\s/'), 
     400        // split by words 
     401        $arr = explode(" ", preg_replace( 
     402            array('/[\s;\+\-\/]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/'), 
    406403            array(' ', '\\1\\2', ' '), 
    407             $norm); 
     404            $str)); 
     405         
     406        foreach ($arr as $i => $part) { 
     407            if (utf8_encode(utf8_decode($part)) == $part) {  // is latin-1 ? 
     408                $arr[$i] = strtr(strtolower(strtr(utf8_decode($part), 
     409                    'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', 
     410                    'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')), 
     411                    array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); 
     412            } 
     413            else 
     414                $arr[$i] = strtolower($part); 
     415        } 
     416         
     417        return join(" ", $arr); 
    408418    } 
    409419     
Note: See TracChangeset for help on using the changeset viewer.