predictivesearch/PcsUtils/src/CWords.cpp
changeset 0 e686773b3f54
child 7 b3431bff8c19
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Utility class to hold data for predictive search.
       
    15 *                Used to marshal data between the client, server and data 
       
    16 *                plugins.
       
    17 *
       
    18 */
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CWords.h"
       
    22 
       
    23 
       
    24 // CWords
       
    25 inline CWords::CWords()
       
    26     {
       
    27     }
       
    28 
       
    29 EXPORT_C CWords* CWords::NewLC
       
    30         (const TDesC& aText)
       
    31     {
       
    32     CWords* self = new(ELeave) CWords();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL(aText);
       
    35     return self;
       
    36     }
       
    37 
       
    38 EXPORT_C CWords::~CWords()
       
    39     {
       
    40     iWords.Close();
       
    41     }
       
    42 
       
    43 EXPORT_C TInt CWords::MdcaCount() const
       
    44     {
       
    45     return iWords.Count();
       
    46     }
       
    47 
       
    48 EXPORT_C TPtrC16 CWords::MdcaPoint(TInt aIndex) const
       
    49     {
       
    50     return iWords[aIndex];
       
    51     }
       
    52 
       
    53 void CWords::ConstructL(const TDesC& aText)
       
    54     {
       
    55     const TInt textLength = aText.Length();
       
    56     for (TInt beg=0; beg < textLength; ++beg)
       
    57         {
       
    58         // Skip separators before next word
       
    59         if (!DefaultIsWordSeparator(aText[beg]))
       
    60             {
       
    61             // Scan the end of the word
       
    62             TInt end = beg;
       
    63             for (; end < textLength && !DefaultIsWordSeparator(aText[end]); ++end)
       
    64                 {
       
    65                 }
       
    66             const TInt len = end-beg;
       
    67             // Append found word to the array
       
    68             User::LeaveIfError(iWords.Append(aText.Mid(beg,len)));
       
    69             // Scan for next word
       
    70             beg = end;
       
    71             }
       
    72         }
       
    73 
       
    74     if (iWords.Count()==0 && textLength > 0)
       
    75         {
       
    76         // aText is all word separator characters -> make a "word" out of those
       
    77         User::LeaveIfError(iWords.Append(aText));
       
    78         }
       
    79     }
       
    80 
       
    81 TBool CWords::DefaultIsWordSeparator(TChar aChar)
       
    82     {
       
    83     return (aChar.IsSpace());
       
    84     }
       
    85