predictivesearch/PcsAlgorithm/Algorithm2/src/FindUtilChineseECE.cpp
branchRCL_3
changeset 58 d4f567ce2e7c
parent 32 2828b4d142c0
child 64 c1e8ba0c2b16
equal deleted inserted replaced
57:2666d9724c76 58:d4f567ce2e7c
    18 #include <PtiEngine.h>
    18 #include <PtiEngine.h>
    19 #include <centralrepository.h>
    19 #include <centralrepository.h>
    20 #include <AknFepInternalCRKeys.h>
    20 #include <AknFepInternalCRKeys.h>
    21 #include <aknedsts.h>
    21 #include <aknedsts.h>
    22 #include <coeaui.h>
    22 #include <coeaui.h>
       
    23 #include <AvkonInternalCRKeys.h>
       
    24 
    23 // The below code is commented out because current CFindUtilChineseECE is used
    25 // The below code is commented out because current CFindUtilChineseECE is used
    24 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
    26 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
    25 // for the further merging work (merge from FindUtil 5.0)
    27 // for the further merging work (merge from FindUtil 5.0)
    26 #if 0
    28 #if 0
    27 #include <AvkonInternalCRKeys.h>
       
    28 #include <aknenv.h> //phonebook
    29 #include <aknenv.h> //phonebook
    29 #include <aknappui.h>
    30 #include <aknappui.h>
    30 #include <aknapp.h>
    31 #include <aknapp.h>
    31 #include <eikenv.h>
    32 #include <eikenv.h>
    32 #include <eikapp.h>
    33 #include <eikapp.h>
    43 // CONSTANTS 
    44 // CONSTANTS 
    44 const TUint16 KStarChar = 0x002a;
    45 const TUint16 KStarChar = 0x002a;
    45 const TUint16 KZhuyinstart = 0x3105;
    46 const TUint16 KZhuyinstart = 0x3105;
    46 const TInt KZhuyincount = 37;
    47 const TInt KZhuyincount = 37;
    47 const TInt KSeperator = 2626;
    48 const TInt KSeperator = 2626;
    48 const TInt16 KMinUnicodeHz = 0x4e00;
    49 const TUint16 KMinUnicodeHz = 0x4e00;
    49 const TInt16 KStrokeHorizontalValue = 0x4e00;
    50 const TUint16 KMaxUnicodeHz = 0x9fa5;
    50 const TInt16 KStrokeVerticalValue = 0x4e28;
    51 const TUint16 KStrokeHorizontalValue = 0x4e00;
    51 const TInt16 KStrokeDownToLeftValue = 0x4e3f;
    52 const TUint16 KStrokeVerticalValue = 0x4e28;
    52 const TInt16 KStrokeDownToRightValue = 0x4e36;
    53 const TUint16 KStrokeDownToLeftValue = 0x4e3f;
    53 const TInt16 KStrokeBendingValue = 0x4e5b;
    54 const TUint16 KStrokeDownToRightValue = 0x4e36;
       
    55 const TUint16 KStrokeBendingValue = 0x4e5b;
    54 const TInt KSysInputMode = -1;
    56 const TInt KSysInputMode = -1;
    55 const TInt KLeftToRightFlag =0x200e;
    57 const TInt KLeftToRightFlag =0x200e;
    56 const TInt KRightToLeftFlag =0x200f;
    58 const TInt KRightToLeftFlag =0x200f;
    57 // The below code is commented out because current CFindUtilChineseECE is used
    59 // The below code is commented out because current CFindUtilChineseECE is used
    58 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
    60 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
    60 #if 0
    62 #if 0
    61 const TUid KUidPhoneBook = {0x101F4CCE};
    63 const TUid KUidPhoneBook = {0x101F4CCE};
    62 const TUid KUidPhoneBookServer = {0x10207277};
    64 const TUid KUidPhoneBookServer = {0x10207277};
    63 #endif
    65 #endif
    64 
    66 
       
    67 
    65 _LIT(KWildChar, "*");
    68 _LIT(KWildChar, "*");
    66 _LIT(KUnderLine, "_");
    69 _LIT(KUnderLine, "_");
    67 _LIT(KMiddleLine, "-");
    70 _LIT(KMiddleLine, "-");
    68 _LIT(KBlank, " ");
    71 _LIT(KBlank, " ");
    69 _LIT(KTab, "\t");
    72 _LIT(KTab, "\t");
    70 _LIT(KPanicReason, "Abnormal input parameters!");
    73 _LIT(KPanicReason, "Abnormal input parameters!");
    71 
    74 
    72 const TInt KLitLineFeed(8233);
    75 const TInt KLitLineFeed(8233);
    73 
       
    74 // CleanupStack helpers for item owning RPointerArrays
       
    75 template <class T>
       
    76 class CleanupResetAndDestroy
       
    77     {
       
    78 public:
       
    79     inline static void PushL( T& aRef )
       
    80         { 
       
    81         CleanupStack::PushL( TCleanupItem( &ResetAndDestroy, &aRef ) ); 
       
    82         }
       
    83 private:
       
    84     inline static void ResetAndDestroy( TAny *aPtr )
       
    85         { 
       
    86         static_cast<T*>( aPtr )->ResetAndDestroy();
       
    87         }
       
    88     };
       
    89 
       
    90 template <class T>
       
    91 inline void CleanupResetAndDestroyPushL( T& aRef )
       
    92     { 
       
    93     CleanupResetAndDestroy<T>::PushL( aRef );
       
    94     }
       
    95 // ======== MEMBER FUNCTIONS ========
    76 // ======== MEMBER FUNCTIONS ========
    96 
    77 
    97 // ---------------------------------------------------------
    78 // ---------------------------------------------------------
    98 // Symbian constructor
    79 // Symbian constructor
    99 // ---------------------------------------------------------
    80 // ---------------------------------------------------------
   114 // ---------------------------------------------------------
    95 // ---------------------------------------------------------
   115 //
    96 //
   116 void CFindUtilChineseECE::ConstructL(CPcsAlgorithm2* aAlgorithm)
    97 void CFindUtilChineseECE::ConstructL(CPcsAlgorithm2* aAlgorithm)
   117     {
    98     {
   118     iRepositoryFind = CRepository::NewL(KCRUidAknFep);
    99     iRepositoryFind = CRepository::NewL(KCRUidAknFep);
   119     // The below code is commented out because current CFindUtilChineseECE is used
       
   120     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   121     // for the further merging work (merge from FindUtil 5.0)
       
   122 #if 0   
       
   123     iRepositoryFindAdaptive = CRepository::NewL(KCRUidAvkon);
   100     iRepositoryFindAdaptive = CRepository::NewL(KCRUidAvkon);
   124 #endif
       
   125 
   101 
   126     iWatcher = CFindRepositoryWatcher::NewL(KCRUidAknFep, 
   102     iWatcher = CFindRepositoryWatcher::NewL(KCRUidAknFep, 
   127         TCallBack(HandleFindRepositoryCallBack, this), 
   103         TCallBack(HandleFindRepositoryCallBack, this), 
   128         iRepositoryFind);
   104         iRepositoryFind);
   129 
   105 
   130     // The below code is commented out because current CFindUtilChineseECE is used
       
   131     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   132     // for the further merging work (merge from FindUtil 5.0)
       
   133 #if 0
       
   134     iWatcherAdaptive = CFindRepositoryWatcher::NewL(KCRUidAvkon,
   106     iWatcherAdaptive = CFindRepositoryWatcher::NewL(KCRUidAvkon,
   135         TCallBack(HandleFindRepositoryCallBack, this),
   107         TCallBack(HandleFindRepositoryCallBack, this),
   136         iRepositoryFindAdaptive);                                        
   108         iRepositoryFindAdaptive);
   137 #endif
   109 
   138     iAlgorithm = aAlgorithm;
   110     iAlgorithm = aAlgorithm;
   139     OpenL();
   111     OpenL();
   140 
   112 
   141     }
   113     }
   142 
   114 
   144 // CFindUtilChineseECE utils class
   116 // CFindUtilChineseECE utils class
   145 // ---------------------------------------------------------
   117 // ---------------------------------------------------------
   146 //
   118 //
   147 CFindUtilChineseECE::CFindUtilChineseECE() :
   119 CFindUtilChineseECE::CFindUtilChineseECE() :
   148 iLanguage(ELangTest),
   120 iLanguage(ELangTest),
   149 iSupportPRCChinese(EFalse),
   121 iCurInputMode(KSysInputMode),
   150 iCurInputMode(KSysInputMode)
   122 iSearchMethod(EAdptSearchPinyin),
   151 // The below code is commented out because current CFindUtilChineseECE is used
       
   152 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   153 // for the further merging work (merge from FindUtil 5.0)
       
   154 #if 0
       
   155 iSearchMethodPRC(EAdptSearchPinyin),
       
   156 iSearchMethodTaiWan(EAdptSearchZhuyin),
       
   157 iSearchMethodHongKong(EAdptSearchStroke),
       
   158 iSearchMethodAdaptive(EFalse)
   123 iSearchMethodAdaptive(EFalse)
   159 #endif
   124     {
   160     	    {
   125     }
   161     	    }
       
   162 
   126 
   163 // ---------------------------------------------------------
   127 // ---------------------------------------------------------
   164 // Destructor
   128 // Destructor
   165 // ---------------------------------------------------------
   129 // ---------------------------------------------------------
   166 //
   130 //
   167 CFindUtilChineseECE::~CFindUtilChineseECE()
   131 CFindUtilChineseECE::~CFindUtilChineseECE()
   168     {
   132     {
   169     delete iPtiEngine;
   133     delete iPtiEngine;
   170     delete iWatcher;
   134     delete iWatcher;
   171     delete iPtiEnginePrc;
       
   172     delete iRepositoryFind;
   135     delete iRepositoryFind;
   173     // The below code is commented out because current CFindUtilChineseECE is used
       
   174     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   175     // for the further merging work (merge from FindUtil 5.0)
       
   176 #if 0
       
   177     delete iWatcherAdaptive;
   136     delete iWatcherAdaptive;
   178     delete iRepositoryFindAdaptive;
   137     delete iRepositoryFindAdaptive;
   179 #endif
       
   180     }
   138     }
   181 
   139 
   182 // ---------------------------------------------------------
   140 // ---------------------------------------------------------
   183 // Open ptiengine and active it by input language
   141 // Open ptiengine and active it by input language
   184 // ---------------------------------------------------------
   142 // ---------------------------------------------------------
   186 TBool CFindUtilChineseECE::OpenT9InterfaceL(TLanguage aLanguage)
   144 TBool CFindUtilChineseECE::OpenT9InterfaceL(TLanguage aLanguage)
   187     {
   145     {
   188     if (!iPtiEngine)
   146     if (!iPtiEngine)
   189         {
   147         {
   190         iPtiEngine = CPtiEngine::NewL();
   148         iPtiEngine = CPtiEngine::NewL();
   191         iSupportPRCChinese = IsSupportLanguage(ELangPrcChinese);
       
   192         }
   149         }
   193 
   150 
   194     if (aLanguage != iLanguage)
   151     if (aLanguage != iLanguage)
   195         {
   152         {
   196         iLanguage = aLanguage;
   153         // We only support Chinese languages. If input language is changed
       
   154         // to non-Chinese, then first available Chinese language is used
       
   155         // instead.
       
   156         if ( aLanguage == ELangPrcChinese ||
       
   157              aLanguage == ELangTaiwanChinese ||
       
   158              aLanguage == ELangHongKongChinese )
       
   159             {
       
   160             iLanguage = aLanguage;
       
   161             }
       
   162         else if ( IsSupportLanguage(ELangPrcChinese) )
       
   163             {
       
   164             iLanguage = ELangPrcChinese;
       
   165             }
       
   166         else if ( IsSupportLanguage(ELangTaiwanChinese) )
       
   167             {
       
   168             iLanguage = ELangTaiwanChinese;
       
   169             }
       
   170         else if ( IsSupportLanguage(ELangHongKongChinese) )
       
   171             {
       
   172             iLanguage = ELangHongKongChinese;
       
   173             }
       
   174         else
       
   175             {
       
   176             iLanguage = aLanguage;
       
   177             }
       
   178         
   197         iPtiEngine->ActivateLanguageL(iLanguage);
   179         iPtiEngine->ActivateLanguageL(iLanguage);
   198         iPtiEngine->EnableToneMarks(EFalse);
   180         iPtiEngine->EnableToneMarks(EFalse);
   199         }
   181         }
   200 
   182 
   201     return ETrue;
   183     return ETrue;
   215 // Translate Chinese word to its spelling
   197 // Translate Chinese word to its spelling
   216 // ---------------------------------------------------------
   198 // ---------------------------------------------------------
   217 //
   199 //
   218 TBool CFindUtilChineseECE::DoTranslationL(TInt16 aHZUnicode, RPointerArray<HBufC>& aSpellList)
   200 TBool CFindUtilChineseECE::DoTranslationL(TInt16 aHZUnicode, RPointerArray<HBufC>& aSpellList)
   219     {
   201     {
       
   202     // Always translate according the adaptive search method setting
       
   203     return T9ChineseTranslationAdaptiveL(aHZUnicode, aSpellList);
       
   204     
       
   205 #if 0
   220     // The below code is commented out because current CFindUtilChineseECE is used
   206     // The below code is commented out because current CFindUtilChineseECE is used
   221     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
   207     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
   222     // for the further merging work (merge from FindUtil 5.0)
   208     // for the further merging work (merge from FindUtil 5.0)
   223 #if 0
   209 #if 0
   224     if(CEikonEnv::Static())
   210     if(CEikonEnv::Static())
   262             }
   248             }
   263         }
   249         }
   264 #endif
   250 #endif
   265     return ETrue;
   251     return ETrue;
   266 
   252 
       
   253 #endif
   267     }
   254     }
   268 
   255 
   269 // ---------------------------------------------------------
   256 // ---------------------------------------------------------
   270 // Find pane text is including stroke symbol
   257 // Find pane text is including stroke symbol
   271 // ---------------------------------------------------------
   258 // ---------------------------------------------------------
   272 //
   259 //
   273 TInt CFindUtilChineseECE::IsStrokeSymbol(const TInt aFindWord)
   260 TInt CFindUtilChineseECE::IsStrokeSymbol(const TUint16 aFindWord)
   274     {
   261     {
   275     TInt strokeValue = 0;
   262     TInt strokeValue = 0;
   276 
   263 
   277     switch (aFindWord)
   264     switch (aFindWord)
   278         {
   265         {
   296         }// switch
   283         }// switch
   297 
   284 
   298     return strokeValue;
   285     return strokeValue;
   299     }
   286     }
   300 
   287 
   301 TInt CFindUtilChineseECE::CategoryOfLang(TLanguage aLanguage)
   288 #if 0
   302     {
       
   303     TInt ret = 0;
       
   304     if (iLanguage == ELangPrcChinese || ( aLanguage == ELangEnglish && iSupportPRCChinese ))
       
   305         {
       
   306         ret = 1;
       
   307         }
       
   308     else if (aLanguage == ELangTaiwanChinese)
       
   309         {
       
   310         ret = 2;
       
   311         }
       
   312     else if (aLanguage == ELangHongKongChinese)
       
   313         {
       
   314         ret = 3;
       
   315         }
       
   316     return ret;
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------
   289 // ---------------------------------------------------------
   320 // Do translate for Chinese word
   290 // Do translate for Chinese word
   321 // ---------------------------------------------------------
   291 // ---------------------------------------------------------
   322 //
   292 //
   323 TBool CFindUtilChineseECE::T9ChineseTranslationL(TInt16 aHZUnicode, RPointerArray<HBufC>& aSpellList)
   293 TBool CFindUtilChineseECE::T9ChineseTranslationL(TInt16 aHZUnicode, RPointerArray<HBufC>& aSpellList)
   324     {
   294     {
   325     TBuf<KMaxWordInterpretationLen> wordInterpretationBuf;
   295     TBuf<KMaxWordInterpretationLen> wordInterpretationBuf;
   326     TBuf<KMaxWordInterpretationLen> numInterpretationBuf;
       
   327 
   296 
   328     if (iLanguage == ELangPrcChinese)
   297     if (iLanguage == ELangPrcChinese)
   329         {
   298         {
   330         if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) != KErrNone)
   299         if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) != KErrNone)
   331             {
   300             {
   387 
   356 
   388     aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len - start)).Alloc());
   357     aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len - start)).Alloc());
   389 
   358 
   390     return ETrue;
   359     return ETrue;
   391     }
   360     }
   392 
   361 #endif
   393 // The below code is commented out because current CFindUtilChineseECE is used
   362 
   394 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   395 // for the further merging work (merge from FindUtil 5.0)
       
   396 #if 0    
       
   397 // ---------------------------------------------------------
   363 // ---------------------------------------------------------
   398 // Do translate for Chinese word
   364 // Do translate for Chinese word
   399 // ---------------------------------------------------------
   365 // ---------------------------------------------------------
   400 //
   366 //
   401 TBool CFindUtilChineseECE::T9ChineseTranslationAdaptiveL(TInt16 aHZUnicode,  
   367 TBool CFindUtilChineseECE::T9ChineseTranslationAdaptiveL(TInt16 aHZUnicode,  
   402     RPointerArray<HBufC>& aSpellList)
   368     RPointerArray<HBufC>& aSpellList)
   403     {
   369     {
   404     TBuf<KMaxWordInterpretationLen> wordInterpretationBuf;
   370     TBuf<KMaxWordInterpretationLen> wordInterpretationBuf;
   405 
   371 
   406     if ( iLanguage == ELangPrcChinese )
   372     switch(iSearchMethod)
   407         {
   373         {
   408         if(iSearchMethodPRC == EAdptSearchPinyin)
   374         case EAdptSearchPinyin:
   409             {
   375             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin)
   410             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) 
       
   411                 != KErrNone)
   376                 != KErrNone)
   412                 {
   377                 {
   413                 return EFalse;
   378                 return EFalse;
   414                 }	
   379                 }
   415             }
   380              break;
   416         else if(iSearchMethodPRC == EAdptSearchStroke)    
   381         case EAdptSearchStroke:
   417             {
   382             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes)
   418             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) 
       
   419                 != KErrNone)
   383                 != KErrNone)
   420                 {
   384                 {
   421                 return EFalse;
   385                 return EFalse;
   422                 }	
   386                 }
   423             }
   387             break;
   424         else
   388         case EAdptSearchZhuyin:
   425             {
   389             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiZhuyin)
   426             return EFalse;	
       
   427             }    
       
   428 
       
   429         }
       
   430     else if ( iLanguage == ELangTaiwanChinese )
       
   431         {
       
   432         if(iSearchMethodTaiWan == EAdptSearchZhuyin)
       
   433             {
       
   434             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiZhuyin) 
       
   435                 != KErrNone)
   390                 != KErrNone)
   436                 {
   391                 {
   437                 return EFalse;
   392                 return EFalse;
   438                 }	
   393                 }   
   439             }
   394             break;
   440         else if(iSearchMethodTaiWan == EAdptSearchStroke)    
   395         case EAdptSearchNormalCangjie:
   441             {
   396             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie)
   442             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) 
       
   443                 != KErrNone)
   397                 != KErrNone)
   444                 {
   398                 {
   445                 return EFalse;
   399                 return EFalse;
   446                 }	
   400                 }
   447             }
   401             break;
   448         else
   402         case EAdptSearchEasyCangjie:
   449             {
   403             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie) 
   450             return EFalse;	
   404                 != KErrNone)
   451             }       
   405                 {
   452         }
   406                 return EFalse;
   453     else if ( iLanguage == ELangHongKongChinese )
   407                 }
   454         {
   408             break;
   455         switch(iSearchMethodHongKong)
   409         case EAdptSearchAdvCangjie:
   456             {
   410             if ((iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie) != KErrNone)
   457             case EAdptSearchNormalCangjie:
   411                 &&(iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie) != KErrNone))
   458                 if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie) 
   412                 {
   459                     != KErrNone)
   413                 return EFalse;
   460                     {
   414                 }
   461                     return EFalse;
   415             break;
   462                     }
   416         default:
   463                 break;
       
   464             case EAdptSearchEasyCangjie:
       
   465                 if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie) 
       
   466                     != KErrNone)
       
   467                     {
       
   468                     return EFalse;
       
   469                     }
       
   470                 break;
       
   471             case EAdptSearchAdvCangjie:
       
   472                 if ((iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie) != KErrNone)
       
   473                     &&(iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie) != KErrNone))
       
   474                     {
       
   475                     return EFalse;
       
   476                     }
       
   477                 break;
       
   478             case EAdptSearchStroke:
       
   479                 if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) 
       
   480                     != KErrNone)
       
   481                     {
       
   482                     return EFalse;
       
   483                     }
       
   484                 break;
       
   485             default:
       
   486                 return EFalse;        	
       
   487             }
       
   488 
       
   489         }
       
   490     else if ( iLanguage == ELangEnglish )
       
   491         {
       
   492         if (!iSupportPRCChinese)
       
   493             {
       
   494             return EFalse;
   417             return EFalse;
   495             }
   418         }
   496 
   419 
   497         TInt err = KErrNone;
       
   498         if (!iPtiEnginePrc)
       
   499             {
       
   500             iPtiEnginePrc = CPtiEngine::NewL(EFalse);
       
   501             TRAP(err, iPtiEnginePrc->ActivateLanguageL(ELangPrcChinese));
       
   502             }   
       
   503 
       
   504         if (err == KErrNone)
       
   505             {
       
   506             if (iPtiEnginePrc->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) 
       
   507                 != KErrNone) 
       
   508 
       
   509                 return EFalse;
       
   510             }
       
   511         }
       
   512     else
       
   513         {
       
   514         return EFalse;
       
   515         }
       
   516 
   420 
   517     TInt len = wordInterpretationBuf.Length();
   421     TInt len = wordInterpretationBuf.Length();
   518     TInt start = 0;
   422     TInt start = 0;
   519 
   423 
   520     if( iSearchMethodHongKong != EAdptSearchAdvCangjie )
   424     if( iSearchMethod != EAdptSearchAdvCangjie )
   521         {
   425         {
   522         for (TInt i =0; i < len; i++)
   426         for (TInt i =0; i < len; i++)
   523             {
   427             {
   524             if (wordInterpretationBuf[i] == KSeperator) 
   428             if (wordInterpretationBuf[i] == KSeperator) 
   525                 {
   429                 {
   526                 aSpellList.Append((wordInterpretationBuf.MidTPtr(start, i-start)).Alloc());
   430                 aSpellList.Append((wordInterpretationBuf.MidTPtr(start, i-start)).Alloc());
   527                 start = i + 1;
   431                 start = i + 1;
   528                 }
   432                 }
   529             }
   433             }
   530 
   434 
   531         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc());   	
   435         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc());
   532         }
   436         }
   533     //Could look advanced cangjie as normal and easy cangjie
   437     //Could look advanced cangjie as normal and easy cangjie
   534     else 
   438     else 
   535         {
   439         {
   536         iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie);
   440         iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie);
   562 
   466 
   563         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc());  
   467         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc());  
   564         }
   468         }
   565 
   469 
   566     return ETrue;
   470     return ETrue;
   567     } 
   471     }
   568 #endif
       
   569 
   472 
   570 // ---------------------------------------------------------
   473 // ---------------------------------------------------------
   571 // Find pane text is including separator
   474 // Find pane text is including separator
   572 // ---------------------------------------------------------
   475 // ---------------------------------------------------------
   573 //
   476 //
   581 // ---------------------------------------------------------
   484 // ---------------------------------------------------------
   582 //
   485 //
   583 void CFindUtilChineseECE::OpenL()
   486 void CFindUtilChineseECE::OpenL()
   584     {
   487     {
   585     TInt inputLanguage = 0;
   488     TInt inputLanguage = 0;
   586     //TInt searchMode =0;
   489     TInt searchMode = 0;
   587 
   490 
   588     if (iRepositoryFind != NULL)
   491     if (iRepositoryFind != NULL)
   589         {
   492         {
   590         iRepositoryFind->Get(KAknFepInputTxtLang, inputLanguage);
   493         iRepositoryFind->Get(KAknFepInputTxtLang, inputLanguage);
   591         }
   494         }
   592 
   495 
       
   496     // The following sets iLangueage to inputLanguage if inputLanguage
       
   497     // is Chinese. If inputLanguage is non-Chinese, iLanguage will be
       
   498     // set to first available Chinese language.
   593     OpenT9InterfaceL((TLanguage) inputLanguage);
   499     OpenT9InterfaceL((TLanguage) inputLanguage);
   594 
   500 
   595     // The below code is commented out because current CFindUtilChineseECE is used
       
   596     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   597     // for the further merging work (merge from FindUtil 5.0)
       
   598 #if 0
       
   599     if (iRepositoryFindAdaptive != NULL)
   501     if (iRepositoryFindAdaptive != NULL)
   600         {
   502         {
   601         iRepositoryFindAdaptive->Get(KAknAvkonAdaptiveSearchEnabled, iSearchMethodAdaptive);
   503         iRepositoryFindAdaptive->Get(KAknAvkonAdaptiveSearchEnabled, iSearchMethodAdaptive);
   602         }
   504         }
   603     if( inputLanguage == ELangPrcChinese)
   505     if (iLanguage == ELangPrcChinese)
   604         {
   506         {
   605         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChinesePRC , searchMode);	
   507         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChinesePRC , searchMode);
   606         if(searchMode ==0)
   508         if (searchMode == 0)
   607             {
   509             {
   608             iSearchMethodPRC = EAdptSearchPinyin;	
   510             iSearchMethod = EAdptSearchPinyin;
   609             }
   511             }
   610         else if(searchMode ==1)
   512         else if (searchMode == 1)
   611             {
   513             {
   612             iSearchMethodPRC = EAdptSearchStroke;	
   514             iSearchMethod = EAdptSearchStroke;
   613             }
   515             }
   614         }
   516         }
   615     else if(inputLanguage == ELangTaiwanChinese)
   517     else if (iLanguage == ELangTaiwanChinese)
   616         {
   518         {
   617         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseTW , searchMode);
   519         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseTW , searchMode);
   618         if(searchMode ==0)
   520         if (searchMode == 0)
   619             {
   521             {
   620             iSearchMethodTaiWan = EAdptSearchZhuyin;	
   522             iSearchMethod = EAdptSearchZhuyin;
   621             }
   523             }
   622         else if(searchMode ==1)
   524         else if (searchMode == 1)
   623             {
   525             {
   624             iSearchMethodTaiWan = EAdptSearchStroke;	
   526             iSearchMethod = EAdptSearchStroke;
   625             }	
   527             }
   626         }
   528         }
   627     else if(inputLanguage == ELangHongKongChinese)
   529     else if (iLanguage == ELangHongKongChinese)
   628         {
   530         {
   629         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseHongkong  , searchMode);
   531         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseHongkong  , searchMode);
   630         if(searchMode ==1)
   532         if (searchMode == 1)
   631             {	    
   533             {
   632             iRepositoryFind->Get(KAknFepCangJieMode , searchMode);
   534             iRepositoryFind->Get(KAknFepCangJieMode , searchMode);
   633 
   535 
   634             switch (searchMode)
   536             switch (searchMode)
   635                 {
   537                 {
   636                 case 0:
   538                 case 0:
   637                     iSearchMethodHongKong = EAdptSearchNormalCangjie;
   539                     iSearchMethod = EAdptSearchNormalCangjie;
   638                     break;
   540                     break;
   639                 case 1:
   541                 case 1:
   640                     iSearchMethodHongKong = EAdptSearchEasyCangjie;
   542                     iSearchMethod = EAdptSearchEasyCangjie;
   641                     break;
   543                     break;
   642                 case 2:
   544                 case 2:
   643                     iSearchMethodHongKong = EAdptSearchAdvCangjie;
   545                     iSearchMethod = EAdptSearchAdvCangjie;
   644                     break;
   546                     break;
   645                 }
   547                 }
   646 
   548             }
   647             }
   549         else if (searchMode == 0)
   648         else if(searchMode ==0)
   550             {
   649             {
   551             iSearchMethod = EAdptSearchStroke;
   650             iSearchMethodHongKong = EAdptSearchStroke;	
   552             }
   651             }
   553         }
   652 
       
   653         }
       
   654 #endif
       
   655     }
   554     }
   656 
   555 
   657 // ---------------------------------------------------------
   556 // ---------------------------------------------------------
   658 // Close ptiEngine 
   557 // Close ptiEngine 
   659 // ---------------------------------------------------------
   558 // ---------------------------------------------------------
   680         return EFalse;
   579         return EFalse;
   681         }
   580         }
   682 
   581 
   683     TBool ret = EFalse;
   582     TBool ret = EFalse;
   684     // Check Chinese word in find pane
   583     // Check Chinese word in find pane
   685     TBool chineseWord = IsChineseWord(aWord);
   584     TBool chineseWord = IsChineseWordIncluded(aWord);
   686 
   585 
   687     if (chineseWord)
   586     if (chineseWord)
   688         {
   587         {
   689         ret = IncludeString(aContactsField, aWord);
   588         ret = IncludeString(aContactsField, aWord);
   690 
   589 
   849 // Match arithmetic for accurate search 
   748 // Match arithmetic for accurate search 
   850 // ---------------------------------------------------------
   749 // ---------------------------------------------------------
   851 //
   750 //
   852 TBool CFindUtilChineseECE::MatchRefineL(const TDesC& aItemString, CPsQuery& aPsQuery)
   751 TBool CFindUtilChineseECE::MatchRefineL(const TDesC& aItemString, CPsQuery& aPsQuery)
   853     {
   752     {
       
   753     RArray<TInt> ignore1;
       
   754     CleanupClosePushL( ignore1 );
       
   755     RArray<TInt> ignore2;
       
   756     CleanupClosePushL( ignore2 );
       
   757     
       
   758     TBool match = MatchRefineL( aItemString, aPsQuery, ignore1, ignore2, EFalse );
       
   759     
       
   760     CleanupStack::PopAndDestroy( &ignore2 );
       
   761     CleanupStack::PopAndDestroy( &ignore1 );
       
   762     
       
   763     return match;
       
   764     }
       
   765 
       
   766 TBool CFindUtilChineseECE::MatchRefineL(const TDesC& aItemString, CPsQuery& aPsQuery, 
       
   767         RArray<TInt>& aMatchPos, RArray<TInt>& aMatchLength, TBool aHighLight )
       
   768     {
   854     TBuf<KMaxWordLength> tempBuf;
   769     TBuf<KMaxWordLength> tempBuf;
   855     TBuf<KMaxWordLength> itemString;
   770     TBuf<KMaxWordLength> itemString;
       
   771     TBool haschineseword = EFalse; 
   856 
   772 
   857     itemString.Zero();
   773     itemString.Zero();
   858     if ( KMaxWordLength > aItemString.Length() )
   774     if ( KMaxWordLength > aItemString.Length() )
   859         {
   775         {
   860         itemString.Copy( aItemString );
   776         itemString.Copy( aItemString );
   868     if(itemString.Length()>0)
   784     if(itemString.Length()>0)
   869         {
   785         {
   870         if(itemString[0]== KLeftToRightFlag || itemString[0]== KRightToLeftFlag)
   786         if(itemString[0]== KLeftToRightFlag || itemString[0]== KRightToLeftFlag)
   871             {
   787             {
   872             itemString.Delete(0,1);
   788             itemString.Delete(0,1);
   873             itemString.Delete((itemString.Length()-1),1);    
   789             itemString.Delete((itemString.Length()-1),1);
   874             }
   790             }
   875         }
   791         }
   876 
       
   877     TBool haschineseword = EFalse; 
       
   878 
   792 
   879     // Check function parameter
   793     // Check function parameter
   880     if (aPsQuery.Count() == 0)
   794     if (aPsQuery.Count() == 0)
   881         {
   795         {
   882         return ETrue;
   796         return ETrue;
   886         {
   800         {
   887         return EFalse;
   801         return EFalse;
   888         }
   802         }
   889 
   803 
   890     TBool ret = EFalse;
   804     TBool ret = EFalse;
   891 
       
   892     CPsQuery* query = CPsQuery::NewL();
   805     CPsQuery* query = CPsQuery::NewL();
       
   806     CleanupStack::PushL( query );
   893     GetPartOfQueryL(aPsQuery, 0, aPsQuery.Count()-1, *query);
   807     GetPartOfQueryL(aPsQuery, 0, aPsQuery.Count()-1, *query);
   894     RemoveSeparatorL(*query);
   808     RemoveSeparatorL(*query);
   895     TPtrC queryStrPtr = query->QueryAsStringLC();
   809     TPtrC queryStrPtr = query->QueryAsStringLC();
   896 
   810 
   897     tempBuf.Zero();
   811     tempBuf.Zero();
   910         }
   824         }
   911     else
   825     else
   912         {
   826         {
   913         iCurInputMode = KSysInputMode;
   827         iCurInputMode = KSysInputMode;
   914         }
   828         }
   915 
   829     
   916     // Check Chinese word in find pane
   830     TBool inputMethodStroke = EFalse;
   917     if (IsChineseWord(tempBuf))
   831     if(iLanguage == ELangHongKongChinese && iCurInputMode == 0x0020)
       
   832         {
       
   833         inputMethodStroke = ETrue;
       
   834         }
       
   835       
       
   836     // Check if any Chinese word in find pane
       
   837     if ( IsChineseWordIncluded(tempBuf) )
   918         {
   838         {
   919         haschineseword = ETrue;
   839         haschineseword = ETrue;
   920         ret = IncludeString(aItemString, tempBuf);
   840         ret = IncludeString(aItemString, tempBuf);
   921 
   841       
   922         if (ret)
   842         if( IsAllChineseWord( tempBuf ))
   923             {
   843             {
       
   844             CleanupStack::PopAndDestroy( query );
   924             return ret;
   845             return ret;
   925             }
   846             }
   926         /*    else
   847         }
   927             {
   848 
   928             // if Stroke Symbol in HongKong
   849    
   929             TBool strokeSymHK = (IsStrokeSymbolInString(tempBuf)) && 
   850     // There are two steps to do when searchstring includes Chinese character 
   930                                  (iLanguage == ELangHongKongChinese) &&
   851     //
   931                                  iCurInputMode == 0x0020;
   852     // step 1:  check whether itemstring includes the chinese charactor in the searchstring
   932 
   853     //              If not, return EFalse. Otherwise, go to step2
   933             if (!strokeSymHK)
   854     //
   934                 {
   855     // step2:  If itemstring includes the chinese charactor in the searchstring, translate 
   935                 return ret;
   856     //             the Chinese character in the searchstring to spellList and reconstruct the query.
   936                 }
       
   937             }*/
       
   938         }
       
   939 
       
   940     //Find if search string has chinese word. 
       
   941     //Compare with item string if find chinese word in item string then delete it from search and item string.
       
   942     //if not then return EFalse.
       
   943     TBool InputMethodStroke = EFalse;
       
   944     if(iLanguage == ELangHongKongChinese && iCurInputMode == 0x0020)
       
   945         {
       
   946         InputMethodStroke = ETrue;
       
   947         }
       
   948     
       
   949     if (haschineseword)
   857     if (haschineseword)
   950         {
   858         {
   951         TInt ii=0;
   859         TInt ii=0;
   952         TBool leftDifferentChinese = EFalse; //Fixed for ESSG-7PJ6GF, flag the different Chinese character at the left of aSearchText.
   860         
       
   861         // Step 1: 
       
   862         // E.g: itemstring = "0x4E00,0x4E8C,0x4E09,0x56DB,0x4E94" 
       
   863         // (Unicode of Chinese number "1 2 3 4 5")
       
   864         // searchstring1 = "0x4E00,x,y,z,0x4E09"
       
   865         // searchstring2 = "0x4E8C,0x4E00"
       
   866         // searchstring3 = "0x4E00,0x4E5D" 
       
   867         // In this case, searchstring2 and searchstring3 will return EFalse, 
       
   868         // only searchstring1 will be translated to spellList in step 2
   953         while (ii< tempBuf.Length())
   869         while (ii< tempBuf.Length())
   954             {
   870             {
   955             if ((TInt)tempBuf[ii]>= KMinUnicodeHz && (!InputMethodStroke
   871             TInt lastFindCursor = -1;
   956                     ||(InputMethodStroke && !IsStrokeSymbol(tempBuf[ii]))))
   872             if( (TUint16)tempBuf[ii] <= KMaxUnicodeHz 
       
   873                 && (TUint16)tempBuf[ii]>= KMinUnicodeHz
       
   874                 && ( !inputMethodStroke ||(inputMethodStroke &&
       
   875                     !IsStrokeSymbol(tempBuf[ii])) ) )
   957                 {
   876                 {
   958                 TInt Findcursor = itemString.Locate(tempBuf[ii]);
   877                 TInt Findcursor = itemString.Locate(tempBuf[ii]);
   959                 if (Findcursor != KErrNotFound)
   878                 if( KErrNotFound == Findcursor || Findcursor < lastFindCursor )
   960                     {
   879                     {
   961                     if ((Findcursor == itemString.Length()-1)&& (ii
   880                     CleanupStack::PopAndDestroy( query );
   962                             ==tempBuf.Length()-1))
   881                     return EFalse;
   963                         {
       
   964                         //Start:Fixed for ESSG-7PJ6GF
       
   965                         if ( leftDifferentChinese || IsChineseWord(
       
   966                             itemString.Left( Findcursor ) ) )
       
   967                             {
       
   968                             //if the different Chinese character at the left or middle, return false.
       
   969                             return EFalse;
       
   970                             }
       
   971                         //End:Fixed for ESSG-7PJ6GF
       
   972                         return ETrue;
       
   973                         }
       
   974                     itemString.Delete(0, Findcursor+1);
       
   975                     tempBuf.Delete(0, ii+1);
       
   976                     ii=0;
       
   977                     }
   882                     }
   978                 else
   883                 else
   979                     {
   884                     {
   980                     //Start:Fixed for ESSG-7PJ6GF
   885                     lastFindCursor = Findcursor;
   981                     if ( IsChineseWord( tempBuf.Left( ii + 1 ) ) )
       
   982                         {
       
   983                         //flag the different Chinese character at the left.
       
   984                         leftDifferentChinese = ETrue;
       
   985                         }
       
   986                     //End:Fixed for ESSG-7PJ6GF
       
   987                     ii++;
   886                     ii++;
   988                     }
   887                     }
   989                 }
   888                 }
   990             else
   889             else
   991                 {
   890                 {
   992                 ii++;
   891                 ii++;
   993                 }
   892                 }
   994             }
   893             }
   995 
   894             
   996         }
   895         ii = 0;
   997 
   896         // Counter of queryItem
       
   897         TInt queryItemCount = 0;
       
   898         
       
   899         //Step 2: 
       
   900         // Translating searchstring to spellList and reconstruct query
       
   901          while ( ii< tempBuf.Length() )
       
   902              {            
       
   903              // If it is a valid chinese character
       
   904              if ( (TUint16)tempBuf[ii] <= KMaxUnicodeHz 
       
   905                  && (TUint16)tempBuf[ii]>= KMinUnicodeHz
       
   906                  && ( !inputMethodStroke ||(inputMethodStroke &&
       
   907                      !IsStrokeSymbol(tempBuf[ii])) ) )
       
   908                  {
       
   909                  RPointerArray<HBufC> spellList;
       
   910                  
       
   911                  // If successfully translating the chinese character to spellList( Pinyin,Zhuyin or stroke )
       
   912                  // then reconstruct the query, replace the Chinese character with its spellList in the query.
       
   913                  // Otherwise, just increase the counter of queryItem.
       
   914                  if( DoTranslationL(TInt16(tempBuf[ii]), spellList) )
       
   915                      {                    
       
   916                      // Replace the queryItem by the translated spelling
       
   917                      CPsQueryItem& tempItem = query->GetItemAtL(queryItemCount);
       
   918                      const TKeyboardModes tempMode = tempItem.Mode();
       
   919                      
       
   920                      // Remove the Chinese character queryItem
       
   921                      query->Remove(queryItemCount);
       
   922                      
       
   923                      // Reconstruct the query, replace Chinese character with its spellList
       
   924                      for(TInt cnt = 0; cnt < spellList[0]->Length(); cnt++)
       
   925                          {
       
   926                          // Add a new query item to query
       
   927                          CPsQueryItem* newItem = CPsQueryItem::NewL();   
       
   928                          CleanupStack::PushL(newItem);
       
   929                          newItem->SetCharacter(  (*spellList[0])[cnt] );
       
   930                          newItem->SetMode(tempMode);
       
   931    
       
   932                          query->InsertL(*newItem, queryItemCount + cnt );
       
   933                          CleanupStack::Pop(newItem);  
       
   934                          }
       
   935                     
       
   936                      queryItemCount += spellList[0]->Length();
       
   937                      }
       
   938                  else
       
   939                      {
       
   940                      queryItemCount++;
       
   941                      }
       
   942                      
       
   943                  ii++;
       
   944                  spellList.ResetAndDestroy();
       
   945                  spellList.Close();
       
   946 
       
   947                  }
       
   948              //if not, just pass it by     
       
   949              else
       
   950                  {
       
   951                  ii++;
       
   952                  queryItemCount++;
       
   953                  }
       
   954              }
       
   955 
       
   956         }
       
   957     
   998     // Array for item string
   958     // Array for item string
   999     RPointerArray<STRINGINFO> stringInfoArr;
   959     RPointerArray<STRINGINFO> stringInfoArr;
  1000     // Split item string
   960     // Split item string
  1001     SplitItemStringL(stringInfoArr, itemString);
   961     SplitItemStringL(stringInfoArr, itemString);
  1002 
   962 
  1003     if (stringInfoArr.Count() > 0)
   963     if (stringInfoArr.Count() > 0)
  1004         {
   964         {
  1005         ret = MatchSegmentL(stringInfoArr, *query);
   965         ret = MatchSegmentL(stringInfoArr, *query, aMatchPos, aMatchLength, aHighLight);
  1006         }
   966         }
  1007 
   967 
  1008     stringInfoArr.ResetAndDestroy();
   968     stringInfoArr.ResetAndDestroy();
  1009     stringInfoArr.Close();
   969     stringInfoArr.Close();
  1010 
   970 
  1011     delete query;
   971     CleanupStack::PopAndDestroy( query );
  1012 
   972 
  1013     return ret;
   973     return ret;
  1014     }
   974     }
  1015 
   975 
  1016 // ---------------------------------------------------------
   976 // ---------------------------------------------------------
  1017 // Splite the input text to sgement by language
   977 // Splite the input text to sgement by language
  1018 // ---------------------------------------------------------
   978 // ---------------------------------------------------------
  1019 //
   979 //
  1020 void CFindUtilChineseECE::SplitItemStringL(RPointerArray<STRINGINFO>& aStringInfoArr, 
   980 void CFindUtilChineseECE::SplitItemStringL(RPointerArray<STRINGINFO>& aStringInfoArr, 
  1021     const TDesC &aItemString)
   981     const TDesC& aItemString)
  1022     {
   982     {
  1023     TBuf<KMaxWordLength> tempBuf;
   983     TBuf<KMaxWordLength> tempBuf;
  1024     TBuf<KMaxWordLength> englishBuf;
   984     TBuf<KMaxWordLength> englishBuf;
  1025     TBuf<KMaxWordLength> chineseBuf;
   985     TBuf<KMaxWordLength> chineseBuf;
  1026 
   986 
  1027     tempBuf.Zero();
   987     tempBuf.Zero();
  1028     englishBuf.Zero();
   988     englishBuf.Zero();
  1029     chineseBuf.Zero();
   989     chineseBuf.Zero();
  1030 
   990 
  1031     TInt index = 0;
   991     TInt index = 0;
  1032     TUint32 temp = 0;
   992     TBool isChinese = EFalse;
  1033     TInt32 distance = 0;
       
  1034     const TInt strLength = aItemString.Length();
   993     const TInt strLength = aItemString.Length();
  1035 
   994 
  1036     for (; index < strLength; index++)
   995     for (; index < strLength; index++)
  1037         {
   996         {
  1038         if (IsFindWordSeparator(aItemString[index]))
   997         if (IsFindWordSeparator(aItemString[index]))
  1039             {
   998             {
  1040             // Check Chinese and English Buf. If it is not empty, 
   999             // Check Chinese and English Buf. If it is not empty, 
  1041             // add buf to Array
  1000             // add buf to Array
  1042             InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue);
  1001             InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue, index);
  1043             InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse);
  1002             InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse, index);
  1044             continue;
  1003             continue;
  1045             }
  1004             }
  1046 
  1005 
  1047         temp = aItemString[index];
  1006         isChinese = ((TUint16)aItemString[index] >= KMinUnicodeHz && 
  1048         distance = (TInt32)(temp - KMinUnicodeHz);
  1007                                (TUint16)aItemString[index] <= KMaxUnicodeHz);
  1049 
  1008         
  1050         if (distance < 0)// English word
  1009         if ( !isChinese )// English word
  1051             {
  1010             {
  1052             // Chinese word is end and add to array
  1011             // Chinese word is end and add to array
  1053             InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue);
  1012             InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue, index);
  1054 
  1013 
  1055             // Add English word to array
  1014             // Add English word to array
  1056             englishBuf.Append((TChar) aItemString[index]);
  1015             englishBuf.Append(aItemString[index]);
  1057             }
  1016             }
  1058         else // Chinese word
  1017         else // Chinese word
  1059             {
  1018             {
  1060             // English word is end and add to array
  1019             // English word is end and add to array
  1061             InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse);
  1020             InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse, index);
  1062 
  1021 
  1063             // Add Chinese word to array
  1022             // Add Chinese word to array
  1064             chineseBuf.Append((TChar) aItemString[index]);
  1023             chineseBuf.Append(aItemString[index]);
  1065             }
  1024             }
  1066         }
  1025         }
  1067 
  1026 
  1068     // Finish loop check buffer is empty
  1027     // Finish loop check buffer is empty
  1069     InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue);
  1028     InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue, index);
  1070     InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse);
  1029     InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse, index);
  1071     }
  1030     }
  1072 
  1031 
  1073 // ---------------------------------------------------------
  1032 // ---------------------------------------------------------
  1074 // Insert segment to list
  1033 // Insert segment to list
  1075 // ---------------------------------------------------------
  1034 // ---------------------------------------------------------
  1076 //
  1035 //
  1077 void CFindUtilChineseECE::InsertStrInforArrayL(RPointerArray<STRINGINFO>& aStringInfoArr, 
  1036 void CFindUtilChineseECE::InsertStrInforArrayL(RPointerArray<STRINGINFO>& aStringInfoArr, 
  1078     TDes &aSegmentStr, const TBool aChinese)
  1037     TDes &aSegmentStr, TBool aChinese, TInt aIndexAfterStr)
  1079     {
  1038     {
  1080     CleanupResetAndDestroyPushL( aStringInfoArr );
       
  1081     if (aSegmentStr.Length() <= 0)
  1039     if (aSegmentStr.Length() <= 0)
  1082         {
  1040         {
  1083         return;
  1041         return;
  1084         }
  1042         }
  1085 
  1043 
  1087 
  1045 
  1088     strInfo->segmentString.Zero();
  1046     strInfo->segmentString.Zero();
  1089     strInfo->segmentString.Copy(aSegmentStr);
  1047     strInfo->segmentString.Copy(aSegmentStr);
  1090     strInfo->segmentString.LowerCase();
  1048     strInfo->segmentString.LowerCase();
  1091     strInfo->isChinese = aChinese;
  1049     strInfo->isChinese = aChinese;
       
  1050     strInfo->segmentPos = aIndexAfterStr - aSegmentStr.Length();
  1092 
  1051 
  1093     aStringInfoArr.AppendL(strInfo);
  1052     aStringInfoArr.AppendL(strInfo);
  1094     aSegmentStr.Zero();
  1053     aSegmentStr.Zero();
  1095     CleanupStack::Pop( &aStringInfoArr );
       
  1096     }
  1054     }
  1097 
  1055 
  1098 // ---------------------------------------------------------
  1056 // ---------------------------------------------------------
  1099 // This segment is matched by search text
  1057 // This segment is matched by search text
  1100 // ---------------------------------------------------------
  1058 // ---------------------------------------------------------
  1101 //
  1059 //
  1102 TBool CFindUtilChineseECE::MatchSegmentL(RPointerArray<STRINGINFO>& aStringInfoArr, 
  1060 TBool CFindUtilChineseECE::MatchSegmentL(RPointerArray<STRINGINFO>& aStringInfoArr, 
  1103     CPsQuery& aQuery)
  1061     CPsQuery& aQuery, RArray<TInt>& aMatchPos, RArray<TInt>& aMatchLength, TBool aHighLight )
  1104     {
  1062     {
  1105     const TInt arrayLength = aStringInfoArr.Count();
  1063     const TInt arrayLength = aStringInfoArr.Count();
  1106     const TInt searchStrLength = aQuery.Count();
  1064     const TInt searchStrLength = aQuery.Count();
  1107     TInt searchStrIndex = 0;
       
  1108     STRINGINFO* pStringInfo;
  1065     STRINGINFO* pStringInfo;
  1109     TInt index = 0;
  1066     TInt index = 0;
  1110 
  1067     TBool ret = EFalse;
  1111     // First only check English
  1068     TBool hasChinese = EFalse;
       
  1069 
       
  1070     // First check if there is a full match in non-Chinese in any one segment
  1112     for (; index < arrayLength; index++)
  1071     for (; index < arrayLength; index++)
       
  1072         {
       
  1073         pStringInfo = aStringInfoArr[index];
       
  1074         TPtrC currentSeg( pStringInfo->segmentString );
       
  1075         TInt matchLen( 0 );
       
  1076 
       
  1077         // Compare word
       
  1078         if (pStringInfo->isChinese)
       
  1079             {
       
  1080             hasChinese = ETrue;
       
  1081             }
       
  1082         else
       
  1083             {
       
  1084             matchLen = MatchStringL( currentSeg, aQuery );
       
  1085             }
       
  1086         
       
  1087         // If full match is found
       
  1088         if ( matchLen == searchStrLength  )
       
  1089             {
       
  1090             //Only append postion of non-Chinese character
       
  1091             if(  !pStringInfo->isChinese )
       
  1092                 {
       
  1093                 aMatchPos.Append( pStringInfo->segmentPos );
       
  1094                 aMatchLength.Append( matchLen );
       
  1095                 }
       
  1096             ret =   ETrue;
       
  1097             
       
  1098             // If there is no need to HighLight the matched part, return immediately
       
  1099             // Otherwise, continue to find all the matched positions
       
  1100             if( !aHighLight ) 
       
  1101                 return ret;
       
  1102             }
       
  1103         }
       
  1104     
       
  1105     // Then search through segments again, this time considering
       
  1106     // also cases where matching part continues over several segments.
       
  1107     // This algorithm is greedy and heuristic and can't necesarily find
       
  1108     // all the matches in the segments after the first one.
       
  1109     TPtrC segCurrent;
       
  1110     TInt searchStrIndextemp = 0;
       
  1111     TInt searchStrIndexMax = 0;
       
  1112     TInt searchStrIndex = 0;
       
  1113     index = 0;
       
  1114 
       
  1115     // Loop through seqments until whole query is matched
       
  1116     for (; index < arrayLength && !ret ; index++)
  1113         {
  1117         {
  1114         // Create an empty CPsQuery
  1118         // Create an empty CPsQuery
  1115         CPsQuery* tempQuery = CPsQuery::NewL();
  1119         CPsQuery* tempQuery = CPsQuery::NewL();
       
  1120         CleanupStack::PushL( tempQuery );
       
  1121 
       
  1122         GetPartOfQueryL( aQuery, searchStrIndex, searchStrLength - 1, *tempQuery );
       
  1123 
  1116         pStringInfo = aStringInfoArr[index];
  1124         pStringInfo = aStringInfoArr[index];
  1117 
  1125         segCurrent.Set( pStringInfo->segmentString );
  1118         GetPartOfQueryL( aQuery, searchStrIndex, searchStrLength - 1,
  1126 
  1119             *tempQuery );
  1127         if (pStringInfo->isChinese)
  1120 
  1128             {
  1121         // Compare word
  1129             // find the longest substring matching the query
  1122         if (!pStringInfo->isChinese)
  1130             searchStrIndexMax = 0;
  1123             {
  1131             for (TInt i = 0; i< segCurrent.Length(); i++)
  1124             searchStrIndex += MatchString(pStringInfo->segmentString, *tempQuery);
  1132                 {
  1125             }
  1133                 TPtrC tempSeg( segCurrent.Mid(i) );
  1126 
  1134                 TInt startIdx( KErrNotFound );
  1127         delete tempQuery;
  1135                 TInt endIdx( KErrNotFound );
  1128         tempQuery = NULL;
  1136                 searchStrIndextemp = MatchChineseStringL(tempSeg, *tempQuery, startIdx, endIdx);
  1129 
  1137                 if (searchStrIndextemp > searchStrIndexMax)
  1130         if (searchStrIndex >= searchStrLength)
       
  1131             {
       
  1132             return ETrue;
       
  1133             }
       
  1134         }
       
  1135 
       
  1136     TBuf<KMaxWordLength> bufcurrent;
       
  1137     TBuf<KMaxWordLength> tempbufcurrent;
       
  1138     TInt searchStrIndextemp = 0;
       
  1139     TInt searchStrIndexMax = 0;
       
  1140     // Find Chinese and English
       
  1141     searchStrIndex = 0;
       
  1142     index = 0;
       
  1143 
       
  1144     for (; index < arrayLength; index++)
       
  1145         {
       
  1146         // Create an empty CPsQuery
       
  1147         CPsQuery* tempQuery = CPsQuery::NewL();
       
  1148         pStringInfo = aStringInfoArr[index];
       
  1149 
       
  1150         GetPartOfQueryL( aQuery, searchStrIndex, searchStrLength - 1,
       
  1151             *tempQuery );
       
  1152         searchStrIndexMax = 0;
       
  1153 
       
  1154         bufcurrent = pStringInfo->segmentString;
       
  1155 
       
  1156         for(TInt i =0;i< pStringInfo->segmentString.Length();i++)
       
  1157             {
       
  1158             tempbufcurrent = bufcurrent.Mid(i);
       
  1159             if (pStringInfo->isChinese)
       
  1160                 {
       
  1161                 TInt temp=0;
       
  1162                 searchStrIndextemp = MatchChineseStringL(tempbufcurrent, *tempQuery, temp);  
       
  1163                 if(searchStrIndextemp > searchStrIndexMax)
       
  1164                     {
  1138                     {
  1165                     searchStrIndex -= searchStrIndexMax;
  1139                     searchStrIndex -= searchStrIndexMax;
  1166                     searchStrIndexMax = searchStrIndextemp;
  1140                     searchStrIndexMax = searchStrIndextemp;
  1167                     searchStrIndex += searchStrIndexMax;
  1141                     searchStrIndex += searchStrIndexMax;
  1168                     }
  1142                     }
  1169                 }
  1143                 
  1170             else
  1144                 if (searchStrIndex >= searchStrLength)
  1171                 {
  1145                     {
  1172                 searchStrIndex += MatchString(pStringInfo->segmentString, *tempQuery);
  1146                     // found substring which consumes whole query, no need to find any longer
  1173                 }
  1147                     break;
  1174 
  1148                     }
  1175             if (searchStrIndex >= searchStrLength)
  1149                 }
  1176                 {
  1150             }
  1177                 delete tempQuery;
  1151         else // not chinese
  1178                 tempQuery = NULL;
  1152             {
  1179                 return ETrue;
  1153             TInt matchLen = MatchStringL(segCurrent, *tempQuery);
  1180                 }
  1154             searchStrIndex += matchLen;
  1181             else if(!pStringInfo->isChinese)
  1155             if ( matchLen )
  1182                 {
  1156                 {
  1183                 break;
  1157                 aMatchPos.Append( pStringInfo->segmentPos );
  1184                 }
  1158                 aMatchLength.Append( matchLen );
  1185             }
  1159                 }
  1186 
  1160             }
  1187         delete tempQuery;
  1161 
  1188         tempQuery = NULL;
  1162         if (searchStrIndex >= searchStrLength)
  1189         }
  1163             {
  1190 
  1164              ret = ETrue; // also breaks us out from the loop
  1191     return EFalse;
  1165             }
       
  1166         else if ( !pStringInfo->isChinese && !hasChinese )
       
  1167             {
       
  1168            CleanupStack::PopAndDestroy( tempQuery );
       
  1169             break;
       
  1170             }
       
  1171         
       
  1172         CleanupStack::PopAndDestroy( tempQuery );
       
  1173         }
       
  1174 
       
  1175     return ret;
  1192     }
  1176     }
  1193 
  1177 
  1194 // ---------------------------------------------------------
  1178 // ---------------------------------------------------------
  1195 // Search Chinese word in input text 
  1179 // Search Chinese word in input text 
  1196 // ---------------------------------------------------------
  1180 // ---------------------------------------------------------
  1197 //
  1181 //
  1198 TInt CFindUtilChineseECE::MatchChineseStringL(const TDesC& aSearhTargetString, CPsQuery& aQuery, TInt& aIndex)
  1182 TInt CFindUtilChineseECE::MatchChineseStringL(const TDesC& aSearhTargetString, CPsQuery& aQuery, 
       
  1183         TInt& aMatchStartIdx, TInt& aMatchEndIdx)
  1199     {
  1184     {
  1200     const TInt stringLength = aSearhTargetString.Length();
  1185     const TInt stringLength = aSearhTargetString.Length();
  1201     const TInt searchLength = aQuery.Count();
  1186     const TInt searchLength = aQuery.Count();
  1202     TInt index = 0;
  1187     TInt index = 0;
  1203     //TBuf<KMaxWordLength> tempBuf;
       
  1204     TBuf<KMaxWordLength> previousBuf;
  1188     TBuf<KMaxWordLength> previousBuf;
  1205     TInt curMatchCount = 0;
  1189     TInt curMatchCount = 0;
  1206     TInt preMatchCount = 0;
  1190     TInt preMatchCount = 0;
  1207     TInt matchIndex = 0;
  1191     TInt matchIndex = 0;
  1208     TInt curSearchIndex = 0;
  1192     TInt curSearchIndex = 0;
  1209     TBool bFullMatched = EFalse;
  1193     TBool bFullMatched = EFalse;
  1210     TBool bContinue = EFalse;
  1194     TBool bContinue = EFalse;
       
  1195     TBool bPrevReplaced = EFalse;
       
  1196     aMatchStartIdx = KErrNotFound;
       
  1197     aMatchEndIdx = KErrNotFound;
       
  1198     
       
  1199     CPsQuery* tempFullQuery = CPsQuery::NewL();
       
  1200     CleanupStack::PushL( tempFullQuery );
       
  1201     GetPartOfQueryL( aQuery, 0, aQuery.Count() - 1, *tempFullQuery );
  1211 
  1202 
  1212     for (; index < stringLength; index++)
  1203     for (; index < stringLength; index++)
  1213         {
  1204         {
  1214         RPointerArray<HBufC> spellList;
  1205         RPointerArray<HBufC> spellList;
  1215 
  1206 
  1224         matchIndex = 0;
  1215         matchIndex = 0;
  1225         bContinue = EFalse;
  1216         bContinue = EFalse;
  1226 
  1217 
  1227         // Get left string
  1218         // Get left string
  1228         CPsQuery* tempQuery = CPsQuery::NewL();
  1219         CPsQuery* tempQuery = CPsQuery::NewL();
  1229         GetPartOfQueryL( aQuery, curSearchIndex, searchLength - 1,
  1220         CleanupStack::PushL( tempQuery );
  1230             *tempQuery );
  1221         GetPartOfQueryL( aQuery, curSearchIndex, searchLength - 1, *tempQuery );
  1231 
  1222 
  1232         // Get Matched count and the matched index in list     
  1223         // Get Matched count and the matched index in list
  1233         curMatchCount = MaxMatchInList(spellList, *tempQuery, previousBuf, matchIndex, 
  1224         curMatchCount = MaxMatchInListL(spellList, *tempQuery, previousBuf, matchIndex, 
  1234             bFullMatched, preMatchCount, bContinue);
  1225             bFullMatched, preMatchCount, bContinue, bPrevReplaced, *tempFullQuery);
  1235 
  1226 
  1236         // There is a string matched in list 
  1227         // There is a string matched in list 
  1237         if (curMatchCount != 0)
  1228         if (curMatchCount != 0)
  1238             {
  1229             {
  1239             previousBuf.Copy(spellList[matchIndex]->Des());
  1230             previousBuf.Copy(*spellList[matchIndex]);
  1240 
  1231 
  1241             if (curMatchCount == previousBuf.Length())
  1232             if (curMatchCount == previousBuf.Length())
  1242                 {
  1233                 {
  1243                 bFullMatched = ETrue;
  1234                 bFullMatched = ETrue;
  1244                 }
  1235                 }
  1245             else
  1236             else
  1246                 {
  1237                 {
  1247                 bFullMatched = EFalse;
  1238                 bFullMatched = EFalse;
  1248                 }
  1239                 }
  1249 
  1240 
  1250             // If it is repeat match, continue     
  1241             // If it is repeat match, continue
  1251             if (!bContinue)
  1242             if (!bContinue)
  1252                 {
  1243                 {
  1253                 curSearchIndex += curMatchCount;
  1244                 curSearchIndex += curMatchCount;
  1254                 }
  1245                 }
  1255             else
  1246             else
  1256                 {
  1247                 {
  1257                 bFullMatched = EFalse;
  1248                 bFullMatched = EFalse;
  1258                 previousBuf.Zero();
  1249                 previousBuf.Zero();
  1259                 curMatchCount = 0;
  1250                 curMatchCount = 0;
  1260                 }
  1251                 }
       
  1252 
       
  1253             // Store the index of first matched Han character
       
  1254             if ( bPrevReplaced || aMatchStartIdx == KErrNotFound )
       
  1255                 {
       
  1256                 aMatchStartIdx = index;
       
  1257                 }
       
  1258             // Store the index of last matched Han character
       
  1259             aMatchEndIdx = index;
  1261             }
  1260             }
  1262         else
  1261         else
  1263             {
  1262             {
  1264             bFullMatched = EFalse;
  1263             bFullMatched = EFalse;
  1265             previousBuf.Zero();
  1264             previousBuf.Zero();
  1267                 {
  1266                 {
  1268                 index--;
  1267                 index--;
  1269                 }
  1268                 }
  1270 
  1269 
  1271             curSearchIndex = 0;
  1270             curSearchIndex = 0;
       
  1271             
       
  1272             // Any earlier partial match is discarded, reset the matching part indices
       
  1273             aMatchStartIdx = KErrNotFound;
       
  1274             aMatchEndIdx = KErrNotFound;
  1272             }
  1275             }
  1273 
  1276 
  1274         spellList.ResetAndDestroy();//destroy spellList
  1277         spellList.ResetAndDestroy();//destroy spellList
  1275         spellList.Close();
  1278         spellList.Close();
  1276         preMatchCount = curMatchCount;
  1279         preMatchCount = curMatchCount;
  1277 
  1280 
  1278         delete tempQuery;
  1281         CleanupStack::PopAndDestroy( tempQuery );
  1279         tempQuery = NULL;
  1282         tempQuery = NULL;
  1280 
  1283 
  1281         // Search to End and return
  1284         // Search to End and return
  1282         if (curSearchIndex >= searchLength)
  1285         if (curSearchIndex >= searchLength)
  1283             {
  1286             {
  1284             break;
  1287             break;
  1285             }
  1288             }
  1286         }
  1289         }
  1287 
  1290     CleanupStack::PopAndDestroy( tempFullQuery );
  1288     aIndex = index;
  1291     tempFullQuery = NULL;
       
  1292 
  1289     return curSearchIndex;
  1293     return curSearchIndex;
  1290     }
  1294     }
  1291 
  1295 
  1292 // ---------------------------------------------------------
  1296 // ---------------------------------------------------------
  1293 // Maximal matched count in spelling list  
  1297 // Maximal matched count in spelling list  
  1294 // ---------------------------------------------------------
  1298 // ---------------------------------------------------------
  1295 //
  1299 //
  1296 TInt CFindUtilChineseECE::MaxMatchInList(RPointerArray<HBufC> &spellList, CPsQuery& aQuery,
  1300 TInt CFindUtilChineseECE::MaxMatchInListL(RPointerArray<HBufC> &aSpellList, CPsQuery& aQuery,
  1297     TDesC& aPreviouStr, TInt& aMatchIndex, const TBool aFullMatched, 
  1301     TDesC& aPreviouStr, TInt& aMatchIndex, const TBool aFullMatched, 
  1298     const TInt aMatchedCount, TBool& aAgain)
  1302     const TInt aMatchedCount, TBool& aAgain, TBool& aPrevReplaced, CPsQuery& aFullQuery)
  1299     {
  1303     {
  1300     const TInt itemCount = spellList.Count();
  1304     const TInt itemCount = aSpellList.Count();
  1301     TInt matchCount = 0;
  1305     TInt matchCount = 0;
  1302     TBool selfMatch = EFalse;
  1306     TBool selfMatch = EFalse;
  1303     aMatchIndex = 0;
  1307     aMatchIndex = 0;
  1304 
  1308 
  1305     // If list is empty, then return
  1309     // If list is empty, then return
  1318         {
  1322         {
  1319         temp = 0;
  1323         temp = 0;
  1320         repeatCount = 0;
  1324         repeatCount = 0;
  1321         loopFlag = EFalse;
  1325         loopFlag = EFalse;
  1322         tempBuf.Zero();
  1326         tempBuf.Zero();
  1323         tempBuf.Copy(spellList[index]->Des());
  1327         tempBuf.Copy( *aSpellList[index] );
  1324 
  1328 
  1325         temp = MatchString(tempBuf, aQuery);
  1329         temp = MatchStringL(tempBuf, aQuery);
  1326         if(temp != 0)
  1330         if(temp != 0)
  1327             {
  1331             {
  1328             selfMatch = ETrue;
  1332             selfMatch = ETrue;
  1329             }
  1333             }
  1330         else
  1334         else
  1335         if (temp == 0 && aPreviouStr.Length() != 0)
  1339         if (temp == 0 && aPreviouStr.Length() != 0)
  1336             {
  1340             {
  1337             // Previous word is fully matched
  1341             // Previous word is fully matched
  1338             if (aFullMatched)
  1342             if (aFullMatched)
  1339                 {
  1343                 {
  1340                 repeatCount = ReverseMatchString(aPreviouStr, tempBuf);
  1344                 repeatCount = ReverseMatchStringL(aPreviouStr, tempBuf, aFullQuery );
  1341                 // Find repeat and remove it, search again
  1345                 // Find repeat and remove it, search again
  1342                 if (repeatCount != 0)
  1346                 if (repeatCount != 0)
  1343                     {
  1347                     {
  1344                     temp = MatchString(tempBuf.Right(tempBuf.Length() - repeatCount), aQuery);
  1348                     temp = MatchStringL(tempBuf.Right(tempBuf.Length() - repeatCount), aQuery);
  1345 
  1349 
  1346                     if (temp == 0)
  1350                     if (temp == 0)
  1347                         {
  1351                         {
  1348                         loopFlag = ETrue;
  1352                         loopFlag = ETrue;
  1349                         temp = repeatCount;
  1353                         temp = repeatCount;
  1350                         }
  1354                         }
  1351                     }
  1355                     }
  1352                 }
  1356                 }
  1353             else
  1357             else
  1354                 {
  1358                 {
  1355                 repeatCount = MatchString(aPreviouStr, tempBuf);
  1359                 repeatCount = MatchStringL(aPreviouStr, tempBuf, aFullQuery);
  1356 
  1360 
  1357                 // Find repeat and remove it, search again
  1361                 // Find repeat and remove it, search again
  1358                 if (repeatCount != 0)
  1362                 if (repeatCount != 0)
  1359                     {
  1363                     {
  1360                     if (aMatchedCount <= repeatCount)
  1364                     if (aMatchedCount <= repeatCount)
  1361                         {
  1365                         {
  1362                         temp = MatchString(tempBuf.Right(tempBuf.Length() - aMatchedCount), aQuery);
  1366                         temp = MatchStringL(tempBuf.Right(tempBuf.Length() - aMatchedCount), aQuery);
  1363 
  1367 
  1364                         if (temp == 0)
  1368                         if (temp == 0)
  1365                             {
  1369                             {
  1366                             loopFlag = ETrue;
  1370                             loopFlag = ETrue;
  1367                             temp = aMatchedCount;
  1371                             temp = aMatchedCount;
  1369                         }
  1373                         }
  1370                     }
  1374                     }
  1371 
  1375 
  1372                 if (temp == 0)
  1376                 if (temp == 0)
  1373                     {
  1377                     {
  1374                     repeatCount = ReverseMatchString(aPreviouStr.Left(aMatchedCount), tempBuf);
  1378                     repeatCount = ReverseMatchStringL(aPreviouStr.Left(aMatchedCount), tempBuf, aFullQuery);
  1375 
  1379 
  1376                     if (repeatCount != 0)
  1380                     if (repeatCount != 0)
  1377                         {
  1381                         {
  1378                         temp = MatchString(tempBuf.Right(tempBuf.Length() - repeatCount), aQuery);
  1382                         temp = MatchStringL(tempBuf.Right(tempBuf.Length() - repeatCount), aQuery);
  1379 
  1383 
  1380                         if (temp == 0)
  1384                         if (temp == 0)
  1381                             {
  1385                             {
  1382                             loopFlag = ETrue;
  1386                             loopFlag = ETrue;
  1383                             temp = repeatCount;
  1387                             temp = repeatCount;
  1412             {
  1416             {
  1413             matchCount = temp;
  1417             matchCount = temp;
  1414             aMatchIndex = index;
  1418             aMatchIndex = index;
  1415             aAgain = loopFlag;
  1419             aAgain = loopFlag;
  1416             }
  1420             }
  1417         if(matchCount == aQuery.Count() && selfMatch)
  1421         if (matchCount == aQuery.Count() && selfMatch)
  1418             {
  1422             {
  1419             break;
  1423             break;
  1420             }
  1424             }
  1421         }
  1425         }
       
  1426     
       
  1427     // Was the previous match replaced with a longer match from this spell list
       
  1428     aPrevReplaced = ( matchCount && repeatCount );
       
  1429     
  1422     return matchCount;
  1430     return matchCount;
  1423     }
  1431     }
  1424 
  1432 
  1425 // ---------------------------------------------------------
  1433 // ---------------------------------------------------------
  1426 // Search the taxt is include the input text  
  1434 // Search the text is include the input text  
  1427 // ---------------------------------------------------------
  1435 // ---------------------------------------------------------
  1428 //
  1436 //
  1429 TBool CFindUtilChineseECE::IncludeString(const TDesC& aFirst, const TDesC& aSecond)
  1437 TBool CFindUtilChineseECE::IncludeString(const TDesC& aFirst, const TDesC& aSecond)
  1430     {
  1438     {
  1431     TBuf<KMaxWordLength> tempBuf;
  1439     TBuf<KMaxWordLength> tempBuf;
  1453 
  1461 
  1454 // ---------------------------------------------------------
  1462 // ---------------------------------------------------------
  1455 // Search text in other text  
  1463 // Search text in other text  
  1456 // ---------------------------------------------------------
  1464 // ---------------------------------------------------------
  1457 //
  1465 //
  1458 TInt CFindUtilChineseECE::MatchString(const TDesC& aFirst, const TDesC& aSecond)
  1466 TInt CFindUtilChineseECE::MatchStringL(const TDesC& aFirst, const TDesC& aSecond, CPsQuery& aFullQuery)
  1459     {
  1467     {
  1460     const TInt secondStrLength = aSecond.Length();
  1468     const TInt secondStrLength = aSecond.Length();
  1461     const TInt firstStrLength = aFirst.Length();
  1469     const TInt firstStrLength = aFirst.Length();
  1462 
  1470 
  1463     const TInt compareCount = firstStrLength > secondStrLength ? secondStrLength
  1471     const TInt compareCount = Min( firstStrLength, secondStrLength );
  1464         : firstStrLength;
       
  1465     TInt index = 0;
  1472     TInt index = 0;
  1466 
  1473     TBuf<KMaxWordInterpretationLen> firstNumInterpretationBuf;
  1467     TBuf<KMaxWordLength> tempStr;
  1474     TBuf<KMaxWordInterpretationLen> secondNumInterpretationBuf;
  1468     // translate search target string into numeric string before match
  1475     
  1469     if (iAlgorithm)
  1476     iAlgorithm->GetKeyMap()->GetMixedKeyStringForDataL(aFullQuery, aFirst, firstNumInterpretationBuf);
  1470         {
  1477     iAlgorithm->GetKeyMap()->GetMixedKeyStringForDataL(aFullQuery, aSecond, secondNumInterpretationBuf);
  1471         iAlgorithm->Converter( aFirst, tempStr );
       
  1472         }
       
  1473     else
       
  1474         {
       
  1475         tempStr.Copy(aFirst);
       
  1476         }
       
  1477 
  1478 
  1478     for (; index < compareCount; index++)
  1479     for (; index < compareCount; index++)
  1479         {
  1480         {
  1480         if (tempStr.Left(index + 1).FindC(aSecond.Left(index + 1)) == KErrNotFound)
  1481         if (firstNumInterpretationBuf.Left(index + 1).FindC(secondNumInterpretationBuf.Left(index + 1)) == KErrNotFound)
  1481             {
  1482             {
  1482             break;
  1483             break;
  1483             }
  1484             }
  1484         }
  1485         }
  1485     // Match count
  1486     // Match count
  1486     return index;
  1487     return index;
  1487     }
  1488     }
       
  1489 
  1488 // ---------------------------------------------------------
  1490 // ---------------------------------------------------------
  1489 // Search CPsQuery in aSearhTargetStr
  1491 // Search CPsQuery in aSearhTargetStr
  1490 // ---------------------------------------------------------
  1492 // ---------------------------------------------------------
  1491 //
  1493 //
  1492 TInt CFindUtilChineseECE::MatchString(const TDesC& aSearhTargetStr, CPsQuery& aQuery)
  1494 TInt CFindUtilChineseECE::MatchStringL(const TDesC& aSearhTargetStr, CPsQuery& aQuery)
  1493     {
  1495     {
  1494     const TInt secondStrLength = aQuery.Count();
  1496     const TInt secondStrLength = aQuery.Count();
  1495     const TInt firstStrLength = aSearhTargetStr.Length();
  1497     const TInt firstStrLength = aSearhTargetStr.Length();
  1496     TBuf<KMaxWordInterpretationLen> numInterpretationBuf;
  1498     TBuf<KMaxWordInterpretationLen> numInterpretationBuf;
  1497 
  1499     TBuf<KMaxWordInterpretationLen> queryStr;
  1498     const TInt compareCount = firstStrLength > secondStrLength ? secondStrLength
  1500 
  1499         : firstStrLength;
  1501     const TInt compareCount = Min( firstStrLength, secondStrLength );
       
  1502 
  1500     TInt index = 0;
  1503     TInt index = 0;
  1501 
  1504 
  1502     ConvertdDataToKeyBoardModeL(aQuery, aSearhTargetStr, numInterpretationBuf);
  1505     iAlgorithm->GetKeyMap()->GetMixedKeyStringForDataL(aQuery, aSearhTargetStr, numInterpretationBuf);
  1503 
  1506     iAlgorithm->GetKeyMap()->GetMixedKeyStringForQueryL(aQuery, queryStr);
  1504     TPtrC queryStr = aQuery.QueryAsStringLC();
  1507 
  1505     for (; index < compareCount; index++)
  1508     for (; index < compareCount; index++)
  1506         {
  1509         {
  1507 
       
  1508         if (numInterpretationBuf.Left(index + 1).FindC(queryStr.Left(index + 1)) == KErrNotFound)
  1510         if (numInterpretationBuf.Left(index + 1).FindC(queryStr.Left(index + 1)) == KErrNotFound)
  1509             {
  1511             {
  1510             break;
  1512             break;
  1511             }
  1513             }
  1512         }
  1514         }
  1513     CleanupStack::PopAndDestroy();
       
  1514 
  1515 
  1515     // Match count
  1516     // Match count
  1516     return index;
  1517     return index;
  1517     }
  1518     }
  1518 
  1519 
  1519 // ---------------------------------------------------------
  1520 // ---------------------------------------------------------
  1520 // Search text by reverse  
  1521 // Search text by reverse  
  1521 // ---------------------------------------------------------
  1522 // ---------------------------------------------------------
  1522 //
  1523 //
  1523 TInt CFindUtilChineseECE::ReverseMatchString(const TDesC& aFirst, const TDesC& aSecond)
  1524 TInt CFindUtilChineseECE::ReverseMatchStringL(const TDesC& aFirst, const TDesC& aSecond, CPsQuery& aFullQuery)
  1524     {
  1525     {
  1525     const TInt secondStrLength = aSecond.Length();
  1526     const TInt secondStrLength = aSecond.Length();
  1526     const TInt firstStrLength = aFirst.Length();
  1527     const TInt firstStrLength = aFirst.Length();
  1527     TInt compareCount = firstStrLength > secondStrLength ? secondStrLength : firstStrLength;
  1528     TInt compareCount = firstStrLength > secondStrLength ? secondStrLength : firstStrLength;
  1528     TInt index = 0;
  1529     TInt index = 0;
  1529     TInt matchCount = 0;
  1530     TInt matchCount = 0;
  1530 
  1531     TBuf<KMaxWordInterpretationLen> firstNumInterpretationBuf;
       
  1532     TBuf<KMaxWordInterpretationLen> secondNumInterpretationBuf;
       
  1533     
       
  1534     iAlgorithm->GetKeyMap()->GetMixedKeyStringForDataL(aFullQuery, aFirst, firstNumInterpretationBuf);
       
  1535     iAlgorithm->GetKeyMap()->GetMixedKeyStringForDataL(aFullQuery, aSecond, secondNumInterpretationBuf);
       
  1536     
  1531     for (; index < compareCount; index++)
  1537     for (; index < compareCount; index++)
  1532         {
  1538         {
  1533         TBuf<KMaxWordLength> firstConvStr;
  1539         if( firstNumInterpretationBuf.Right( index + 1 ).FindC( secondNumInterpretationBuf.Left( index + 1 ) ) != KErrNotFound )
  1534         TBuf<KMaxWordLength> secondConvStr;
       
  1535 
       
  1536         // translate compared target string into numeric string before match
       
  1537         if ( iAlgorithm )
       
  1538             {
       
  1539             iAlgorithm->Converter( aFirst, firstConvStr );
       
  1540             iAlgorithm->Converter( aSecond, secondConvStr );
       
  1541             }
       
  1542         else
       
  1543             {
       
  1544             firstConvStr.Copy( aFirst );
       
  1545             secondConvStr.Copy( aSecond );
       
  1546             }
       
  1547 
       
  1548         if( firstConvStr.Right( index + 1 ).FindC( secondConvStr.Left( index + 1 ) ) != KErrNotFound )
       
  1549             {
  1540             {
  1550             matchCount = index + 1;
  1541             matchCount = index + 1;
  1551             }
  1542             }
  1552         }
  1543         }
  1553 
  1544 
  1565 
  1556 
  1566 // ---------------------------------------------------------
  1557 // ---------------------------------------------------------
  1567 // Find pane text is including Chinese word  
  1558 // Find pane text is including Chinese word  
  1568 // ---------------------------------------------------------
  1559 // ---------------------------------------------------------
  1569 //
  1560 //
  1570 TBool CFindUtilChineseECE::IsChineseWord(const TDesC& aWord)
  1561 TBool CFindUtilChineseECE::IsChineseWordIncluded(const TDesC& aWord)
  1571     {
  1562     {
  1572     TBool IsChineseSearchStr = EFalse;
  1563     TBool IsChineseSearchStr = EFalse;
  1573     const TInt len = aWord.Length();
  1564     const TInt len = aWord.Length();
  1574 
  1565 
  1575     for (TInt ii = 0; ii < len; ii++)
  1566     for (TInt ii = 0; ii < len; ii++)
  1576         {
  1567         {
  1577         if ((TInt) aWord[ii] >= KMinUnicodeHz)
  1568 
       
  1569         if ( ((TUint16) aWord[ii] >= KMinUnicodeHz) &&
       
  1570             ((TUint16) aWord[ii] <= KMaxUnicodeHz) )
  1578             {
  1571             {
  1579             IsChineseSearchStr = ETrue;
  1572             IsChineseSearchStr = ETrue;
  1580             break;
  1573             break;
  1581             }
  1574             }
  1582         }
  1575         }
  1592     {
  1585     {
  1593     const TInt len = aWord.Length();
  1586     const TInt len = aWord.Length();
  1594 
  1587 
  1595     for (TInt index = 0; index < len; index++)
  1588     for (TInt index = 0; index < len; index++)
  1596         {
  1589         {
  1597         if (IsStrokeSymbol(TInt(aWord[index])) != 0)
  1590         if (IsStrokeSymbol(TUint16(aWord[index])) != 0)
  1598             {
  1591             {
  1599             return ETrue;
  1592             return ETrue;
  1600             }
  1593             }
  1601         }
  1594         }
  1602     return EFalse;
  1595     return EFalse;
       
  1596     }
       
  1597 
       
  1598 // --------------------------------------------------------
       
  1599 // Find pane text is all Chinese word(s)
       
  1600 // --------------------------------------------------------
       
  1601 //
       
  1602 TBool CFindUtilChineseECE::IsAllChineseWord(const TDesC& aWord)
       
  1603     {
       
  1604     TBool isChineseWord = ETrue;
       
  1605     const TInt len = aWord.Length();
       
  1606     
       
  1607     TBool InputMethodStroke = EFalse;
       
  1608     if(iLanguage == ELangHongKongChinese && iCurInputMode == 0x0020)
       
  1609         {
       
  1610         InputMethodStroke = ETrue;
       
  1611         }
       
  1612     
       
  1613     for( TInt i = 0; i < len; i++ )
       
  1614         {
       
  1615         if( (( TUint16 )aWord[i] > KMaxUnicodeHz ) ||  (( TUint16 )aWord[i] < KMinUnicodeHz )
       
  1616             || ( InputMethodStroke && IsStrokeSymbol(aWord[i]) ) )
       
  1617             {
       
  1618             isChineseWord = EFalse;
       
  1619             break;
       
  1620             }
       
  1621         }
       
  1622     return isChineseWord;
  1603     }
  1623     }
  1604 
  1624 
  1605 // ---------------------------------------------------------
  1625 // ---------------------------------------------------------
  1606 // Find pane text is including zhuyin symbol  
  1626 // Find pane text is including zhuyin symbol  
  1607 // ---------------------------------------------------------
  1627 // ---------------------------------------------------------
  1641 // ---------------------------------------------------------
  1661 // ---------------------------------------------------------
  1642 //
  1662 //
  1643 TInt CFindUtilChineseECE::HandleFindRepositoryCallBack(TAny* aPtr)
  1663 TInt CFindUtilChineseECE::HandleFindRepositoryCallBack(TAny* aPtr)
  1644     {
  1664     {
  1645     TInt ret = KErrNone;
  1665     TInt ret = KErrNone;
  1646     CFindUtilChineseECE *self = static_cast<CFindUtilChineseECE*> (aPtr);
  1666     CFindUtilChineseECE* self = static_cast<CFindUtilChineseECE*> (aPtr);
  1647     TInt searchMode = 0;
  1667 
  1648 
  1668     // Get changed key either from language repository (AknFepRepository)
  1649     if (self->iWatcher->ChangedKey() == KAknFepInputTxtLang)
  1669     // or from adaptive repository (AvkonRepository).
  1650         {
  1670     TUint32 changedKey = self->iWatcher->ChangedKey();
  1651         TInt inputLanguage = 0;
  1671     if ( changedKey == NCentralRepositoryConstants::KInvalidNotificationId )
  1652         self->iRepositoryFind->Get(KAknFepInputTxtLang, inputLanguage);
  1672         {
  1653 
  1673         changedKey = self->iWatcherAdaptive->ChangedKey();
  1654         TInt prevCategory = self->CategoryOfLang(self->iLanguage);
  1674         }
  1655         TRAP(ret, self->OpenT9InterfaceL(TLanguage(inputLanguage)));
  1675 
  1656 
  1676 
  1657         TInt category = self->CategoryOfLang(TLanguage(inputLanguage));
  1677     // Update the search method if input language or any search method variable
  1658         if (prevCategory != category && category != 0)
  1678     // changed
       
  1679     if ( changedKey == KAknFepInputTxtLang ||
       
  1680          changedKey == KAknAdaptiveSearchChinesePRC ||
       
  1681          changedKey == KAknAdaptiveSearchChineseTW ||
       
  1682          changedKey == KAknAdaptiveSearchChineseHongkong ||
       
  1683          changedKey == KAknFepCangJieMode ||
       
  1684          changedKey == KAknAvkonAdaptiveSearchEnabled )
       
  1685         {
       
  1686         TChineseSearchMethod prevSearchMethods = self->iSearchMethod;
       
  1687 
       
  1688         TRAP( ret, self->OpenL() );
       
  1689         
       
  1690         // Reconstruct cache if search method got changed
       
  1691         if ( ret == KErrNone && prevSearchMethods != self->iSearchMethod )
  1659             {
  1692             {
  1660             TRAP(ret, self->iAlgorithm->ReconstructCacheDataL());
  1693             TRAP(ret, self->iAlgorithm->ReconstructCacheDataL());
  1661             }
  1694             }
  1662         }
  1695         }
  1663 
  1696     
  1664     // The below code is commented out because current CFindUtilChineseECE is used
       
  1665     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
  1666     // for the further merging work (merge from FindUtil 5.0)
       
  1667 #if 0    
       
  1668     if(self->iWatcherAdaptive->ChangedKey() == KAknAvkonAdaptiveSearchEnabled)
       
  1669         {
       
  1670         self->iRepositoryFindAdaptive->Get(KAknAvkonAdaptiveSearchEnabled, self->iSearchMethodAdaptive);
       
  1671         }
       
  1672 
       
  1673     if (self->iWatcherAdaptive->ChangedKey() == KAknAdaptiveSearchChinesePRC)
       
  1674         {
       
  1675         self->iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChinesePRC, searchMode);
       
  1676 
       
  1677         if(searchMode ==0)
       
  1678             {
       
  1679             self->iSearchMethodPRC = EAdptSearchPinyin;	
       
  1680             }
       
  1681         else if(searchMode ==1)
       
  1682             {
       
  1683             self->iSearchMethodPRC = EAdptSearchStroke;	
       
  1684             }
       
  1685         }
       
  1686 
       
  1687     if (self->iWatcherAdaptive->ChangedKey() == KAknAdaptiveSearchChineseTW )
       
  1688         {
       
  1689         self->iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseTW , searchMode);
       
  1690 
       
  1691         if(searchMode ==0)
       
  1692             {
       
  1693             self->iSearchMethodTaiWan = EAdptSearchZhuyin;	
       
  1694             }
       
  1695         else if(searchMode ==1)
       
  1696             {
       
  1697             self->iSearchMethodTaiWan = EAdptSearchStroke;	
       
  1698             }
       
  1699         }
       
  1700 
       
  1701     if (self->iWatcherAdaptive->ChangedKey() == KAknAdaptiveSearchChineseHongkong )
       
  1702         {
       
  1703         self->iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseHongkong , searchMode);
       
  1704 
       
  1705         if(searchMode ==1)
       
  1706             {
       
  1707             self->iRepositoryFind->Get(KAknFepCangJieMode , searchMode);
       
  1708 
       
  1709             switch (searchMode)
       
  1710                 {
       
  1711                 case 0:
       
  1712                     self->iSearchMethodHongKong = EAdptSearchNormalCangjie;
       
  1713                     break;
       
  1714                 case 1:
       
  1715                     self->iSearchMethodHongKong = EAdptSearchEasyCangjie;
       
  1716                     break;
       
  1717                 case 2:
       
  1718                     self->iSearchMethodHongKong = EAdptSearchAdvCangjie;
       
  1719                     break;	
       
  1720                 }
       
  1721 
       
  1722             }
       
  1723         else if(searchMode ==0)
       
  1724             {
       
  1725             self->iSearchMethodHongKong = EAdptSearchStroke;	
       
  1726             }
       
  1727         }
       
  1728 
       
  1729     if (self->iWatcher->ChangedKey() == KAknFepCangJieMode )
       
  1730         {
       
  1731         self->iRepositoryFind->Get(KAknFepCangJieMode , searchMode);
       
  1732 
       
  1733         switch (searchMode)
       
  1734             {
       
  1735             case 0:
       
  1736                 self->iSearchMethodHongKong = EAdptSearchNormalCangjie;
       
  1737                 break;
       
  1738             case 1:
       
  1739                 self->iSearchMethodHongKong = EAdptSearchEasyCangjie;
       
  1740                 break;
       
  1741             case 2:
       
  1742                 self->iSearchMethodHongKong = EAdptSearchAdvCangjie;
       
  1743                 break;	
       
  1744             }
       
  1745 
       
  1746         }
       
  1747 #endif
       
  1748     return ret;
  1697     return ret;
  1749     }
  1698     }
  1750 
  1699 
  1751 // ---------------------------------------------------------
  1700 // ---------------------------------------------------------
  1752 // Update input method in ptiengine from find pane
  1701 // Update input method in ptiengine from find pane
  1773                 {
  1722                 {
  1774                 iCurInputMode = pState->CurrentInputMode();
  1723                 iCurInputMode = pState->CurrentInputMode();
  1775                 }
  1724                 }
  1776             }
  1725             }
  1777         }
  1726         }
  1778     }
       
  1779 
       
  1780 void CFindUtilChineseECE::SetKeyboardMode(TInt aMode)
       
  1781     {
       
  1782     iKeyboardMode = aMode;
       
  1783     }
  1727     }
  1784 
  1728 
  1785 // The below code is commented out because current CFindUtilChineseECE is used
  1729 // The below code is commented out because current CFindUtilChineseECE is used
  1786 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
  1730 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
  1787 // for the further merging work (merge from FindUtil 5.0)
  1731 // for the further merging work (merge from FindUtil 5.0)
  1796         {			
  1740         {			
  1797         if( aNextChars->Des().Length() == aNextChars->Des().MaxLength())
  1741         if( aNextChars->Des().Length() == aNextChars->Des().MaxLength())
  1798             {
  1742             {
  1799             aNextChars = aNextChars->ReAllocL( aNextChars->Des().MaxLength()+10 );
  1743             aNextChars = aNextChars->ReAllocL( aNextChars->Des().MaxLength()+10 );
  1800             }		
  1744             }		
  1801         aNextChars->Des().Append(aCh);								
  1745         aNextChars->Des().Append(aCh);
  1802         }
  1746         }
  1803     }    
  1747     }    
  1804 
  1748 
  1805 // ---------------------------------------------------------------------------
  1749 // ---------------------------------------------------------------------------
  1806 // UpdateNextCharFromString
  1750 // UpdateNextCharFromString
  1988                 - searchStrIndex);
  1932                 - searchStrIndex);
  1989 
  1933 
  1990             // Compare word
  1934             // Compare word
  1991             if (!pStringInfo->isChinese)
  1935             if (!pStringInfo->isChinese)
  1992                 {
  1936                 {
  1993                 searchStrIndex += MatchString(pStringInfo->segmentString,
  1937                 searchStrIndex += MatchStringL(pStringInfo->segmentString,
  1994                     transSearchBuf);
  1938                     transSearchBuf);
  1995                 }
  1939                 }
  1996 
  1940 
  1997             if (searchStrIndex >= searchStrLength)
  1941             if (searchStrIndex >= searchStrLength)
  1998                 {
  1942                 {
  2068                 }
  2012                 }
  2069             }
  2013             }
  2070 
  2014 
  2071         }
  2015         }
  2072     tempSpellList.ResetAndDestroy();
  2016     tempSpellList.ResetAndDestroy();
  2073     if(ReverseMatchString(aCurrentBuf,temp)>0)
  2017     if(ReverseMatchStringL(aCurrentBuf,temp)>0)
  2074         {
  2018         {
  2075         if (pStringInfo->isChinese)
  2019         if (pStringInfo->isChinese)
  2076             {
  2020             {
  2077             if((pStringInfo->segmentString).Length()>aindexforfind+2)//in same segment
  2021             if((pStringInfo->segmentString).Length()>aindexforfind+2)//in same segment
  2078                 {
  2022                 {
  2318         }                
  2262         }                
  2319 
  2263 
  2320     //Find if search string has chinese word. 
  2264     //Find if search string has chinese word. 
  2321     //Compare with item string if find chinese word in item string then delete it from search and item string.
  2265     //Compare with item string if find chinese word in item string then delete it from search and item string.
  2322 
  2266 
  2323     if(IsChineseWord(tempBuf))
  2267     if(IsChineseWordIncluded(tempBuf))
  2324         {
  2268         {
  2325         if(TrimChineseCharacterL(itemString,tempBuf,aNextChars))
  2269         if(TrimChineseCharacterL(itemString,tempBuf,aNextChars))
  2326             {
  2270             {
  2327             spellList.ResetAndDestroy();//destroy spellList
  2271             spellList.ResetAndDestroy();//destroy spellList
  2328             spellList.Close();
  2272             spellList.Close();
  2403                     indexlast = index;
  2347                     indexlast = index;
  2404                     }
  2348                     }
  2405                 }
  2349                 }
  2406             else
  2350             else
  2407                 {//english words and chinese words don't coexist in same segment
  2351                 {//english words and chinese words don't coexist in same segment
  2408                 matchLength = MatchString(bufcurrent, transSearchBuf);
  2352                 matchLength = MatchStringL(bufcurrent, transSearchBuf);
  2409                 searchStrIndex +=matchLength;
  2353                 searchStrIndex +=matchLength;
  2410                 if (searchStrIndex >= searchStrLength)
  2354                 if (searchStrIndex >= searchStrLength)
  2411                     {
  2355                     {
  2412                     //append next char in the same segment
  2356                     //append next char in the same segment
  2413                     ret = ETrue;
  2357                     ret = ETrue;
  2552     return IsAdaptiveFindMatchL( aItemString, aSearchText, aNextChars);		    
  2496     return IsAdaptiveFindMatchL( aItemString, aSearchText, aNextChars);		    
  2553 
  2497 
  2554     }
  2498     }
  2555 #endif
  2499 #endif
  2556 
  2500 
  2557 // ----------------------------------------------------------------------------
       
  2558 // CFindUtilChineseECE::ConvertdDataToKeyBoardModeL
       
  2559 // Converts the input data to the key board mode specified by the query
       
  2560 // ----------------------------------------------------------------------------
       
  2561 void CFindUtilChineseECE::ConvertdDataToKeyBoardModeL(CPsQuery& aQuery, 
       
  2562     const TDesC& aSearchTargetStr, 
       
  2563     TBuf<KMaxWordInterpretationLen>& aOutputNumInterpretationStr)
       
  2564     {    
       
  2565     if (iKeyboardMode == EItut)
       
  2566         {
       
  2567         iAlgorithm->GetKeyMap()->GetNumericKeyString(aSearchTargetStr, aOutputNumInterpretationStr);
       
  2568         }
       
  2569     else if (iKeyboardMode == EQwerty)
       
  2570         {
       
  2571         aOutputNumInterpretationStr = aSearchTargetStr;
       
  2572         aOutputNumInterpretationStr.LowerCase();
       
  2573         }
       
  2574     else
       
  2575         {
       
  2576 
       
  2577         TInt len = -1;
       
  2578         TBuf<KPsQueryMaxLen> outBuf;
       
  2579 
       
  2580         iAlgorithm->GetKeyMap()->GetNumericKeyString(aSearchTargetStr, outBuf);
       
  2581 
       
  2582         // Always loop thru the lowest length
       
  2583         if (aSearchTargetStr.Length() > aQuery.Count() )
       
  2584             {
       
  2585             len = aQuery.Count();
       
  2586             }
       
  2587         else
       
  2588             {
       
  2589             len = aSearchTargetStr.Length();
       
  2590             }
       
  2591 
       
  2592         // Interprete search target str according to the query char mode
       
  2593         for (TInt i = 0; i < len; i++)
       
  2594             {
       
  2595             if (aQuery.GetItemAtL(i).Mode() == EItut)
       
  2596                 {
       
  2597                 aOutputNumInterpretationStr.Append(outBuf[i]);
       
  2598                 }
       
  2599             else
       
  2600                 {
       
  2601                 aOutputNumInterpretationStr.Append(aSearchTargetStr[i]);
       
  2602                 }
       
  2603             }
       
  2604 
       
  2605         aOutputNumInterpretationStr.LowerCase();
       
  2606         }
       
  2607     }
       
  2608 
       
  2609 void CFindUtilChineseECE::GetPartOfQueryL(CPsQuery& aSrcQuery, TInt aStartIndex, 
  2501 void CFindUtilChineseECE::GetPartOfQueryL(CPsQuery& aSrcQuery, TInt aStartIndex, 
  2610     TInt aEndIndex, CPsQuery& aDestQuery)
  2502     TInt aEndIndex, CPsQuery& aDestQuery)
  2611     {
  2503     {
  2612     TInt index = aStartIndex;
  2504     TInt index = aStartIndex;
  2613 
  2505 
  2622             newItem->SetCharacter(tempItem.Character());
  2514             newItem->SetCharacter(tempItem.Character());
  2623             newItem->SetMode(tempItem.Mode());
  2515             newItem->SetMode(tempItem.Mode());
  2624 
  2516 
  2625             aDestQuery.AppendL(*newItem);
  2517             aDestQuery.AppendL(*newItem);
  2626             }
  2518             }
  2627 
       
  2628         }
  2519         }
  2629     else 
  2520     else 
  2630         {
  2521         {
  2631         User::Panic(KPanicReason, 0);
  2522         User::Panic(KPanicReason, 0);
  2632         }
  2523         }
  2649                 // remove the charator of index
  2540                 // remove the charator of index
  2650                 aQuery.Remove( index );
  2541                 aQuery.Remove( index );
  2651                 // ajust index after remove
  2542                 // ajust index after remove
  2652                 index--; 
  2543                 index--; 
  2653                 }
  2544                 }
       
  2545                 break;
  2654             default:
  2546             default:
  2655                 continue;
  2547                 continue;
  2656             } // switch
  2548             } // switch
  2657         } // for
  2549         } // for
  2658     }
  2550     }