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