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