predictivesearch/PcsAlgorithm/Algorithm2/src/FindUtilChineseECE.cpp
changeset 0 e686773b3f54
child 11 2828b4d142c0
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Chinese Find Utilities implementation file.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <PtiEngine.h>
       
    19 #include <centralrepository.h>
       
    20 #include <AknFepInternalCRKeys.h>
       
    21 #include <aknedsts.h>
       
    22 #include <coeaui.h>
       
    23 // 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 
       
    25 // for the further merging work (merge from FindUtil 5.0)
       
    26 #if 0
       
    27 #include <AvkonInternalCRKeys.h>
       
    28 #include <aknenv.h> //phonebook
       
    29 #include <aknappui.h>
       
    30 #include <aknapp.h>
       
    31 #include <eikenv.h>
       
    32 #include <eikapp.h>
       
    33 #include <eikappui.h>
       
    34 #endif
       
    35 
       
    36 #include "CPcsAlgorithm2.h"
       
    37 #include "FindUtilChineseECE.h"
       
    38 #include "chinesefindutils.h"
       
    39 #include "CPcsKeyMap.h"
       
    40 #include "CPsQuery.h"
       
    41 #include "CPsQueryItem.h"
       
    42 
       
    43 // CONSTANTS 
       
    44 const TUint16 KStarChar = 0x002a;
       
    45 const TUint16 KZhuyinstart = 0x3105;
       
    46 const TInt KZhuyincount = 37;
       
    47 const TInt KSeperator = 2626;
       
    48 const TInt16 KMinUnicodeHz = 0x4e00;
       
    49 const TInt16 KStrokeHorizontalValue = 0x4e00;
       
    50 const TInt16 KStrokeVerticalValue = 0x4e28;
       
    51 const TInt16 KStrokeDownToLeftValue = 0x4e3f;
       
    52 const TInt16 KStrokeDownToRightValue = 0x4e36;
       
    53 const TInt16 KStrokeBendingValue = 0x4e5b;
       
    54 const TInt KSysInputMode = -1;
       
    55 const TInt KLeftToRightFlag =0x200e;
       
    56 const TInt KRightToLeftFlag =0x200f;
       
    57 // 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 
       
    59 // for the further merging work (merge from FindUtil 5.0)
       
    60 #if 0
       
    61 const TUid KUidPhoneBook = {0x101F4CCE};
       
    62 const TUid KUidPhoneBookServer = {0x10207277};
       
    63 #endif
       
    64 
       
    65 _LIT(KWildChar, "*");
       
    66 _LIT(KUnderLine, "_");
       
    67 _LIT(KMiddleLine, "-");
       
    68 _LIT(KBlank, " ");
       
    69 _LIT(KTab, "\t");
       
    70 _LIT(KPanicReason, "Abnormal input parameters!");
       
    71 
       
    72 const TInt KLitLineFeed(8233);
       
    73 // ======== MEMBER FUNCTIONS ========
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // Symbian constructor
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 CFindUtilChineseECE* CFindUtilChineseECE::NewL(CPcsAlgorithm2* aAlgorithm)
       
    80     {
       
    81     CFindUtilChineseECE* self = new (ELeave) CFindUtilChineseECE();
       
    82 
       
    83     CleanupStack::PushL(self);
       
    84     self->ConstructL(aAlgorithm);
       
    85     CleanupStack::Pop(self);//self
       
    86 
       
    87     return self;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // Symbian second-phase constructor
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 void CFindUtilChineseECE::ConstructL(CPcsAlgorithm2* aAlgorithm)
       
    95     {
       
    96     iRepositoryFind = CRepository::NewL(KCRUidAknFep);
       
    97     // The below code is commented out because current CFindUtilChineseECE is used
       
    98     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
    99     // for the further merging work (merge from FindUtil 5.0)
       
   100 #if 0   
       
   101     iRepositoryFindAdaptive = CRepository::NewL(KCRUidAvkon);
       
   102 #endif
       
   103 
       
   104     iWatcher = CFindRepositoryWatcher::NewL(KCRUidAknFep, 
       
   105         TCallBack(HandleFindRepositoryCallBack, this), 
       
   106         iRepositoryFind);
       
   107 
       
   108     // The below code is commented out because current CFindUtilChineseECE is used
       
   109     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   110     // for the further merging work (merge from FindUtil 5.0)
       
   111 #if 0
       
   112     iWatcherAdaptive = CFindRepositoryWatcher::NewL(KCRUidAvkon,
       
   113         TCallBack(HandleFindRepositoryCallBack, this),
       
   114         iRepositoryFindAdaptive);                                        
       
   115 #endif
       
   116     iAlgorithm = aAlgorithm;
       
   117     OpenL();
       
   118 
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CFindUtilChineseECE utils class
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 CFindUtilChineseECE::CFindUtilChineseECE() :
       
   126 iLanguage(ELangTest),
       
   127 iSupportPRCChinese(EFalse),
       
   128 iCurInputMode(KSysInputMode)
       
   129 // The below code is commented out because current CFindUtilChineseECE is used
       
   130 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   131 // for the further merging work (merge from FindUtil 5.0)
       
   132 #if 0
       
   133 iSearchMethodPRC(EAdptSearchPinyin),
       
   134 iSearchMethodTaiWan(EAdptSearchZhuyin),
       
   135 iSearchMethodHongKong(EAdptSearchStroke),
       
   136 iSearchMethodAdaptive(EFalse)
       
   137 #endif
       
   138     	    {
       
   139     	    }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // Destructor
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 CFindUtilChineseECE::~CFindUtilChineseECE()
       
   146     {
       
   147     delete iPtiEngine;
       
   148     delete iWatcher;
       
   149     delete iPtiEnginePrc;
       
   150     delete iRepositoryFind;
       
   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     delete iWatcherAdaptive;
       
   156     delete iRepositoryFindAdaptive;
       
   157 #endif
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // Open ptiengine and active it by input language
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 TBool CFindUtilChineseECE::OpenT9InterfaceL(TLanguage aLanguage)
       
   165     {
       
   166     if (!iPtiEngine)
       
   167         {
       
   168         iPtiEngine = CPtiEngine::NewL();
       
   169         iSupportPRCChinese = IsSupportLanguage(ELangPrcChinese);
       
   170         }
       
   171 
       
   172     if (aLanguage != iLanguage)
       
   173         {
       
   174         iLanguage = aLanguage;
       
   175         iPtiEngine->ActivateLanguageL(iLanguage);
       
   176         iPtiEngine->EnableToneMarks(EFalse);
       
   177         }
       
   178 
       
   179     return ETrue;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------
       
   183 // Close ptiengine
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 void CFindUtilChineseECE::CloseT9InterfaceL()
       
   187     {
       
   188     iLanguage = ELangTest;
       
   189     iPtiEngine->CloseCurrentLanguageL();
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------
       
   193 // Translate Chinese word to its spelling
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 TBool CFindUtilChineseECE::DoTranslationL(TInt16 aHZUnicode, RPointerArray<HBufC>& aSpellList)
       
   197     {
       
   198     // The below code is commented out because current CFindUtilChineseECE is used
       
   199     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   200     // for the further merging work (merge from FindUtil 5.0)
       
   201 #if 0
       
   202     if(CEikonEnv::Static())
       
   203         {
       
   204         if (iSearchMethodAdaptive &&(CEikonEnv::Static()->EikAppUi()->Application()->AppDllUid() == KUidPhoneBook ||
       
   205             CEikonEnv::Static()->EikAppUi()->Application()->AppDllUid() == KUidPhoneBookServer ))
       
   206             {
       
   207             if (!T9ChineseTranslationAdaptiveL(aHZUnicode, aSpellList))
       
   208                 {
       
   209                 return EFalse;
       
   210                 }    
       
   211             }
       
   212         else
       
   213             {
       
   214 #endif
       
   215             if (!T9ChineseTranslationL(aHZUnicode, aSpellList))
       
   216                 {
       
   217                 return EFalse;
       
   218                 }
       
   219             // The below code is commented out because current CFindUtilChineseECE is used
       
   220             // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   221             // for the further merging work (merge from FindUtil 5.0)
       
   222 #if 0          
       
   223             }
       
   224         }
       
   225     else
       
   226         {
       
   227         if (iSearchMethodAdaptive)
       
   228             {
       
   229             if (!T9ChineseTranslationAdaptiveL(aHZUnicode, aSpellList))
       
   230                 {
       
   231                 return EFalse;
       
   232                 }
       
   233             }
       
   234         else
       
   235             {
       
   236             if (!T9ChineseTranslationL(aHZUnicode, aSpellList))
       
   237                 {
       
   238                 return EFalse;
       
   239                 }
       
   240             }
       
   241         }
       
   242 #endif
       
   243     return ETrue;
       
   244 
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // Find pane text is including stroke symbol
       
   249 // ---------------------------------------------------------
       
   250 //
       
   251 TInt CFindUtilChineseECE::IsStrokeSymbol(const TInt aFindWord)
       
   252     {
       
   253     TInt strokeValue = 0;
       
   254 
       
   255     switch (aFindWord)
       
   256         {
       
   257         case KStrokeHorizontalValue:
       
   258             strokeValue = 1;
       
   259             break;
       
   260         case KStrokeVerticalValue:
       
   261             strokeValue = 2;
       
   262             break;
       
   263         case KStrokeDownToLeftValue:
       
   264             strokeValue = 3;
       
   265             break;
       
   266         case KStrokeDownToRightValue:
       
   267             strokeValue = 4;
       
   268             break;
       
   269         case KStrokeBendingValue:
       
   270             strokeValue = 5;
       
   271             break;
       
   272         default:
       
   273             return strokeValue;
       
   274         }// switch
       
   275 
       
   276     return strokeValue;
       
   277     }
       
   278 
       
   279 TInt CFindUtilChineseECE::CategoryOfLang(TLanguage aLanguage)
       
   280     {
       
   281     TInt ret = 0;
       
   282     if (iLanguage == ELangPrcChinese || ( aLanguage == ELangEnglish && iSupportPRCChinese ))
       
   283         {
       
   284         ret = 1;
       
   285         }
       
   286     else if (aLanguage == ELangTaiwanChinese)
       
   287         {
       
   288         ret = 2;
       
   289         }
       
   290     else if (aLanguage == ELangHongKongChinese)
       
   291         {
       
   292         ret = 3;
       
   293         }
       
   294     return ret;
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------
       
   298 // Do translate for Chinese word
       
   299 // ---------------------------------------------------------
       
   300 //
       
   301 TBool CFindUtilChineseECE::T9ChineseTranslationL(TInt16 aHZUnicode, RPointerArray<HBufC>& aSpellList)
       
   302     {
       
   303     TBuf<KMaxWordInterpretationLen> wordInterpretationBuf;
       
   304     TBuf<KMaxWordInterpretationLen> numInterpretationBuf;
       
   305 
       
   306     if (iLanguage == ELangPrcChinese)
       
   307         {
       
   308         if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) != KErrNone)
       
   309             {
       
   310             return EFalse;
       
   311             }
       
   312         }
       
   313     else if (iLanguage == ELangTaiwanChinese)
       
   314         {
       
   315         if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiZhuyin) != KErrNone)
       
   316             {
       
   317             return EFalse;
       
   318             }
       
   319         }
       
   320     else if (iLanguage == ELangHongKongChinese)
       
   321         {
       
   322         if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) != KErrNone)
       
   323             {
       
   324             return EFalse;
       
   325             }
       
   326         }
       
   327     else if (iLanguage == ELangEnglish)
       
   328         {
       
   329         if (!iSupportPRCChinese)
       
   330             {
       
   331             return EFalse;
       
   332             }
       
   333 
       
   334         TInt err = KErrNone;
       
   335         if (!iPtiEnginePrc)
       
   336             {
       
   337             iPtiEnginePrc = CPtiEngine::NewL(EFalse);
       
   338             TRAP(err, iPtiEnginePrc->ActivateLanguageL(ELangPrcChinese));
       
   339             }
       
   340 
       
   341         if (err == KErrNone)
       
   342             {
       
   343             if (iPtiEnginePrc->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) != KErrNone)
       
   344                 {
       
   345                 return EFalse;
       
   346                 }
       
   347             }
       
   348         }
       
   349     else
       
   350         {
       
   351         return EFalse;
       
   352         }
       
   353 
       
   354     const TInt len = wordInterpretationBuf.Length();
       
   355     TInt start = 0;
       
   356 
       
   357     for (TInt i = 0; i < len; i++)
       
   358         {
       
   359         if (wordInterpretationBuf[i] == KSeperator)
       
   360             {
       
   361             aSpellList.Append((wordInterpretationBuf.MidTPtr(start, i - start)).Alloc());
       
   362             start = i + 1;
       
   363             }
       
   364         }
       
   365 
       
   366     aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len - start)).Alloc());
       
   367 
       
   368     return ETrue;
       
   369     }
       
   370 
       
   371 // The below code is commented out because current CFindUtilChineseECE is used
       
   372 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   373 // for the further merging work (merge from FindUtil 5.0)
       
   374 #if 0    
       
   375 // ---------------------------------------------------------
       
   376 // Do translate for Chinese word
       
   377 // ---------------------------------------------------------
       
   378 //
       
   379 TBool CFindUtilChineseECE::T9ChineseTranslationAdaptiveL(TInt16 aHZUnicode,  
       
   380     RPointerArray<HBufC>& aSpellList)
       
   381     {
       
   382     TBuf<KMaxWordInterpretationLen> wordInterpretationBuf;
       
   383 
       
   384     if ( iLanguage == ELangPrcChinese )
       
   385         {
       
   386         if(iSearchMethodPRC == EAdptSearchPinyin)
       
   387             {
       
   388             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) 
       
   389                 != KErrNone)
       
   390                 {
       
   391                 return EFalse;
       
   392                 }	
       
   393             }
       
   394         else if(iSearchMethodPRC == EAdptSearchStroke)    
       
   395             {
       
   396             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) 
       
   397                 != KErrNone)
       
   398                 {
       
   399                 return EFalse;
       
   400                 }	
       
   401             }
       
   402         else
       
   403             {
       
   404             return EFalse;	
       
   405             }    
       
   406 
       
   407         }
       
   408     else if ( iLanguage == ELangTaiwanChinese )
       
   409         {
       
   410         if(iSearchMethodTaiWan == EAdptSearchZhuyin)
       
   411             {
       
   412             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiZhuyin) 
       
   413                 != KErrNone)
       
   414                 {
       
   415                 return EFalse;
       
   416                 }	
       
   417             }
       
   418         else if(iSearchMethodTaiWan == EAdptSearchStroke)    
       
   419             {
       
   420             if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) 
       
   421                 != KErrNone)
       
   422                 {
       
   423                 return EFalse;
       
   424                 }	
       
   425             }
       
   426         else
       
   427             {
       
   428             return EFalse;	
       
   429             }       
       
   430         }
       
   431     else if ( iLanguage == ELangHongKongChinese )
       
   432         {
       
   433         switch(iSearchMethodHongKong)
       
   434             {
       
   435             case EAdptSearchNormalCangjie:
       
   436                 if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie) 
       
   437                     != KErrNone)
       
   438                     {
       
   439                     return EFalse;
       
   440                     }
       
   441                 break;
       
   442             case EAdptSearchEasyCangjie:
       
   443                 if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie) 
       
   444                     != KErrNone)
       
   445                     {
       
   446                     return EFalse;
       
   447                     }
       
   448                 break;
       
   449             case EAdptSearchAdvCangjie:
       
   450                 if ((iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie) != KErrNone)
       
   451                     &&(iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie) != KErrNone))
       
   452                     {
       
   453                     return EFalse;
       
   454                     }
       
   455                 break;
       
   456             case EAdptSearchStroke:
       
   457                 if (iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiStrokes) 
       
   458                     != KErrNone)
       
   459                     {
       
   460                     return EFalse;
       
   461                     }
       
   462                 break;
       
   463             default:
       
   464                 return EFalse;        	
       
   465             }
       
   466 
       
   467         }
       
   468     else if ( iLanguage == ELangEnglish )
       
   469         {
       
   470         if (!iSupportPRCChinese)
       
   471             {
       
   472             return EFalse;
       
   473             }
       
   474 
       
   475         TInt err = KErrNone;
       
   476         if (!iPtiEnginePrc)
       
   477             {
       
   478             iPtiEnginePrc = CPtiEngine::NewL(EFalse);
       
   479             TRAP(err, iPtiEnginePrc->ActivateLanguageL(ELangPrcChinese));
       
   480             }   
       
   481 
       
   482         if (err == KErrNone)
       
   483             {
       
   484             if (iPtiEnginePrc->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiPinyin) 
       
   485                 != KErrNone) 
       
   486 
       
   487                 return EFalse;
       
   488             }
       
   489         }
       
   490     else
       
   491         {
       
   492         return EFalse;
       
   493         }
       
   494 
       
   495     TInt len = wordInterpretationBuf.Length();
       
   496     TInt start = 0;
       
   497 
       
   498     if( iSearchMethodHongKong != EAdptSearchAdvCangjie )
       
   499         {
       
   500         for (TInt i =0; i < len; i++)
       
   501             {
       
   502             if (wordInterpretationBuf[i] == KSeperator) 
       
   503                 {
       
   504                 aSpellList.Append((wordInterpretationBuf.MidTPtr(start, i-start)).Alloc());
       
   505                 start = i + 1;
       
   506                 }
       
   507             }
       
   508 
       
   509         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc());   	
       
   510         }
       
   511     //Could look advanced cangjie as normal and easy cangjie
       
   512     else 
       
   513         {
       
   514         iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiEasyCangjie);
       
   515         len = wordInterpretationBuf.Length();
       
   516         start = 0;
       
   517         for (TInt i =0; i < len; i++)
       
   518             {
       
   519             if (wordInterpretationBuf[i] == KSeperator) 
       
   520                 {
       
   521                 aSpellList.Append((wordInterpretationBuf.MidTPtr(start, i-start)).Alloc());
       
   522                 start = i + 1;
       
   523                 }
       
   524             }
       
   525 
       
   526         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc()); 
       
   527 
       
   528 
       
   529         iPtiEngine->GetSpelling(aHZUnicode, wordInterpretationBuf, EPtiCangJie);
       
   530         len = wordInterpretationBuf.Length();
       
   531         start = 0;
       
   532         for (TInt i =0; i < len; i++)
       
   533             {
       
   534             if (wordInterpretationBuf[i] == KSeperator) 
       
   535                 {
       
   536                 aSpellList.Append((wordInterpretationBuf.MidTPtr(start, i-start)).Alloc());
       
   537                 start = i + 1;
       
   538                 }
       
   539             }
       
   540 
       
   541         aSpellList.Append((wordInterpretationBuf.MidTPtr(start, len-start)).Alloc());  
       
   542         }
       
   543 
       
   544     return ETrue;
       
   545     } 
       
   546 #endif
       
   547 
       
   548 // ---------------------------------------------------------
       
   549 // Find pane text is including separator
       
   550 // ---------------------------------------------------------
       
   551 //
       
   552 TBool CFindUtilChineseECE::IsFindWordSeparator(TChar aCh)
       
   553     {
       
   554     return aCh ==' '|| aCh=='-'|| aCh =='\t' || aCh == '_'|| aCh == KLitLineFeed;
       
   555     }
       
   556 
       
   557 // ---------------------------------------------------------
       
   558 // Create ptiengine and initialize member data 
       
   559 // ---------------------------------------------------------
       
   560 //
       
   561 void CFindUtilChineseECE::OpenL()
       
   562     {
       
   563     TInt inputLanguage = 0;
       
   564     //TInt searchMode =0;
       
   565 
       
   566     if (iRepositoryFind != NULL)
       
   567         {
       
   568         iRepositoryFind->Get(KAknFepInputTxtLang, inputLanguage);
       
   569         }
       
   570 
       
   571     OpenT9InterfaceL((TLanguage) inputLanguage);
       
   572 
       
   573     // The below code is commented out because current CFindUtilChineseECE is used
       
   574     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
   575     // for the further merging work (merge from FindUtil 5.0)
       
   576 #if 0
       
   577     if (iRepositoryFindAdaptive != NULL)
       
   578         {
       
   579         iRepositoryFindAdaptive->Get(KAknAvkonAdaptiveSearchEnabled, iSearchMethodAdaptive);
       
   580         }
       
   581     if( inputLanguage == ELangPrcChinese)
       
   582         {
       
   583         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChinesePRC , searchMode);	
       
   584         if(searchMode ==0)
       
   585             {
       
   586             iSearchMethodPRC = EAdptSearchPinyin;	
       
   587             }
       
   588         else if(searchMode ==1)
       
   589             {
       
   590             iSearchMethodPRC = EAdptSearchStroke;	
       
   591             }
       
   592         }
       
   593     else if(inputLanguage == ELangTaiwanChinese)
       
   594         {
       
   595         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseTW , searchMode);
       
   596         if(searchMode ==0)
       
   597             {
       
   598             iSearchMethodTaiWan = EAdptSearchZhuyin;	
       
   599             }
       
   600         else if(searchMode ==1)
       
   601             {
       
   602             iSearchMethodTaiWan = EAdptSearchStroke;	
       
   603             }	
       
   604         }
       
   605     else if(inputLanguage == ELangHongKongChinese)
       
   606         {
       
   607         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseHongkong  , searchMode);
       
   608         if(searchMode ==1)
       
   609             {	    
       
   610             iRepositoryFind->Get(KAknFepCangJieMode , searchMode);
       
   611 
       
   612             switch (searchMode)
       
   613                 {
       
   614                 case 0:
       
   615                     iSearchMethodHongKong = EAdptSearchNormalCangjie;
       
   616                     break;
       
   617                 case 1:
       
   618                     iSearchMethodHongKong = EAdptSearchEasyCangjie;
       
   619                     break;
       
   620                 case 2:
       
   621                     iSearchMethodHongKong = EAdptSearchAdvCangjie;
       
   622                     break;
       
   623                 }
       
   624 
       
   625             }
       
   626         else if(searchMode ==0)
       
   627             {
       
   628             iSearchMethodHongKong = EAdptSearchStroke;	
       
   629             }
       
   630 
       
   631         }
       
   632 #endif
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------
       
   636 // Close ptiEngine 
       
   637 // ---------------------------------------------------------
       
   638 //
       
   639 void CFindUtilChineseECE::Close()
       
   640     {
       
   641     TRAP_IGNORE(CloseT9InterfaceL());    
       
   642     }
       
   643 
       
   644 // ---------------------------------------------------------
       
   645 // Match arithmetic for general search
       
   646 // ---------------------------------------------------------
       
   647 //
       
   648 TBool CFindUtilChineseECE::Match(const TDesC& aContactsField, const TDesC& aWord)
       
   649     {
       
   650     // Check function parameter
       
   651     if (aWord.Length() == 0)
       
   652         {
       
   653         return ETrue;
       
   654         }
       
   655 
       
   656     if (aContactsField.Length() == 0)
       
   657         {
       
   658         return EFalse;
       
   659         }
       
   660 
       
   661     TBool ret = EFalse;
       
   662     // Check Chinese word in find pane
       
   663     TBool chineseWord = IsChineseWord(aWord);
       
   664 
       
   665     if (chineseWord)
       
   666         {
       
   667         ret = IncludeString(aContactsField, aWord);
       
   668 
       
   669         if (ret)
       
   670             {
       
   671             // Included return ETrue
       
   672             return ret;
       
   673             }
       
   674         /*     else// If it do not find, check the symbol
       
   675             {
       
   676             // if Stroke Symbol in HongKong
       
   677             TBool strokeSymHK = (IsStrokeSymbolInString(aWord)) && 
       
   678                                (iLanguage == ELangHongKongChinese);
       
   679 
       
   680             // it is not include stroke symbol
       
   681             if (!strokeSymHK)
       
   682                 {
       
   683                 return ret;
       
   684                 }
       
   685             }*/
       
   686         }
       
   687 
       
   688     // Array for item string
       
   689     RPointerArray<STRINGINFO> stringInfoArr;
       
   690     // Split item string
       
   691     TRAPD(err, SplitItemStringL(stringInfoArr, aContactsField));
       
   692     if (err != KErrNone)
       
   693         {
       
   694         stringInfoArr.ResetAndDestroy();
       
   695         stringInfoArr.Close();
       
   696         return ret;
       
   697         }
       
   698 
       
   699     TInt index = 0;
       
   700     STRINGINFO* pStringInfo;
       
   701     const TInt arrayCount = stringInfoArr.Count();
       
   702 
       
   703     if (!chineseWord)
       
   704         {
       
   705         // Search English word
       
   706         for (index = 0; index < arrayCount; index++)
       
   707             {
       
   708             pStringInfo = stringInfoArr[index];
       
   709             if (!pStringInfo->isChinese &&
       
   710                 pStringInfo->segmentString.MatchC(aWord) != KErrNotFound)
       
   711                 {
       
   712                 ret = ETrue;
       
   713                 break;
       
   714                 }
       
   715             }
       
   716         }
       
   717 
       
   718     if (!ret)// If not find, search Chinese word 
       
   719         {
       
   720         TRAP(err, ret = MatchChineseInitialStringL(stringInfoArr, aWord));
       
   721         }
       
   722 
       
   723     stringInfoArr.ResetAndDestroy();
       
   724     stringInfoArr.Close();
       
   725 
       
   726     return ret;
       
   727     }
       
   728 
       
   729 // ---------------------------------------------------------
       
   730 // Initial character search 
       
   731 // ---------------------------------------------------------
       
   732 //
       
   733 TBool CFindUtilChineseECE::MatchChineseInitialStringL(RPointerArray<STRINGINFO>& aStringInfoArr, 
       
   734     const TDesC& aSearchStr)
       
   735     {
       
   736     TInt spellCount = 0;
       
   737     TInt i = 0;
       
   738     TInt chineseWordCount;
       
   739     TInt chineseWordIndex;
       
   740     STRINGINFO* pStringInfo;
       
   741     TBool ret = EFalse;
       
   742     const TInt arrayCount = aStringInfoArr.Count();
       
   743 
       
   744     for (TInt index = 0; index < arrayCount; index++)
       
   745         {
       
   746         pStringInfo = aStringInfoArr[index];
       
   747         // English word, continue
       
   748         if (!pStringInfo->isChinese)
       
   749             {
       
   750             continue;
       
   751             }
       
   752 
       
   753         chineseWordCount = pStringInfo->segmentString.Length();
       
   754 
       
   755         for (chineseWordIndex = 0; chineseWordIndex < chineseWordCount; chineseWordIndex++)
       
   756             {
       
   757             RPointerArray<HBufC> spellList;
       
   758 
       
   759             if (!DoTranslationL(TInt16(pStringInfo->segmentString[chineseWordIndex]), spellList))
       
   760                 {
       
   761                 spellList.ResetAndDestroy();//destroy spellList
       
   762                 spellList.Close();
       
   763                 continue;
       
   764                 }
       
   765 
       
   766             spellCount = spellList.Count();
       
   767             // Search all spelling
       
   768             for (i = 0; i < spellCount; i++)
       
   769                 {
       
   770                 if (spellList[i]->MatchC(aSearchStr) != KErrNotFound)
       
   771                     {
       
   772                     // If find, break
       
   773                     ret = ETrue;
       
   774                     break;
       
   775                     }
       
   776                 }//end for
       
   777 
       
   778             spellList.ResetAndDestroy();//destroy spellList
       
   779             spellList.Close();
       
   780 
       
   781             if (ret)
       
   782                 {
       
   783                 // If find, return
       
   784                 return ret;
       
   785                 }
       
   786             }
       
   787         }
       
   788 
       
   789     return ret;
       
   790     }
       
   791 
       
   792 // ---------------------------------------------------------
       
   793 // Remove separator from search text
       
   794 // ---------------------------------------------------------
       
   795 //
       
   796 void CFindUtilChineseECE::RemoveSeparator(TDes& aSearchText)
       
   797     {
       
   798     TInt index = -1;
       
   799     TBuf<1> temp;
       
   800 
       
   801     temp.Copy(KUnderLine);
       
   802     while ((index = aSearchText.FindC(temp)) > 0)
       
   803         {
       
   804         aSearchText.Replace(index, 1, KNullDesC);
       
   805         }
       
   806 
       
   807     temp.Copy(KMiddleLine);
       
   808     while ((index = aSearchText.FindC(temp)) > 0)
       
   809         {
       
   810         aSearchText.Replace(index, 1, KNullDesC);
       
   811         }
       
   812 
       
   813     temp.Copy(KBlank);
       
   814     while ((index = aSearchText.FindC(temp)) > 0)
       
   815         {
       
   816         aSearchText.Replace(index, 1, KNullDesC);
       
   817         }
       
   818 
       
   819     temp.Copy(KTab);
       
   820     while ((index = aSearchText.FindC(temp)) > 0)
       
   821         {
       
   822         aSearchText.Replace(index, 1, KNullDesC);
       
   823         }
       
   824     }
       
   825 
       
   826 // ---------------------------------------------------------
       
   827 // Match arithmetic for accurate search 
       
   828 // ---------------------------------------------------------
       
   829 //
       
   830 TBool CFindUtilChineseECE::MatchRefineL(const TDesC& aItemString, CPsQuery& aPsQuery)
       
   831     {
       
   832     TBuf<KMaxWordLength> tempBuf;
       
   833     TBuf<KMaxWordLength> itemString;
       
   834 
       
   835     itemString.Zero();
       
   836     if ( KMaxWordLength > aItemString.Length() )
       
   837         {
       
   838         itemString.Copy( aItemString );
       
   839         }
       
   840     else
       
   841         {
       
   842         itemString.Copy( aItemString.Left( KMaxWordLength ) );
       
   843         }
       
   844     
       
   845     //trim the special char
       
   846     if(itemString.Length()>0)
       
   847         {
       
   848         if(itemString[0]== KLeftToRightFlag || itemString[0]== KRightToLeftFlag)
       
   849             {
       
   850             itemString.Delete(0,1);
       
   851             itemString.Delete((itemString.Length()-1),1);    
       
   852             }
       
   853         }
       
   854 
       
   855     TBool haschineseword = EFalse; 
       
   856 
       
   857     // Check function parameter
       
   858     if (aPsQuery.Count() == 0)
       
   859         {
       
   860         return ETrue;
       
   861         }
       
   862 
       
   863     if (aItemString.Length() == 0)
       
   864         {
       
   865         return EFalse;
       
   866         }
       
   867 
       
   868     TBool ret = EFalse;
       
   869 
       
   870     CPsQuery* query = CPsQuery::NewL();
       
   871     GetPartOfQueryL(aPsQuery, 0, aPsQuery.Count()-1, *query);
       
   872     RemoveSeparatorL(*query);
       
   873     TPtrC queryStrPtr = query->QueryAsStringLC();
       
   874 
       
   875     tempBuf.Zero();
       
   876     tempBuf.Copy(queryStrPtr);
       
   877 
       
   878     CleanupStack::PopAndDestroy(); // queryStrPtr
       
   879 
       
   880     if (iLanguage == ELangHongKongChinese)
       
   881         {
       
   882         UpdateCurrentInputMode();
       
   883         if (iCurInputMode == KSysInputMode)
       
   884             {
       
   885             iCurInputMode = 0x0020;
       
   886             }
       
   887 
       
   888         }
       
   889     else
       
   890         {
       
   891         iCurInputMode = KSysInputMode;
       
   892         }
       
   893 
       
   894     // Check Chinese word in find pane
       
   895     if (IsChineseWord(tempBuf))
       
   896         {
       
   897         haschineseword = ETrue;
       
   898         ret = IncludeString(aItemString, tempBuf);
       
   899 
       
   900         if (ret)
       
   901             {
       
   902             return ret;
       
   903             }
       
   904         /*    else
       
   905             {
       
   906             // if Stroke Symbol in HongKong
       
   907             TBool strokeSymHK = (IsStrokeSymbolInString(tempBuf)) && 
       
   908                                  (iLanguage == ELangHongKongChinese) &&
       
   909                                  iCurInputMode == 0x0020;
       
   910 
       
   911             if (!strokeSymHK)
       
   912                 {
       
   913                 return ret;
       
   914                 }
       
   915             }*/
       
   916         }
       
   917 
       
   918     //Find if search string has chinese word. 
       
   919     //Compare with item string if find chinese word in item string then delete it from search and item string.
       
   920     //if not then return EFalse.
       
   921     TBool InputMethodStroke = EFalse;
       
   922     if(iLanguage == ELangHongKongChinese && iCurInputMode == 0x0020)
       
   923         {
       
   924         InputMethodStroke = ETrue;
       
   925         }
       
   926     
       
   927     if (haschineseword)
       
   928         {
       
   929         TInt ii=0;
       
   930         TBool leftDifferentChinese = EFalse; //Fixed for ESSG-7PJ6GF, flag the different Chinese character at the left of aSearchText.
       
   931         while (ii< tempBuf.Length())
       
   932             {
       
   933             if ((TInt)tempBuf[ii]>= KMinUnicodeHz && (!InputMethodStroke
       
   934                     ||(InputMethodStroke && !IsStrokeSymbol(tempBuf[ii]))))
       
   935                 {
       
   936                 TInt Findcursor = itemString.Locate(tempBuf[ii]);
       
   937                 if (Findcursor != KErrNotFound)
       
   938                     {
       
   939                     if ((Findcursor == itemString.Length()-1)&& (ii
       
   940                             ==tempBuf.Length()-1))
       
   941                         {
       
   942                         //Start:Fixed for ESSG-7PJ6GF
       
   943                         if ( leftDifferentChinese || IsChineseWord(
       
   944                             itemString.Left( Findcursor ) ) )
       
   945                             {
       
   946                             //if the different Chinese character at the left or middle, return false.
       
   947                             return EFalse;
       
   948                             }
       
   949                         //End:Fixed for ESSG-7PJ6GF
       
   950                         return ETrue;
       
   951                         }
       
   952                     itemString.Delete(0, Findcursor+1);
       
   953                     tempBuf.Delete(0, ii+1);
       
   954                     ii=0;
       
   955                     }
       
   956                 else
       
   957                     {
       
   958                     //Start:Fixed for ESSG-7PJ6GF
       
   959                     if ( IsChineseWord( tempBuf.Left( ii + 1 ) ) )
       
   960                         {
       
   961                         //flag the different Chinese character at the left.
       
   962                         leftDifferentChinese = ETrue;
       
   963                         }
       
   964                     //End:Fixed for ESSG-7PJ6GF
       
   965                     ii++;
       
   966                     }
       
   967                 }
       
   968             else
       
   969                 {
       
   970                 ii++;
       
   971                 }
       
   972             }
       
   973 
       
   974         }
       
   975 
       
   976     // Array for item string
       
   977     RPointerArray<STRINGINFO> stringInfoArr;
       
   978     // Split item string
       
   979     SplitItemStringL(stringInfoArr, itemString);
       
   980 
       
   981     if (stringInfoArr.Count() > 0)
       
   982         {
       
   983         ret = MatchSegmentL(stringInfoArr, *query);
       
   984         }
       
   985 
       
   986     stringInfoArr.ResetAndDestroy();
       
   987     stringInfoArr.Close();
       
   988 
       
   989     delete query;
       
   990 
       
   991     return ret;
       
   992     }
       
   993 
       
   994 // ---------------------------------------------------------
       
   995 // Splite the input text to sgement by language
       
   996 // ---------------------------------------------------------
       
   997 //
       
   998 void CFindUtilChineseECE::SplitItemStringL(RPointerArray<STRINGINFO>& aStringInfoArr, 
       
   999     const TDesC &aItemString)
       
  1000     {
       
  1001     TBuf<KMaxWordLength> tempBuf;
       
  1002     TBuf<KMaxWordLength> englishBuf;
       
  1003     TBuf<KMaxWordLength> chineseBuf;
       
  1004 
       
  1005     tempBuf.Zero();
       
  1006     englishBuf.Zero();
       
  1007     chineseBuf.Zero();
       
  1008 
       
  1009     TInt index = 0;
       
  1010     TUint32 temp = 0;
       
  1011     TInt32 distance = 0;
       
  1012     const TInt strLength = aItemString.Length();
       
  1013 
       
  1014     for (; index < strLength; index++)
       
  1015         {
       
  1016         if (IsFindWordSeparator(aItemString[index]))
       
  1017             {
       
  1018             // Check Chinese and English Buf. If it is not empty, 
       
  1019             // add buf to Array
       
  1020             InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue);
       
  1021             InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse);
       
  1022             continue;
       
  1023             }
       
  1024 
       
  1025         temp = aItemString[index];
       
  1026         distance = (TInt32)(temp - KMinUnicodeHz);
       
  1027 
       
  1028         if (distance < 0)// English word
       
  1029             {
       
  1030             // Chinese word is end and add to array
       
  1031             InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue);
       
  1032 
       
  1033             // Add English word to array
       
  1034             englishBuf.Append((TChar) aItemString[index]);
       
  1035             }
       
  1036         else // Chinese word
       
  1037             {
       
  1038             // English word is end and add to array
       
  1039             InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse);
       
  1040 
       
  1041             // Add Chinese word to array
       
  1042             chineseBuf.Append((TChar) aItemString[index]);
       
  1043             }
       
  1044         }
       
  1045 
       
  1046     // Finish loop check buffer is empty
       
  1047     InsertStrInforArrayL(aStringInfoArr, chineseBuf, ETrue);
       
  1048     InsertStrInforArrayL(aStringInfoArr, englishBuf, EFalse);
       
  1049     }
       
  1050 
       
  1051 // ---------------------------------------------------------
       
  1052 // Insert segment to list
       
  1053 // ---------------------------------------------------------
       
  1054 //
       
  1055 void CFindUtilChineseECE::InsertStrInforArrayL(RPointerArray<STRINGINFO>& aStringInfoArr, 
       
  1056     TDes &aSegmentStr, const TBool aChinese)
       
  1057     {
       
  1058     if (aSegmentStr.Length() <= 0)
       
  1059         {
       
  1060         return;
       
  1061         }
       
  1062 
       
  1063     STRINGINFO* strInfo = new (ELeave) STRINGINFO;
       
  1064 
       
  1065     strInfo->segmentString.Zero();
       
  1066     strInfo->segmentString.Copy(aSegmentStr);
       
  1067     strInfo->segmentString.LowerCase();
       
  1068     strInfo->isChinese = aChinese;
       
  1069 
       
  1070     aStringInfoArr.AppendL(strInfo);
       
  1071     aSegmentStr.Zero();
       
  1072     }
       
  1073 
       
  1074 // ---------------------------------------------------------
       
  1075 // This segment is matched by search text
       
  1076 // ---------------------------------------------------------
       
  1077 //
       
  1078 TBool CFindUtilChineseECE::MatchSegmentL(RPointerArray<STRINGINFO>& aStringInfoArr, 
       
  1079     CPsQuery& aQuery)
       
  1080     {
       
  1081     const TInt arrayLength = aStringInfoArr.Count();
       
  1082     const TInt searchStrLength = aQuery.Count();
       
  1083     TInt searchStrIndex = 0;
       
  1084     STRINGINFO* pStringInfo;
       
  1085     TInt index = 0;
       
  1086 
       
  1087     // First only check English
       
  1088     for (; index < arrayLength; index++)
       
  1089         {
       
  1090         // Create an empty CPsQuery
       
  1091         CPsQuery* tempQuery = CPsQuery::NewL();
       
  1092         pStringInfo = aStringInfoArr[index];
       
  1093 
       
  1094         GetPartOfQueryL( aQuery, searchStrIndex, searchStrLength - 1,
       
  1095             *tempQuery );
       
  1096 
       
  1097         // Compare word
       
  1098         if (!pStringInfo->isChinese)
       
  1099             {
       
  1100             searchStrIndex += MatchString(pStringInfo->segmentString, *tempQuery);
       
  1101             }
       
  1102 
       
  1103         delete tempQuery;
       
  1104         tempQuery = NULL;
       
  1105 
       
  1106         if (searchStrIndex >= searchStrLength)
       
  1107             {
       
  1108             return ETrue;
       
  1109             }
       
  1110         }
       
  1111 
       
  1112     TBuf<KMaxWordLength> bufcurrent;
       
  1113     TBuf<KMaxWordLength> tempbufcurrent;
       
  1114     TInt searchStrIndextemp = 0;
       
  1115     TInt searchStrIndexMax = 0;
       
  1116     // Find Chinese and English
       
  1117     searchStrIndex = 0;
       
  1118     index = 0;
       
  1119 
       
  1120     for (; index < arrayLength; index++)
       
  1121         {
       
  1122         // Create an empty CPsQuery
       
  1123         CPsQuery* tempQuery = CPsQuery::NewL();
       
  1124         pStringInfo = aStringInfoArr[index];
       
  1125 
       
  1126         GetPartOfQueryL( aQuery, searchStrIndex, searchStrLength - 1,
       
  1127             *tempQuery );
       
  1128         searchStrIndexMax = 0;
       
  1129 
       
  1130         bufcurrent = pStringInfo->segmentString;
       
  1131 
       
  1132         for(TInt i =0;i< pStringInfo->segmentString.Length();i++)
       
  1133             {
       
  1134             tempbufcurrent = bufcurrent.Mid(i);
       
  1135             if (pStringInfo->isChinese)
       
  1136                 {
       
  1137                 TInt temp=0;
       
  1138                 searchStrIndextemp = MatchChineseStringL(tempbufcurrent, *tempQuery, temp);  
       
  1139                 if(searchStrIndextemp > searchStrIndexMax)
       
  1140                     {
       
  1141                     searchStrIndex -= searchStrIndexMax;
       
  1142                     searchStrIndexMax = searchStrIndextemp;
       
  1143                     searchStrIndex += searchStrIndexMax;
       
  1144                     }
       
  1145                 }
       
  1146             else
       
  1147                 {
       
  1148                 searchStrIndex += MatchString(pStringInfo->segmentString, *tempQuery);
       
  1149                 }
       
  1150 
       
  1151             if (searchStrIndex >= searchStrLength)
       
  1152                 {
       
  1153                 delete tempQuery;
       
  1154                 tempQuery = NULL;
       
  1155                 return ETrue;
       
  1156                 }
       
  1157             else if(!pStringInfo->isChinese)
       
  1158                 {
       
  1159                 break;
       
  1160                 }
       
  1161             }
       
  1162 
       
  1163         delete tempQuery;
       
  1164         tempQuery = NULL;
       
  1165         }
       
  1166 
       
  1167     return EFalse;
       
  1168     }
       
  1169 
       
  1170 // ---------------------------------------------------------
       
  1171 // Search Chinese word in input text 
       
  1172 // ---------------------------------------------------------
       
  1173 //
       
  1174 TInt CFindUtilChineseECE::MatchChineseStringL(const TDesC& aSearhTargetString, CPsQuery& aQuery, TInt& aIndex)
       
  1175     {
       
  1176     const TInt stringLength = aSearhTargetString.Length();
       
  1177     const TInt searchLength = aQuery.Count();
       
  1178     TInt index = 0;
       
  1179     //TBuf<KMaxWordLength> tempBuf;
       
  1180     TBuf<KMaxWordLength> previousBuf;
       
  1181     TInt curMatchCount = 0;
       
  1182     TInt preMatchCount = 0;
       
  1183     TInt matchIndex = 0;
       
  1184     TInt curSearchIndex = 0;
       
  1185     TBool bFullMatched = EFalse;
       
  1186     TBool bContinue = EFalse;
       
  1187 
       
  1188     for (; index < stringLength; index++)
       
  1189         {
       
  1190         RPointerArray<HBufC> spellList;
       
  1191 
       
  1192         if (!DoTranslationL(TInt16(aSearhTargetString[index]), spellList))
       
  1193             {
       
  1194             spellList.ResetAndDestroy();//destroy spellList
       
  1195             spellList.Close();
       
  1196 
       
  1197             continue;
       
  1198             }
       
  1199 
       
  1200         matchIndex = 0;
       
  1201         bContinue = EFalse;
       
  1202 
       
  1203         // Get left string
       
  1204         CPsQuery* tempQuery = CPsQuery::NewL();
       
  1205         GetPartOfQueryL( aQuery, curSearchIndex, searchLength - 1,
       
  1206             *tempQuery );
       
  1207 
       
  1208         // Get Matched count and the matched index in list     
       
  1209         curMatchCount = MaxMatchInList(spellList, *tempQuery, previousBuf, matchIndex, 
       
  1210             bFullMatched, preMatchCount, bContinue);
       
  1211 
       
  1212         // There is a string matched in list 
       
  1213         if (curMatchCount != 0)
       
  1214             {
       
  1215             previousBuf.Copy(spellList[matchIndex]->Des());
       
  1216 
       
  1217             if (curMatchCount == previousBuf.Length())
       
  1218                 {
       
  1219                 bFullMatched = ETrue;
       
  1220                 }
       
  1221             else
       
  1222                 {
       
  1223                 bFullMatched = EFalse;
       
  1224                 }
       
  1225 
       
  1226             // If it is repeat match, continue     
       
  1227             if (!bContinue)
       
  1228                 {
       
  1229                 curSearchIndex += curMatchCount;
       
  1230                 }
       
  1231             else
       
  1232                 {
       
  1233                 bFullMatched = EFalse;
       
  1234                 previousBuf.Zero();
       
  1235                 curMatchCount = 0;
       
  1236                 }
       
  1237             }
       
  1238         else
       
  1239             {
       
  1240             bFullMatched = EFalse;
       
  1241             previousBuf.Zero();
       
  1242             if (curSearchIndex != 0)
       
  1243                 {
       
  1244                 index--;
       
  1245                 }
       
  1246 
       
  1247             curSearchIndex = 0;
       
  1248             }
       
  1249 
       
  1250         spellList.ResetAndDestroy();//destroy spellList
       
  1251         spellList.Close();
       
  1252         preMatchCount = curMatchCount;
       
  1253 
       
  1254         delete tempQuery;
       
  1255         tempQuery = NULL;
       
  1256 
       
  1257         // Search to End and return
       
  1258         if (curSearchIndex >= searchLength)
       
  1259             {
       
  1260             break;
       
  1261             }
       
  1262         }
       
  1263 
       
  1264     aIndex = index;
       
  1265     return curSearchIndex;
       
  1266     }
       
  1267 
       
  1268 // ---------------------------------------------------------
       
  1269 // Maximal matched count in spelling list  
       
  1270 // ---------------------------------------------------------
       
  1271 //
       
  1272 TInt CFindUtilChineseECE::MaxMatchInList(RPointerArray<HBufC> &spellList, CPsQuery& aQuery,
       
  1273     TDesC& aPreviouStr, TInt& aMatchIndex, const TBool aFullMatched, 
       
  1274     const TInt aMatchedCount, TBool& aAgain)
       
  1275     {
       
  1276     const TInt itemCount = spellList.Count();
       
  1277     TInt matchCount = 0;
       
  1278     TBool selfMatch = EFalse;
       
  1279     aMatchIndex = 0;
       
  1280 
       
  1281     // If list is empty, then return
       
  1282     if (itemCount == 0)
       
  1283         {
       
  1284         return matchCount;
       
  1285         }
       
  1286 
       
  1287     TInt index = 0;
       
  1288     TInt temp = 0;
       
  1289     TBuf<KMaxWordLength> tempBuf;
       
  1290     TInt repeatCount = 0;
       
  1291     TBool loopFlag = EFalse;
       
  1292 
       
  1293     for (; index < itemCount; index++)
       
  1294         {
       
  1295         temp = 0;
       
  1296         repeatCount = 0;
       
  1297         loopFlag = EFalse;
       
  1298         tempBuf.Zero();
       
  1299         tempBuf.Copy(spellList[index]->Des());
       
  1300 
       
  1301         temp = MatchString(tempBuf, aQuery);
       
  1302         if(temp != 0)
       
  1303             {
       
  1304             selfMatch = ETrue;
       
  1305             }
       
  1306         else
       
  1307             {
       
  1308             selfMatch = EFalse;
       
  1309             }
       
  1310         // Not find and previous word is not empty
       
  1311         if (temp == 0 && aPreviouStr.Length() != 0)
       
  1312             {
       
  1313             // Previous word is fully matched
       
  1314             if (aFullMatched)
       
  1315                 {
       
  1316                 repeatCount = ReverseMatchString(aPreviouStr, tempBuf);
       
  1317                 // Find repeat and remove it, search again
       
  1318                 if (repeatCount != 0)
       
  1319                     {
       
  1320                     temp = MatchString(tempBuf.Right(tempBuf.Length() - repeatCount), aQuery);
       
  1321 
       
  1322                     if (temp == 0)
       
  1323                         {
       
  1324                         loopFlag = ETrue;
       
  1325                         temp = repeatCount;
       
  1326                         }
       
  1327                     }
       
  1328                 }
       
  1329             else
       
  1330                 {
       
  1331                 repeatCount = MatchString(aPreviouStr, tempBuf);
       
  1332 
       
  1333                 // Find repeat and remove it, search again
       
  1334                 if (repeatCount != 0)
       
  1335                     {
       
  1336                     if (aMatchedCount <= repeatCount)
       
  1337                         {
       
  1338                         temp = MatchString(tempBuf.Right(tempBuf.Length() - aMatchedCount), aQuery);
       
  1339 
       
  1340                         if (temp == 0)
       
  1341                             {
       
  1342                             loopFlag = ETrue;
       
  1343                             temp = aMatchedCount;
       
  1344                             }
       
  1345                         }
       
  1346                     }
       
  1347 
       
  1348                 if (temp == 0)
       
  1349                     {
       
  1350                     repeatCount = ReverseMatchString(aPreviouStr.Left(aMatchedCount), tempBuf);
       
  1351 
       
  1352                     if (repeatCount != 0)
       
  1353                         {
       
  1354                         temp = MatchString(tempBuf.Right(tempBuf.Length() - repeatCount), aQuery);
       
  1355 
       
  1356                         if (temp == 0)
       
  1357                             {
       
  1358                             loopFlag = ETrue;
       
  1359                             temp = repeatCount;
       
  1360                             }
       
  1361                         }
       
  1362                     }
       
  1363                 }
       
  1364             }
       
  1365 
       
  1366         // Find count is longer than before
       
  1367         // Record new data
       
  1368         if ((loopFlag == aAgain) &&
       
  1369             (temp > matchCount))
       
  1370             {
       
  1371             matchCount = temp;
       
  1372             aMatchIndex = index;
       
  1373             aAgain = loopFlag;
       
  1374             }
       
  1375 
       
  1376         if (loopFlag != aAgain &&
       
  1377             loopFlag &&
       
  1378             (temp > matchCount))
       
  1379             {
       
  1380             matchCount = temp;
       
  1381             aMatchIndex = index;
       
  1382             aAgain = loopFlag;
       
  1383             }
       
  1384 
       
  1385         if (loopFlag != aAgain &&
       
  1386             !loopFlag &&
       
  1387             temp != 0)
       
  1388             {
       
  1389             matchCount = temp;
       
  1390             aMatchIndex = index;
       
  1391             aAgain = loopFlag;
       
  1392             }
       
  1393         if(matchCount == aQuery.Count() && selfMatch)
       
  1394             {
       
  1395             break;
       
  1396             }
       
  1397         }
       
  1398     return matchCount;
       
  1399     }
       
  1400 
       
  1401 // ---------------------------------------------------------
       
  1402 // Search the taxt is include the input text  
       
  1403 // ---------------------------------------------------------
       
  1404 //
       
  1405 TBool CFindUtilChineseECE::IncludeString(const TDesC& aFirst, const TDesC& aSecond)
       
  1406     {
       
  1407     TBuf<KMaxWordLength> tempBuf;
       
  1408     tempBuf.Zero();
       
  1409 
       
  1410     if (TInt16(aSecond[0]) != KStarChar)
       
  1411         {
       
  1412         tempBuf.Append(KWildChar);
       
  1413         }
       
  1414 
       
  1415     tempBuf.Append(aSecond);
       
  1416 
       
  1417     if (TInt16(aSecond[aSecond.Length() - 1]) != KStarChar)
       
  1418         {
       
  1419         tempBuf.Append(KWildChar);
       
  1420         }
       
  1421 
       
  1422     if (aFirst.MatchC(tempBuf) != KErrNotFound)
       
  1423         {
       
  1424         return ETrue;
       
  1425         }
       
  1426 
       
  1427     return EFalse;
       
  1428     }
       
  1429 
       
  1430 // ---------------------------------------------------------
       
  1431 // Search text in other text  
       
  1432 // ---------------------------------------------------------
       
  1433 //
       
  1434 TInt CFindUtilChineseECE::MatchString(const TDesC& aFirst, const TDesC& aSecond)
       
  1435     {
       
  1436     const TInt secondStrLength = aSecond.Length();
       
  1437     const TInt firstStrLength = aFirst.Length();
       
  1438 
       
  1439     const TInt compareCount = firstStrLength > secondStrLength ? secondStrLength
       
  1440         : firstStrLength;
       
  1441     TInt index = 0;
       
  1442 
       
  1443     TBuf<KMaxWordLength> tempStr;
       
  1444     // translate search target string into numeric string before match
       
  1445     if (iAlgorithm)
       
  1446         {
       
  1447         iAlgorithm->Converter( aFirst, tempStr );
       
  1448         }
       
  1449     else
       
  1450         {
       
  1451         tempStr.Copy(aFirst);
       
  1452         }
       
  1453 
       
  1454     for (; index < compareCount; index++)
       
  1455         {
       
  1456         if (tempStr.Left(index + 1).FindC(aSecond.Left(index + 1)) == KErrNotFound)
       
  1457             {
       
  1458             break;
       
  1459             }
       
  1460         }
       
  1461     // Match count
       
  1462     return index;
       
  1463     }
       
  1464 // ---------------------------------------------------------
       
  1465 // Search CPsQuery in aSearhTargetStr
       
  1466 // ---------------------------------------------------------
       
  1467 //
       
  1468 TInt CFindUtilChineseECE::MatchString(const TDesC& aSearhTargetStr, CPsQuery& aQuery)
       
  1469     {
       
  1470     const TInt secondStrLength = aQuery.Count();
       
  1471     const TInt firstStrLength = aSearhTargetStr.Length();
       
  1472     TBuf<KMaxWordInterpretationLen> numInterpretationBuf;
       
  1473 
       
  1474     const TInt compareCount = firstStrLength > secondStrLength ? secondStrLength
       
  1475         : firstStrLength;
       
  1476     TInt index = 0;
       
  1477 
       
  1478     ConvertdDataToKeyBoardModeL(aQuery, aSearhTargetStr, numInterpretationBuf);
       
  1479 
       
  1480     TPtrC queryStr = aQuery.QueryAsStringLC();
       
  1481     for (; index < compareCount; index++)
       
  1482         {
       
  1483 
       
  1484         if (numInterpretationBuf.Left(index + 1).FindC(queryStr.Left(index + 1)) == KErrNotFound)
       
  1485             {
       
  1486             break;
       
  1487             }
       
  1488         }
       
  1489     CleanupStack::PopAndDestroy();
       
  1490 
       
  1491     // Match count
       
  1492     return index;
       
  1493     }
       
  1494 
       
  1495 // ---------------------------------------------------------
       
  1496 // Search text by reverse  
       
  1497 // ---------------------------------------------------------
       
  1498 //
       
  1499 TInt CFindUtilChineseECE::ReverseMatchString(const TDesC& aFirst, const TDesC& aSecond)
       
  1500     {
       
  1501     const TInt secondStrLength = aSecond.Length();
       
  1502     const TInt firstStrLength = aFirst.Length();
       
  1503     TInt compareCount = firstStrLength > secondStrLength ? secondStrLength : firstStrLength;
       
  1504     TInt index = 0;
       
  1505     TInt matchCount = 0;
       
  1506 
       
  1507     for (; index < compareCount; index++)
       
  1508         {
       
  1509         TBuf<KMaxWordLength> firstConvStr;
       
  1510         TBuf<KMaxWordLength> secondConvStr;
       
  1511 
       
  1512         // translate compared target string into numeric string before match
       
  1513         if ( iAlgorithm )
       
  1514             {
       
  1515             iAlgorithm->Converter( aFirst, firstConvStr );
       
  1516             iAlgorithm->Converter( aSecond, secondConvStr );
       
  1517             }
       
  1518         else
       
  1519             {
       
  1520             firstConvStr.Copy( aFirst );
       
  1521             secondConvStr.Copy( aSecond );
       
  1522             }
       
  1523 
       
  1524         if( firstConvStr.Right( index + 1 ).FindC( secondConvStr.Left( index + 1 ) ) != KErrNotFound )
       
  1525             {
       
  1526             matchCount = index + 1;
       
  1527             }
       
  1528         }
       
  1529 
       
  1530     return matchCount;
       
  1531     }
       
  1532 
       
  1533 // ---------------------------------------------------------
       
  1534 // Current input text is handled by this model  
       
  1535 // ---------------------------------------------------------
       
  1536 //
       
  1537 TBool CFindUtilChineseECE::IsWordValidForMatching(const TDesC& /*aWord*/)
       
  1538     {
       
  1539     return ETrue;
       
  1540     }
       
  1541 
       
  1542 // ---------------------------------------------------------
       
  1543 // Find pane text is including Chinese word  
       
  1544 // ---------------------------------------------------------
       
  1545 //
       
  1546 TBool CFindUtilChineseECE::IsChineseWord(const TDesC& aWord)
       
  1547     {
       
  1548     TBool IsChineseSearchStr = EFalse;
       
  1549     const TInt len = aWord.Length();
       
  1550 
       
  1551     for (TInt ii = 0; ii < len; ii++)
       
  1552         {
       
  1553         if ((TInt) aWord[ii] >= KMinUnicodeHz)
       
  1554             {
       
  1555             IsChineseSearchStr = ETrue;
       
  1556             break;
       
  1557             }
       
  1558         }
       
  1559 
       
  1560     return IsChineseSearchStr;
       
  1561     }
       
  1562 
       
  1563 // ---------------------------------------------------------
       
  1564 // Find pane text is including stroke symbol  
       
  1565 // ---------------------------------------------------------
       
  1566 //
       
  1567 TBool CFindUtilChineseECE::IsStrokeSymbolInString(const TDesC& aWord)
       
  1568     {
       
  1569     const TInt len = aWord.Length();
       
  1570 
       
  1571     for (TInt index = 0; index < len; index++)
       
  1572         {
       
  1573         if (IsStrokeSymbol(TInt(aWord[index])) != 0)
       
  1574             {
       
  1575             return ETrue;
       
  1576             }
       
  1577         }
       
  1578     return EFalse;
       
  1579     }
       
  1580 
       
  1581 // ---------------------------------------------------------
       
  1582 // Find pane text is including zhuyin symbol  
       
  1583 // ---------------------------------------------------------
       
  1584 //
       
  1585 TBool CFindUtilChineseECE::IsZhuyinSymbolInString(const TDesC& aWord)
       
  1586     {
       
  1587     const TInt len = aWord.Length();
       
  1588 
       
  1589     for (TInt index = 0; index < len; index++)
       
  1590         {
       
  1591         if ((aWord[index] >= KZhuyinstart) && 
       
  1592             (aWord[index] < KZhuyinstart + KZhuyincount))
       
  1593             {
       
  1594             return ETrue;
       
  1595             }
       
  1596         }
       
  1597 
       
  1598     return EFalse;
       
  1599     }
       
  1600 
       
  1601 // ---------------------------------------------------------
       
  1602 // This language is support by this model 
       
  1603 // ---------------------------------------------------------
       
  1604 //
       
  1605 TBool CFindUtilChineseECE::IsSupportLanguage(TLanguage aLang)
       
  1606     {
       
  1607     if (iPtiEngine->GetLanguage(aLang))
       
  1608         {
       
  1609         return ETrue;
       
  1610         }
       
  1611 
       
  1612     return EFalse;
       
  1613     }
       
  1614 
       
  1615 // ---------------------------------------------------------
       
  1616 // Callback method to notify client about language change.
       
  1617 // ---------------------------------------------------------
       
  1618 //
       
  1619 TInt CFindUtilChineseECE::HandleFindRepositoryCallBack(TAny* aPtr)
       
  1620     {
       
  1621     TInt ret = KErrNone;
       
  1622     CFindUtilChineseECE *self = static_cast<CFindUtilChineseECE*> (aPtr);
       
  1623     TInt searchMode = 0;
       
  1624 
       
  1625     if (self->iWatcher->ChangedKey() == KAknFepInputTxtLang)
       
  1626         {
       
  1627         TInt inputLanguage = 0;
       
  1628         self->iRepositoryFind->Get(KAknFepInputTxtLang, inputLanguage);
       
  1629 
       
  1630         TInt prevCategory = self->CategoryOfLang(self->iLanguage);
       
  1631         TRAP(ret, self->OpenT9InterfaceL(TLanguage(inputLanguage)));
       
  1632 
       
  1633         TInt category = self->CategoryOfLang(TLanguage(inputLanguage));
       
  1634         if (prevCategory != category && category != 0)
       
  1635             {
       
  1636             TRAP(ret, self->iAlgorithm->ReconstructCacheDataL());
       
  1637             }
       
  1638         }
       
  1639 
       
  1640     // The below code is commented out because current CFindUtilChineseECE is used
       
  1641     // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
  1642     // for the further merging work (merge from FindUtil 5.0)
       
  1643 #if 0    
       
  1644     if(self->iWatcherAdaptive->ChangedKey() == KAknAvkonAdaptiveSearchEnabled)
       
  1645         {
       
  1646         self->iRepositoryFindAdaptive->Get(KAknAvkonAdaptiveSearchEnabled, self->iSearchMethodAdaptive);
       
  1647         }
       
  1648 
       
  1649     if (self->iWatcherAdaptive->ChangedKey() == KAknAdaptiveSearchChinesePRC)
       
  1650         {
       
  1651         self->iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChinesePRC, searchMode);
       
  1652 
       
  1653         if(searchMode ==0)
       
  1654             {
       
  1655             self->iSearchMethodPRC = EAdptSearchPinyin;	
       
  1656             }
       
  1657         else if(searchMode ==1)
       
  1658             {
       
  1659             self->iSearchMethodPRC = EAdptSearchStroke;	
       
  1660             }
       
  1661         }
       
  1662 
       
  1663     if (self->iWatcherAdaptive->ChangedKey() == KAknAdaptiveSearchChineseTW )
       
  1664         {
       
  1665         self->iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseTW , searchMode);
       
  1666 
       
  1667         if(searchMode ==0)
       
  1668             {
       
  1669             self->iSearchMethodTaiWan = EAdptSearchZhuyin;	
       
  1670             }
       
  1671         else if(searchMode ==1)
       
  1672             {
       
  1673             self->iSearchMethodTaiWan = EAdptSearchStroke;	
       
  1674             }
       
  1675         }
       
  1676 
       
  1677     if (self->iWatcherAdaptive->ChangedKey() == KAknAdaptiveSearchChineseHongkong )
       
  1678         {
       
  1679         self->iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseHongkong , searchMode);
       
  1680 
       
  1681         if(searchMode ==1)
       
  1682             {
       
  1683             self->iRepositoryFind->Get(KAknFepCangJieMode , searchMode);
       
  1684 
       
  1685             switch (searchMode)
       
  1686                 {
       
  1687                 case 0:
       
  1688                     self->iSearchMethodHongKong = EAdptSearchNormalCangjie;
       
  1689                     break;
       
  1690                 case 1:
       
  1691                     self->iSearchMethodHongKong = EAdptSearchEasyCangjie;
       
  1692                     break;
       
  1693                 case 2:
       
  1694                     self->iSearchMethodHongKong = EAdptSearchAdvCangjie;
       
  1695                     break;	
       
  1696                 }
       
  1697 
       
  1698             }
       
  1699         else if(searchMode ==0)
       
  1700             {
       
  1701             self->iSearchMethodHongKong = EAdptSearchStroke;	
       
  1702             }
       
  1703         }
       
  1704 
       
  1705     if (self->iWatcher->ChangedKey() == KAknFepCangJieMode )
       
  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 #endif
       
  1724     return ret;
       
  1725     }
       
  1726 
       
  1727 // ---------------------------------------------------------
       
  1728 // Update input method in ptiengine from find pane
       
  1729 // ---------------------------------------------------------
       
  1730 //
       
  1731 void CFindUtilChineseECE::UpdateCurrentInputMode()
       
  1732     {
       
  1733     CCoeEnv* coeEnv = NULL;
       
  1734     coeEnv = CCoeEnv::Static();
       
  1735     iCurInputMode = KSysInputMode;
       
  1736     if (coeEnv)
       
  1737         {
       
  1738         CAknEdwinState* pState = NULL;
       
  1739 
       
  1740         if (coeEnv->AppUi() == NULL)
       
  1741             return;
       
  1742 
       
  1743         TCoeInputCapabilities inputCapabilities = static_cast<const CCoeAppUi*>(coeEnv->AppUi())->InputCapabilities();
       
  1744         MCoeFepAwareTextEditor* fepAvareTextEditor = inputCapabilities.FepAwareTextEditor();
       
  1745         if (fepAvareTextEditor)
       
  1746             {
       
  1747             pState = static_cast<CAknEdwinState*> (fepAvareTextEditor->Extension1()->State(KNullUid));
       
  1748             if (pState)
       
  1749                 {
       
  1750                 iCurInputMode = pState->CurrentInputMode();
       
  1751                 }
       
  1752             }
       
  1753         }
       
  1754     }
       
  1755 
       
  1756 void CFindUtilChineseECE::SetKeyboardMode(TInt aMode)
       
  1757     {
       
  1758     iKeyboardMode = aMode;
       
  1759     }
       
  1760 
       
  1761 // The below code is commented out because current CFindUtilChineseECE is used
       
  1762 // on 3.2.3 which is not supported adaptive search. It will be easy to keep these code 
       
  1763 // for the further merging work (merge from FindUtil 5.0)
       
  1764 #if 0  
       
  1765 // ---------------------------------------------------------------------------
       
  1766 // UpdateNextChar
       
  1767 // ---------------------------------------------------------------------------
       
  1768 //
       
  1769 void CFindUtilChineseECE::UpdateNextCharsL(HBufC*& aNextChars, TChar aCh)
       
  1770     {
       
  1771     if( aNextChars->Locate(aCh) == KErrNotFound )
       
  1772         {			
       
  1773         if( aNextChars->Des().Length() == aNextChars->Des().MaxLength())
       
  1774             {
       
  1775             aNextChars = aNextChars->ReAllocL( aNextChars->Des().MaxLength()+10 );
       
  1776             }		
       
  1777         aNextChars->Des().Append(aCh);								
       
  1778         }
       
  1779     }    
       
  1780 
       
  1781 // ---------------------------------------------------------------------------
       
  1782 // UpdateNextCharFromString
       
  1783 // ---------------------------------------------------------------------------
       
  1784 //
       
  1785 void CFindUtilChineseECE::UpdateNextCharsFromStringL(HBufC*& aNextChars, const TDesC& aItemString)
       
  1786     {
       
  1787 
       
  1788     // Array for item string
       
  1789     RPointerArray<STRINGINFO> stringInfoArr;
       
  1790     // Split item string
       
  1791     TRAPD(err, SplitItemStringL(stringInfoArr, aItemString));
       
  1792 
       
  1793     if (err != KErrNone)
       
  1794         {
       
  1795         stringInfoArr.ResetAndDestroy();
       
  1796         stringInfoArr.Close();
       
  1797         }
       
  1798 
       
  1799     TInt index = 0;
       
  1800     STRINGINFO* pStringInfo;
       
  1801     const TInt arrayCount = stringInfoArr.Count();
       
  1802 
       
  1803 
       
  1804     for (index = 0; index < arrayCount; index ++)
       
  1805         {
       
  1806         pStringInfo = stringInfoArr[index];
       
  1807         if (!pStringInfo->isChinese )
       
  1808             {
       
  1809             UpdateNextCharsL( aNextChars, pStringInfo->segmentString[0]);	
       
  1810             }
       
  1811         else
       
  1812             {
       
  1813             TInt chineseworkcount =  pStringInfo->segmentString.Length();
       
  1814 
       
  1815             for(TInt i =0;i<chineseworkcount;i++) 
       
  1816                 {
       
  1817                 RPointerArray<HBufC> spellList;
       
  1818                 TBuf<KMaxWordLength> tempBuf;
       
  1819                 if (!DoTranslationL(TInt16(pStringInfo->segmentString[i]), spellList))
       
  1820                     {
       
  1821                     UpdateNextCharsL( aNextChars, pStringInfo->segmentString[i]);
       
  1822                     }
       
  1823                 else
       
  1824                     {
       
  1825                     //for multiphnetic spell
       
  1826                     TInt spellCount = spellList.Count();
       
  1827                     // Search all spelling
       
  1828                     for (TInt j = 0; j < spellCount; j++)
       
  1829                         {
       
  1830                         tempBuf.Copy(spellList[j]->Des());
       
  1831                         UpdateNextCharsL( aNextChars, tempBuf[0]);                                        
       
  1832                         }//end for
       
  1833                     }
       
  1834                 spellList.ResetAndDestroy();//destroy spellList
       
  1835                 spellList.Close();       	
       
  1836                 }
       
  1837             }
       
  1838         }
       
  1839     stringInfoArr.ResetAndDestroy();
       
  1840     stringInfoArr.Close();
       
  1841 
       
  1842     }
       
  1843 
       
  1844 // ---------------------------------------------------------------------------
       
  1845 // TrimChineseCharacter
       
  1846 // ---------------------------------------------------------------------------
       
  1847 //
       
  1848 TBool CFindUtilChineseECE::TrimChineseCharacterL(TDes& aItemString, TDes& aSearchText,HBufC*& aNextChars)
       
  1849     {
       
  1850     TBuf<KMaxWordLength> tempBuf;    
       
  1851     TBuf<KMaxWordLength> itemString;
       
  1852 
       
  1853     tempBuf.Zero();
       
  1854 
       
  1855     tempBuf.Copy(aSearchText);
       
  1856 
       
  1857     itemString.Zero();
       
  1858 
       
  1859     itemString.Copy(aItemString);
       
  1860 
       
  1861     TInt searchMode;
       
  1862     TBool InputMethodStroke= EFalse;
       
  1863 
       
  1864     if ( iLanguage == ELangPrcChinese )
       
  1865         {
       
  1866         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChinesePRC, searchMode);
       
  1867         if(searchMode == 1)
       
  1868             {
       
  1869             InputMethodStroke = ETrue;
       
  1870             }
       
  1871         }
       
  1872     else if ( iLanguage == ELangHongKongChinese)
       
  1873         {
       
  1874         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseHongkong, searchMode);
       
  1875         if(searchMode == 1)
       
  1876             {
       
  1877             InputMethodStroke = ETrue;
       
  1878             }
       
  1879         }
       
  1880     else if( iLanguage == ELangTaiwanChinese)
       
  1881         {
       
  1882         iRepositoryFindAdaptive->Get(KAknAdaptiveSearchChineseTW, searchMode);
       
  1883         if(searchMode == 0)
       
  1884             {
       
  1885             InputMethodStroke = ETrue;
       
  1886             }
       
  1887         }
       
  1888     TInt ii =0;
       
  1889     while (ii< tempBuf.Length())
       
  1890         {
       
  1891         if ((TInt)tempBuf[ii]>= KMinUnicodeHz && (!InputMethodStroke
       
  1892             ||(InputMethodStroke && !IsStrokeSymbol(tempBuf[ii]))))
       
  1893             {
       
  1894             TInt Findcursor = itemString.Locate(tempBuf[ii]);
       
  1895             if (Findcursor != KErrNotFound)
       
  1896                 {
       
  1897                 if ((Findcursor == itemString.Length()-1) && (ii
       
  1898                     == tempBuf.Length()-1))
       
  1899                     {
       
  1900                     return ETrue;
       
  1901                     }
       
  1902                 itemString.Delete(0, Findcursor+1);
       
  1903                 tempBuf.Delete(0, ii+1);
       
  1904                 if (tempBuf.Length()==0)
       
  1905                     {
       
  1906                     TBuf<KMaxWordLength> usefortrim;
       
  1907                     usefortrim.Append(itemString[0]);
       
  1908                     UpdateNextCharsFromStringL(aNextChars, usefortrim);
       
  1909                     return ETrue;
       
  1910                     }
       
  1911                 ii=0;
       
  1912                 }
       
  1913             else
       
  1914                 {
       
  1915                 ii++;
       
  1916                 }
       
  1917             }
       
  1918         else
       
  1919             {
       
  1920             ii++;
       
  1921             }
       
  1922 
       
  1923         }
       
  1924     aSearchText.Zero();
       
  1925 
       
  1926     aSearchText.Copy(tempBuf);
       
  1927 
       
  1928     aItemString.Zero();
       
  1929 
       
  1930     aItemString.Copy(itemString);
       
  1931 
       
  1932     return EFalse;
       
  1933 
       
  1934     }
       
  1935 // ---------------------------------------------------------------------------
       
  1936 // CheckEnglishFirst
       
  1937 // ---------------------------------------------------------------------------
       
  1938 //
       
  1939 TBool CFindUtilChineseECE::CheckEnglishFirstL( RPointerArray<STRINGINFO>& aarray, TDes& aSearchText,HBufC*& aNextChars)
       
  1940     {
       
  1941     TBool ret = EFalse ;
       
  1942     if (aarray.Count() > 0)
       
  1943         {
       
  1944         const TInt arrayLength = aarray.Count();
       
  1945         const TInt searchStrLength = aSearchText.Length();
       
  1946         TBuf<KMaxWordLength> tempBuf;
       
  1947         TBuf<KMaxWordLength> temp;
       
  1948 
       
  1949         TInt searchStrIndex = 0;
       
  1950         STRINGINFO* pStringInfo= NULL;
       
  1951         TBuf<KMaxWordLength> transSearchBuf;
       
  1952         TInt index = 0;
       
  1953 
       
  1954         tempBuf.Zero();
       
  1955 
       
  1956         tempBuf.Copy(aSearchText);
       
  1957         // First only check English
       
  1958         for (; index < arrayLength; index ++)
       
  1959             {
       
  1960             transSearchBuf.Zero();
       
  1961             pStringInfo = aarray[index];
       
  1962 
       
  1963             transSearchBuf = tempBuf.Mid(searchStrIndex, searchStrLength
       
  1964                 - searchStrIndex);
       
  1965 
       
  1966             // Compare word
       
  1967             if (!pStringInfo->isChinese)
       
  1968                 {
       
  1969                 searchStrIndex += MatchString(pStringInfo->segmentString,
       
  1970                     transSearchBuf);
       
  1971                 }
       
  1972 
       
  1973             if (searchStrIndex >= searchStrLength)
       
  1974                 {
       
  1975                 ret = ETrue;
       
  1976 
       
  1977                 //append to next char
       
  1978                 if (pStringInfo->segmentString.Length() > searchStrIndex)
       
  1979                     {
       
  1980                     UpdateNextCharsL(aNextChars,
       
  1981                         pStringInfo->segmentString[searchStrIndex]);
       
  1982                     }
       
  1983                 break;
       
  1984                 }
       
  1985             }
       
  1986         //for english string add next character directly    
       
  1987         if (ret)
       
  1988             {
       
  1989             if (arrayLength <= index+1)
       
  1990                 {
       
  1991                 return ret;
       
  1992                 }
       
  1993 
       
  1994             AppendCharInNextSegmentL(aarray,index+1,aNextChars);
       
  1995 
       
  1996             }
       
  1997         }
       
  1998     return ret;
       
  1999     }
       
  2000 // ---------------------------------------------------------------------------
       
  2001 // AddNextIfOverlapL to check if overlap problem 
       
  2002 // ---------------------------------------------------------------------------
       
  2003 //
       
  2004 void CFindUtilChineseECE::AddNextIfOverlapL(const RPointerArray<STRINGINFO>& astringInfoArr ,
       
  2005     const TInt aindex, const TInt aindexforfind, const TDes& aCurrentBuf,HBufC*& aNextChars )
       
  2006     {
       
  2007     TBuf<KMaxWordLength> temp;
       
  2008     TBuf<KMaxWordLength> tempNext;
       
  2009     RPointerArray<HBufC> tempSpellList;
       
  2010     STRINGINFO* pStringInfo;
       
  2011     STRINGINFO* pStringInfoNext;
       
  2012 
       
  2013     if(astringInfoArr.Count()>aindex)
       
  2014         {
       
  2015         pStringInfo= astringInfoArr[aindex];
       
  2016         }
       
  2017 
       
  2018     if (pStringInfo->isChinese)
       
  2019         {
       
  2020         if((pStringInfo->segmentString).Length()>aindexforfind+1)//in same segment
       
  2021             {
       
  2022             if (DoTranslationL(TInt16((pStringInfo->segmentString)[aindexforfind+1]), tempSpellList))
       
  2023                 {
       
  2024                 temp.Copy(tempSpellList[0]->Des());
       
  2025                 }
       
  2026             }
       
  2027         else if(astringInfoArr.Count()>aindex+1)//next segment should be english
       
  2028             {
       
  2029             temp.Copy(astringInfoArr[aindex+1]->segmentString);
       
  2030             }
       
  2031         }
       
  2032     else
       
  2033         {
       
  2034         if(astringInfoArr.Count()>aindex+1)
       
  2035             {
       
  2036             pStringInfo= astringInfoArr[aindex+1]; //next segment should be chinese
       
  2037             if (!DoTranslationL(TInt16((pStringInfo->segmentString)[0]), tempSpellList))
       
  2038                 {
       
  2039                 temp.Copy(pStringInfo->segmentString);
       
  2040                 }
       
  2041             else
       
  2042                 {
       
  2043                 temp.Copy(tempSpellList[0]->Des());
       
  2044                 }
       
  2045             }
       
  2046 
       
  2047         }
       
  2048     tempSpellList.ResetAndDestroy();
       
  2049     if(ReverseMatchString(aCurrentBuf,temp)>0)
       
  2050         {
       
  2051         if (pStringInfo->isChinese)
       
  2052             {
       
  2053             if((pStringInfo->segmentString).Length()>aindexforfind+2)//in same segment
       
  2054                 {
       
  2055                 if (!DoTranslationL(TInt16((pStringInfo->segmentString)[aindexforfind+2]), tempSpellList))
       
  2056                     {
       
  2057                     tempNext.Append((pStringInfo->segmentString)[aindexforfind+2]);
       
  2058                     }
       
  2059                 else
       
  2060                     {
       
  2061                     tempNext.Copy(tempSpellList[0]->Des());
       
  2062                     }
       
  2063                 }
       
  2064             else if(astringInfoArr.Count()>aindex+2)//next segment should be english
       
  2065                 {
       
  2066                 pStringInfoNext = astringInfoArr[aindex+2];
       
  2067                 if(pStringInfoNext->isChinese)
       
  2068                     {
       
  2069                     if (!DoTranslationL(TInt16((pStringInfoNext->segmentString)[0]),
       
  2070                         tempSpellList))
       
  2071                         {
       
  2072                         tempNext.Append((pStringInfoNext->segmentString)[0]);
       
  2073                         }
       
  2074                     else
       
  2075                         {
       
  2076                         tempNext.Copy(tempSpellList[0]->Des());
       
  2077                         }
       
  2078                     }
       
  2079                 else
       
  2080                     {
       
  2081                     tempNext.Copy(pStringInfoNext->segmentString);
       
  2082                     }
       
  2083                 }
       
  2084             }
       
  2085         else
       
  2086             {
       
  2087             if(astringInfoArr.Count()>aindex+2)
       
  2088                 {
       
  2089                 pStringInfo= astringInfoArr[aindex+2]; //next segment should be chinese
       
  2090                 if (!DoTranslationL(TInt16((pStringInfo->segmentString)[0]), tempSpellList))
       
  2091                     {
       
  2092                     tempNext.Copy(pStringInfo->segmentString);
       
  2093                     }
       
  2094                 else
       
  2095                     {
       
  2096                     tempNext.Copy(tempSpellList[0]->Des());
       
  2097                     }
       
  2098                 }        
       
  2099             }
       
  2100         }
       
  2101 
       
  2102     if(tempNext.Length()>0)
       
  2103         {
       
  2104         UpdateNextCharsL(aNextChars,tempNext[0]);
       
  2105         }  
       
  2106     tempSpellList.ResetAndDestroy();
       
  2107     tempSpellList.Close();
       
  2108     }
       
  2109 // ---------------------------------------------------------------------------
       
  2110 // AppendCharInNextSegmentL this segment is english
       
  2111 // ---------------------------------------------------------------------------
       
  2112 //
       
  2113 void CFindUtilChineseECE::AppendCharInNextSegmentL(const RPointerArray<STRINGINFO>& astringInfoArr ,
       
  2114     const TInt aindex,HBufC*& aNextChars)
       
  2115     {
       
  2116     TBuf<KMaxWordLength> temp;
       
  2117 
       
  2118     RPointerArray<HBufC> tempSpellList;
       
  2119 
       
  2120     if ( !astringInfoArr[aindex]->isChinese)
       
  2121         {
       
  2122         UpdateNextCharsL(aNextChars,
       
  2123             astringInfoArr[aindex]->segmentString[0]);
       
  2124         }
       
  2125     else
       
  2126         {
       
  2127         if (!DoTranslationL(
       
  2128             TInt16(astringInfoArr[aindex]->segmentString[0]),
       
  2129             tempSpellList))
       
  2130             {
       
  2131             UpdateNextCharsL(aNextChars,
       
  2132                 astringInfoArr[aindex]->segmentString[0]);
       
  2133             }
       
  2134         else
       
  2135             {
       
  2136             //for multiphnetic spell
       
  2137             TInt spellCount = tempSpellList.Count();
       
  2138             // Search all spelling
       
  2139             for (TInt j = 0; j < spellCount; j++)
       
  2140                 {
       
  2141                 temp = tempSpellList[j]->Des();
       
  2142                 UpdateNextCharsL(aNextChars, temp[0]);
       
  2143                 }//end for
       
  2144             }
       
  2145         }
       
  2146     tempSpellList.ResetAndDestroy();
       
  2147     tempSpellList.Close();
       
  2148     }
       
  2149 
       
  2150 // ---------------------------------------------------------------------------
       
  2151 // AppendNextSegmentFirstChar this segment is chinese
       
  2152 // ---------------------------------------------------------------------------
       
  2153 //
       
  2154 TBool CFindUtilChineseECE::AppendNextSegmentFirstCharL(const RPointerArray<STRINGINFO>& astringInfoArr ,
       
  2155     const TInt aindex ,const TInt aindexforfind,const TDes& aCurrentBuf ,const TDes& aTranSearchBuf,HBufC*& aNextChars)
       
  2156     {
       
  2157     STRINGINFO* pStringInfo= astringInfoArr[aindex];
       
  2158     TBuf<KMaxWordLength> temp;
       
  2159     TInt ret;
       
  2160     if (pStringInfo->isChinese)
       
  2161         {
       
  2162         if (aCurrentBuf.Length() > aindexforfind + 1)
       
  2163             {
       
  2164             RPointerArray<HBufC> tempSpellList;
       
  2165             if (!DoTranslationL(
       
  2166                 TInt16(aCurrentBuf[aindexforfind + 1]),
       
  2167                 tempSpellList))
       
  2168                 {
       
  2169                 UpdateNextCharsL(aNextChars,
       
  2170                     aCurrentBuf[aindexforfind + 1 ]);
       
  2171                 }
       
  2172             else
       
  2173                 {
       
  2174                 //for multiphnetic spell
       
  2175                 TInt spellCount = tempSpellList.Count();
       
  2176                 // Search all spelling
       
  2177                 for (TInt j = 0; j < spellCount; j++)
       
  2178                     {
       
  2179                     temp = tempSpellList[j]->Des();
       
  2180                     UpdateNextCharsL(aNextChars, temp[0]);
       
  2181                     if (temp.Length()>1)
       
  2182                         {
       
  2183                         TBuf<KMaxWordLength>
       
  2184                         useforminan(aTranSearchBuf);
       
  2185                         useforminan.Append(temp[1]);
       
  2186                         if (MatchRefineL(aCurrentBuf, useforminan))
       
  2187                             {
       
  2188                             UpdateNextCharsL(aNextChars,temp[1]);
       
  2189                             }
       
  2190                         }
       
  2191                     }//end for                               
       
  2192                 }
       
  2193             tempSpellList.ResetAndDestroy();
       
  2194             tempSpellList.Close();
       
  2195             }
       
  2196         else
       
  2197             {
       
  2198             //if space exist in chinese words, it will split them into differenct segments.
       
  2199             if (aindex < astringInfoArr.Count() - 1)
       
  2200                 {
       
  2201                 STRINGINFO* pStringInfo1 =
       
  2202                 astringInfoArr[aindex + 1];
       
  2203                 if (pStringInfo1->isChinese)
       
  2204                     {
       
  2205                     RPointerArray<HBufC> tempSpellList;
       
  2206                     if (!DoTranslationL(TInt16((pStringInfo1->segmentString)[0]),
       
  2207                         tempSpellList))
       
  2208                         {
       
  2209                         UpdateNextCharsL(aNextChars,(pStringInfo1->segmentString)[0]);
       
  2210                         }
       
  2211                     else
       
  2212                         {
       
  2213                         //for multiphnetic spell
       
  2214                         TInt spellCount = tempSpellList.Count();
       
  2215                         // Search all spelling
       
  2216                         for (TInt j = 0; j < spellCount; j++)
       
  2217                             {
       
  2218                             temp = tempSpellList[j]->Des();
       
  2219                             UpdateNextCharsL(aNextChars,temp[0]);
       
  2220                             }//end for
       
  2221                         }
       
  2222                     tempSpellList.ResetAndDestroy();
       
  2223                     tempSpellList.Close();
       
  2224                     }
       
  2225                 else
       
  2226                     {
       
  2227                     UpdateNextCharsL(aNextChars,
       
  2228                         pStringInfo1->segmentString[0]);
       
  2229                     }
       
  2230                 }
       
  2231             }
       
  2232 
       
  2233         }
       
  2234     else
       
  2235         {
       
  2236         //have no next element in array
       
  2237         if (astringInfoArr.Count() <= aindex+1)
       
  2238             {
       
  2239             ret = ETrue;
       
  2240             return ret;
       
  2241             }
       
  2242 
       
  2243         AppendCharInNextSegmentL(astringInfoArr,aindex+1,aNextChars);
       
  2244         }
       
  2245     return ret;
       
  2246     }
       
  2247 
       
  2248 // ---------------------------------------------------------------------------
       
  2249 // IsAdaptiveFindMatchL
       
  2250 // ---------------------------------------------------------------------------
       
  2251 //
       
  2252 TBool CFindUtilChineseECE::IsAdaptiveFindMatchL( const TDesC& aItemString, const TDesC& aSearchText,
       
  2253     HBufC*& aNextChars )
       
  2254     {
       
  2255 
       
  2256     TBuf<KMaxWordLength> tempBuf;    
       
  2257     TBuf<KMaxWordLength> itemString;
       
  2258 
       
  2259     TBool ret = EFalse;
       
  2260 
       
  2261     tempBuf.Zero();
       
  2262     if ( KMaxWordLength > aSearchText.Length() )
       
  2263         {
       
  2264         tempBuf.Copy( aSearchText );
       
  2265         }
       
  2266     else
       
  2267         {
       
  2268         tempBuf.Copy( aSearchText.Left( KMaxWordLength ) );
       
  2269         }
       
  2270     
       
  2271     itemString.Zero();
       
  2272      
       
  2273     if ( KMaxWordLength > aItemString.Length() )
       
  2274         {
       
  2275         itemString.Copy( aItemString );
       
  2276         }
       
  2277     else
       
  2278         {
       
  2279         itemString.Copy( aItemString.Left( KMaxWordLength ) );
       
  2280         }
       
  2281     
       
  2282     RemoveSeparator(tempBuf);
       
  2283 
       
  2284     RPointerArray<HBufC> spellList;
       
  2285 
       
  2286     //trim the sepcial char
       
  2287     if(itemString.Length()>0)
       
  2288         {
       
  2289         if(itemString[0]== KLeftToRightFlag || itemString[0]== KRightToLeftFlag)
       
  2290             {
       
  2291             itemString.Delete(0,1);
       
  2292             itemString.Delete((itemString.Length()-1),1);     
       
  2293             } 
       
  2294         }                
       
  2295 
       
  2296     //Find if search string has chinese word. 
       
  2297     //Compare with item string if find chinese word in item string then delete it from search and item string.
       
  2298 
       
  2299     if(IsChineseWord(tempBuf))
       
  2300         {
       
  2301         if(TrimChineseCharacterL(itemString,tempBuf,aNextChars))
       
  2302             {
       
  2303             spellList.ResetAndDestroy();//destroy spellList
       
  2304             spellList.Close();
       
  2305             return ETrue;
       
  2306             }
       
  2307         }
       
  2308 
       
  2309     // Array for item string
       
  2310     RPointerArray<STRINGINFO> stringInfoArr;
       
  2311     // Split item string
       
  2312     SplitItemStringL(stringInfoArr, itemString);
       
  2313 
       
  2314     // For store temp data 
       
  2315     TBuf<KMaxWordInterpretationLen> temp;
       
  2316 
       
  2317     //First only check English
       
  2318 
       
  2319     if(CheckEnglishFirstL(stringInfoArr,tempBuf,aNextChars))
       
  2320         {
       
  2321         spellList.ResetAndDestroy();//destroy spellList
       
  2322         spellList.Close();
       
  2323         stringInfoArr.ResetAndDestroy();
       
  2324         stringInfoArr.Close();
       
  2325         return ETrue;
       
  2326         }
       
  2327 
       
  2328     const TInt arrayLength = stringInfoArr.Count();
       
  2329     const TInt searchStrLength = tempBuf.Length();
       
  2330     TInt searchStrIndex = 0;
       
  2331     STRINGINFO* pStringInfo= NULL;
       
  2332     TBuf<KMaxWordLength> transSearchBuf;
       
  2333     TInt index = 0; 
       
  2334     TInt indexforfind =0;
       
  2335     TInt indexlast=0;
       
  2336 
       
  2337     TBuf<KMaxWordLength> bufcurrent;
       
  2338     TBuf<KMaxWordLength> tempbufcurrent;
       
  2339 
       
  2340     // Find Chinese and English
       
  2341     for (; index < arrayLength; index ++)
       
  2342         {
       
  2343         TInt matchLength = 0;
       
  2344         transSearchBuf.Zero();
       
  2345         pStringInfo = stringInfoArr[index];
       
  2346 
       
  2347         transSearchBuf = tempBuf.Mid(searchStrIndex, searchStrLength
       
  2348             - searchStrIndex);
       
  2349         if (transSearchBuf.Length()==0)
       
  2350             {
       
  2351             break;
       
  2352             }
       
  2353 
       
  2354         bufcurrent = pStringInfo->segmentString;
       
  2355 
       
  2356         for (TInt j =0; j < pStringInfo->segmentString.Length(); j++)
       
  2357             {
       
  2358             TInt indexforfindtemp = 0;
       
  2359             TInt searchStrIndextemp = 0;
       
  2360             if (pStringInfo->isChinese)
       
  2361                 {
       
  2362                 tempbufcurrent = bufcurrent.Mid(j);
       
  2363                 matchLength = MatchChineseStringL(tempbufcurrent,
       
  2364                     transSearchBuf, indexforfindtemp);
       
  2365                 searchStrIndextemp +=matchLength;
       
  2366                 if (indexforfindtemp>=indexforfind)
       
  2367                     {
       
  2368                     if (indexlast == index && searchStrIndextemp
       
  2369                         >= searchStrIndex)
       
  2370                         {
       
  2371                         searchStrIndex = searchStrIndextemp;
       
  2372                         }
       
  2373                     else
       
  2374                         if (indexlast != index)
       
  2375                             {
       
  2376                             searchStrIndex += searchStrIndextemp;
       
  2377                             }
       
  2378                     indexforfind = indexforfindtemp;
       
  2379                     indexlast = index;
       
  2380                     }
       
  2381                 }
       
  2382             else
       
  2383                 {//english words and chinese words don't coexist in same segment
       
  2384                 matchLength = MatchString(bufcurrent, transSearchBuf);
       
  2385                 searchStrIndex +=matchLength;
       
  2386                 if (searchStrIndex >= searchStrLength)
       
  2387                     {
       
  2388                     //append next char in the same segment
       
  2389                     ret = ETrue;
       
  2390 
       
  2391                     if (bufcurrent.Length() > matchLength)
       
  2392                         {
       
  2393                         UpdateNextCharsL(aNextChars, bufcurrent[matchLength]);
       
  2394                         }
       
  2395                     if (arrayLength <= index+1)
       
  2396                         {
       
  2397                         spellList.ResetAndDestroy();//destroy spellList
       
  2398                         spellList.Close();
       
  2399                         stringInfoArr.ResetAndDestroy();
       
  2400                         stringInfoArr.Close();
       
  2401                         return ret;
       
  2402                         }
       
  2403 
       
  2404                     AppendCharInNextSegmentL(stringInfoArr,index+1,aNextChars);
       
  2405 
       
  2406                     }
       
  2407                 break;
       
  2408                 }
       
  2409             // Append next character in same segment this segment is chinese
       
  2410             if (searchStrIndex >= searchStrLength)
       
  2411                 {
       
  2412                 ret = ETrue;
       
  2413                 RPointerArray<HBufC> tempSpellList;
       
  2414                 if (tempbufcurrent.Length()>indexforfind)
       
  2415                     {
       
  2416                     if (!DoTranslationL(TInt16(tempbufcurrent[indexforfind]),
       
  2417                         tempSpellList))
       
  2418                         {
       
  2419                         UpdateNextCharsL(aNextChars,
       
  2420                             tempbufcurrent[indexforfind]);
       
  2421                         }
       
  2422                     else
       
  2423                         {
       
  2424                         //for multiphnetic spell
       
  2425                         TInt spellCount = tempSpellList.Count();
       
  2426                         TInt matchMaxIndex = 0;
       
  2427                         TInt matchMax = 0;
       
  2428                         TInt matchMaxPre = 0;
       
  2429                         // Search all spelling
       
  2430                         for (TInt j = 0; j < spellCount; j++)
       
  2431                             {
       
  2432                             //for multiphnetic spell
       
  2433                             TInt spellCount = tempSpellList.Count();
       
  2434                             TInt matchMaxIndex = 0;
       
  2435                             TInt matchMax = 0;
       
  2436                             TInt matchMaxPre = 0;
       
  2437                             TBool fullmatch = EFalse;
       
  2438                             TBool offset = KErrNotFound;
       
  2439                             // Search all spelling
       
  2440                             for (TInt j = 0; j < spellCount; j++)
       
  2441                                 {
       
  2442                                 temp = tempSpellList[j]->Des();
       
  2443                                 for (TInt k = 1; k <= searchStrLength; k++)
       
  2444                                     {
       
  2445                                     TBuf<KMaxWordLength> tmpBuf = tempBuf.Mid(
       
  2446                                         searchStrLength - k, k);
       
  2447                                     offset = temp.Find(tmpBuf);
       
  2448                                     if (offset != KErrNotFound)
       
  2449                                         {
       
  2450                                         TBuf<KMaxWordLength> buf = temp.Mid(0,k);
       
  2451                                         if (buf == tmpBuf)
       
  2452                                             {
       
  2453                                             fullmatch = ETrue;
       
  2454                                             }
       
  2455                                         }
       
  2456                                     if (offset != KErrNotFound && fullmatch)
       
  2457                                         {
       
  2458                                         matchMax = k;
       
  2459                                         }
       
  2460                                     fullmatch = EFalse;
       
  2461                                     }
       
  2462                                 if (matchMax > matchMaxPre)
       
  2463                                     {
       
  2464                                     matchMaxPre = matchMax;
       
  2465                                     matchMaxIndex = j;
       
  2466                                     }
       
  2467                                 if (matchMax == searchStrLength && fullmatch)
       
  2468                                     {
       
  2469                                     if (matchMaxPre <temp.Length())
       
  2470                                         {
       
  2471                                         UpdateNextCharsL(aNextChars, temp[matchMax]);
       
  2472                                         }
       
  2473                                     }
       
  2474                                 fullmatch = EFalse;
       
  2475                                 offset = KErrNotFound;
       
  2476                                 }
       
  2477                             temp = tempSpellList[matchMaxIndex]->Des();
       
  2478                             if (matchMaxPre <temp.Length())
       
  2479                                 {
       
  2480                                 UpdateNextCharsL(aNextChars,temp[matchMaxPre]);
       
  2481                                 }
       
  2482                             }
       
  2483                         tempSpellList.ResetAndDestroy();
       
  2484                         tempSpellList.Close();
       
  2485                         }
       
  2486                     }
       
  2487                 //Append first translated character or english letter in next segment.
       
  2488                 if (ret)
       
  2489                     { 
       
  2490                     AppendNextSegmentFirstCharL(stringInfoArr,index,
       
  2491                         indexforfind,tempbufcurrent,transSearchBuf,aNextChars);
       
  2492 
       
  2493                     AddNextIfOverlapL(stringInfoArr,index,indexforfind+j,transSearchBuf,aNextChars);
       
  2494                     }
       
  2495                 searchStrIndex = 0;
       
  2496                 }
       
  2497             indexforfind = 0;
       
  2498             }
       
  2499         }
       
  2500 
       
  2501     spellList.ResetAndDestroy();//destroy spellList
       
  2502     spellList.Close(); 		
       
  2503     stringInfoArr.ResetAndDestroy();
       
  2504     stringInfoArr.Close();
       
  2505 
       
  2506     return ret;
       
  2507     }
       
  2508 
       
  2509 // -----------------------------------------------------------------------------
       
  2510 // CFindUtilChineseECE::MatchAdaptiveRefineL
       
  2511 // (other items were commented in a header).
       
  2512 // -----------------------------------------------------------------------------
       
  2513 //  
       
  2514 TBool CFindUtilChineseECE::MatchAdaptiveRefineL( const TDesC& aItemString, 
       
  2515     const TDesC &aSearchText, HBufC*& aNextChars )
       
  2516     {
       
  2517     //Get default adaptive search method.
       
  2518     if ( aItemString.Length() == 0 )
       
  2519         {
       
  2520         return EFalse;
       
  2521         }
       
  2522     if ( aSearchText.Length() == 0 )
       
  2523         {
       
  2524         UpdateNextCharsFromStringL( aNextChars, aItemString );
       
  2525         return ETrue;
       
  2526         } 
       
  2527 
       
  2528     return IsAdaptiveFindMatchL( aItemString, aSearchText, aNextChars);		    
       
  2529 
       
  2530     }
       
  2531 #endif
       
  2532 
       
  2533 // ----------------------------------------------------------------------------
       
  2534 // CFindUtilChineseECE::ConvertdDataToKeyBoardModeL
       
  2535 // Converts the input data to the key board mode specified by the query
       
  2536 // ----------------------------------------------------------------------------
       
  2537 void CFindUtilChineseECE::ConvertdDataToKeyBoardModeL(CPsQuery& aQuery, 
       
  2538     const TDesC& aSearchTargetStr, 
       
  2539     TBuf<KMaxWordInterpretationLen>& aOutputNumInterpretationStr)
       
  2540     {    
       
  2541     if (iKeyboardMode == EItut)
       
  2542         {
       
  2543         iAlgorithm->GetKeyMap()->GetNumericKeyString(aSearchTargetStr, aOutputNumInterpretationStr);
       
  2544         }
       
  2545     else if (iKeyboardMode == EQwerty)
       
  2546         {
       
  2547         aOutputNumInterpretationStr = aSearchTargetStr;
       
  2548         aOutputNumInterpretationStr.LowerCase();
       
  2549         }
       
  2550     else
       
  2551         {
       
  2552 
       
  2553         TInt len = -1;
       
  2554         TBuf<KPsQueryMaxLen> outBuf;
       
  2555 
       
  2556         iAlgorithm->GetKeyMap()->GetNumericKeyString(aSearchTargetStr, outBuf);
       
  2557 
       
  2558         // Always loop thru the lowest length
       
  2559         if (aSearchTargetStr.Length() > aQuery.Count() )
       
  2560             {
       
  2561             len = aQuery.Count();
       
  2562             }
       
  2563         else
       
  2564             {
       
  2565             len = aSearchTargetStr.Length();
       
  2566             }
       
  2567 
       
  2568         // Interprete search target str according to the query char mode
       
  2569         for (TInt i = 0; i < len; i++)
       
  2570             {
       
  2571             if (aQuery.GetItemAtL(i).Mode() == EItut)
       
  2572                 {
       
  2573                 aOutputNumInterpretationStr.Append(outBuf[i]);
       
  2574                 }
       
  2575             else
       
  2576                 {
       
  2577                 aOutputNumInterpretationStr.Append(aSearchTargetStr[i]);
       
  2578                 }
       
  2579             }
       
  2580 
       
  2581         aOutputNumInterpretationStr.LowerCase();
       
  2582         }
       
  2583     }
       
  2584 
       
  2585 void CFindUtilChineseECE::GetPartOfQueryL(CPsQuery& aSrcQuery, TInt aStartIndex, 
       
  2586     TInt aEndIndex, CPsQuery& aDestQuery)
       
  2587     {
       
  2588     TInt index = aStartIndex;
       
  2589 
       
  2590     if (aStartIndex <= aEndIndex && aStartIndex >= 0 && aSrcQuery.Count()>0 )
       
  2591         {
       
  2592         for (; index <= aEndIndex; index++)
       
  2593             {
       
  2594             // Add a query item
       
  2595             CPsQueryItem* newItem = CPsQueryItem::NewL();
       
  2596             CPsQueryItem& tempItem = aSrcQuery.GetItemAtL(index);
       
  2597 
       
  2598             newItem->SetCharacter(tempItem.Character());
       
  2599             newItem->SetMode(tempItem.Mode());
       
  2600 
       
  2601             aDestQuery.AppendL(*newItem);
       
  2602             }
       
  2603 
       
  2604         }
       
  2605     else 
       
  2606         {
       
  2607         User::Panic(KPanicReason, 0);
       
  2608         }
       
  2609     }
       
  2610 
       
  2611 void CFindUtilChineseECE::RemoveSeparatorL(CPsQuery& aQuery)
       
  2612     {
       
  2613     TInt index = 0;
       
  2614 
       
  2615     for ( ; index<aQuery.Count(); index++ )
       
  2616         {
       
  2617         CPsQueryItem& queryItem = aQuery.GetItemAtL( index );
       
  2618         switch( queryItem.Character() )
       
  2619             {
       
  2620             case '_': 
       
  2621             case '-':
       
  2622             case ' ':
       
  2623             case '\t':
       
  2624                 {
       
  2625                 // remove the charator of index
       
  2626                 aQuery.Remove( index );
       
  2627                 // ajust index after remove
       
  2628                 index--; 
       
  2629                 }
       
  2630             default:
       
  2631                 continue;
       
  2632             } // switch
       
  2633         } // for
       
  2634     }
       
  2635 // end of file