phonebookengines/contactsmodel/cntplsql/src/cpcskeymap.cpp
changeset 24 0ba2181d7c28
child 25 76a2435edfd4
equal deleted inserted replaced
0:e686773b3f54 24:0ba2181d7c28
       
     1 /*
       
     2 * Copyright (c) 2010 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: Retrieves the character map for each of the numeric keys.
       
    15 */
       
    16 
       
    17 // INCLUDE FILES
       
    18 #include "cpcskeymap.h"
       
    19 
       
    20 // Treat space as sepator
       
    21 #define KSpaceChar      ' '
       
    22 
       
    23 // Separator character stored in predictive search table columns
       
    24 _LIT(KSeparator, " ");
       
    25 
       
    26 
       
    27 // ============================== MEMBER FUNCTIONS ============================
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CPcsKeyMap::NewL
       
    31 // Two Phase Construction
       
    32 // ----------------------------------------------------------------------------
       
    33 CPcsKeyMap* CPcsKeyMap::NewL()
       
    34 	{
       
    35     CPcsKeyMap* self = new ( ELeave ) CPcsKeyMap();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40 	} 
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // CPcsKeyMap::CPcsKeyMap
       
    44 // Constructor
       
    45 // ----------------------------------------------------------------------------
       
    46 CPcsKeyMap::CPcsKeyMap()
       
    47 	{
       
    48 	}
       
    49 
       
    50 void CPcsKeyMap::ConstructL()
       
    51 	{   
       
    52 	}
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CPcsKeyMap::~CPcsKeyMap
       
    56 // Destructor
       
    57 // ----------------------------------------------------------------------------
       
    58 CPcsKeyMap::~CPcsKeyMap()
       
    59 	{
       
    60 	}
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CPcsKeyMap::GetNumericKeyStringL
       
    64 // If aPlainConversion is EFalse, supports sub-string searches and space is
       
    65 // converted to a separator character (not zero).
       
    66 // ----------------------------------------------------------------------------
       
    67 HBufC* CPcsKeyMap::GetNumericKeyStringL(const TDesC& aSource,
       
    68                                         TBool aPlainConversion) const
       
    69     {
       
    70     TInt length = aSource.Length();
       
    71     if (!aPlainConversion)
       
    72         {
       
    73         ++length; // One extra character for leading separator
       
    74         }
       
    75     HBufC* destination = HBufC::NewL(length);
       
    76     TPtr ptr = destination->Des();
       
    77 
       
    78     if (!aPlainConversion)
       
    79         {
       
    80         ptr.Append(KSeparator);
       
    81         }
       
    82 
       
    83 	for (TInt i = 0; i < aSource.Length(); ++i)
       
    84         {
       
    85 		if (!aPlainConversion && aSource[i] == KSpaceChar)
       
    86 			{
       
    87 			ptr.Append(KSeparator);
       
    88 			}
       
    89 		else
       
    90 			{
       
    91 			TChar a = aSource[i];
       
    92 			TChar b = a.GetUpperCase();
       
    93 			ptr.Append(GetNumericValueForChar(b));
       
    94 			}
       
    95         }
       
    96 
       
    97     return destination;
       
    98     }
       
    99 
       
   100 TChar CPcsKeyMap::GetNumericValueForChar(TChar input ) const
       
   101     {
       
   102     
       
   103     TChar ret = '0';
       
   104     switch (input)
       
   105         {
       
   106         case 'A': 
       
   107         case 'B': 
       
   108         case 'C':
       
   109                ret = '2';
       
   110                break;
       
   111         case 'D': 
       
   112         case 'E':
       
   113         case 'F':
       
   114             ret = '3';
       
   115             break;
       
   116             
       
   117         case 'G': 
       
   118         case 'H':
       
   119         case 'I':
       
   120             ret = '4';
       
   121             break;
       
   122 
       
   123         case 'J': 
       
   124         case 'K': 
       
   125         case 'L':
       
   126             ret = '5';
       
   127             break;
       
   128 
       
   129         case 'M': 
       
   130         case 'N': 
       
   131         case 'O':
       
   132             ret = '6';
       
   133             break;
       
   134       
       
   135         case 'P': 
       
   136         case 'Q':
       
   137         case 'R': 
       
   138         case 'S':
       
   139             ret = '7';
       
   140             break;
       
   141 
       
   142         case 'T':
       
   143         case 'U': 
       
   144         case 'V':
       
   145             ret = '8';
       
   146             break;
       
   147 
       
   148         case 'W':
       
   149         case 'X':
       
   150         case 'Y': 
       
   151         case 'Z':
       
   152             ret = '9';
       
   153             break;
       
   154             
       
   155 		case ' ':
       
   156 			ret = '0';
       
   157 			break;
       
   158 
       
   159 		default: // Other chars, e.g. numbers
       
   160 			ret = input;
       
   161         }
       
   162     return ret;    
       
   163     }
       
   164 
       
   165 // End of file