phoneapp/phoneuiutils/src/phonevanitydialingutils.cpp
branchRCL_3
changeset 81 c26cc2a7c548
parent 73 e30d4a1b8bad
child 82 b49b5af297a7
equal deleted inserted replaced
73:e30d4a1b8bad 81:c26cc2a7c548
     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:
       
    15 *     Helper class for converting vanity dialing numbers
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "phonevanitydialingutils.h"
       
    21 
       
    22 // CONSTANTS
       
    23 const TInt KCharA = 'A';
       
    24 const TInt KCharB = 'B';
       
    25 const TInt KCharC = 'C';
       
    26 const TInt KCharD = 'D';
       
    27 const TInt KCharE = 'E';
       
    28 const TInt KCharF = 'F';
       
    29 const TInt KCharG = 'G';
       
    30 const TInt KCharH = 'H';
       
    31 const TInt KCharI = 'I';
       
    32 const TInt KCharJ = 'J';
       
    33 const TInt KCharK = 'K';
       
    34 const TInt KCharL = 'L';
       
    35 const TInt KCharM = 'M';
       
    36 const TInt KCharN = 'N';
       
    37 const TInt KCharO = 'O';
       
    38 const TInt KCharP = 'P';
       
    39 const TInt KCharQ = 'Q';
       
    40 const TInt KCharR = 'R';
       
    41 const TInt KCharS = 'S';
       
    42 const TInt KCharT = 'T';
       
    43 const TInt KCharU = 'U';
       
    44 const TInt KCharV = 'V';
       
    45 const TInt KCharW = 'W';
       
    46 const TInt KCharX = 'X';
       
    47 const TInt KCharY = 'Y';
       
    48 const TInt KCharZ = 'Z';
       
    49 
       
    50 const TInt KChar2 = '2';
       
    51 const TInt KChar3 = '3';
       
    52 const TInt KChar4 = '4';
       
    53 const TInt KChar5 = '5';
       
    54 const TInt KChar6 = '6';
       
    55 const TInt KChar7 = '7';
       
    56 const TInt KChar8 = '8';
       
    57 const TInt KChar9 = '9';
       
    58 
       
    59 _LIT( KPhoneVanityValidFirstChars, "0123456789+" );
       
    60 _LIT( KPhoneVanityValidChars, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*#+pw" );
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CouldBeVanityNumber
       
    64 //
       
    65 // Vanity dialing numbers start with a number, and after that they
       
    66 // contain only upper case letters (A-Z) and numbers
       
    67 // for example: 555PIZZA, +3583ONE2THREE
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 TBool CouldBeVanityNumber( TDesC& aDes )
       
    71     {
       
    72     if ( !aDes.Length() )
       
    73         {
       
    74         return EFalse;
       
    75         }
       
    76         
       
    77     TBool possibleVanityNumber = ETrue;
       
    78     
       
    79     // check first character
       
    80     TPtrC validFirstChar( KPhoneVanityValidFirstChars );
       
    81     if ( validFirstChar.Locate( aDes[0] ) == KErrNotFound )
       
    82         {
       
    83         possibleVanityNumber = EFalse;
       
    84         }
       
    85     
       
    86     // check rest of the string
       
    87     TInt i = 1;
       
    88     TPtrC validChar( KPhoneVanityValidChars );
       
    89     while ( possibleVanityNumber && i < aDes.Length() )
       
    90         {
       
    91         if ( validChar.Locate( aDes[i] ) == KErrNotFound )
       
    92             {
       
    93             possibleVanityNumber = EFalse;
       
    94             }
       
    95         i++;
       
    96         }
       
    97     
       
    98     return possibleVanityNumber;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // PhoneVanityDialingUtils::DoVanityNumberConversion
       
   103 //
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 EXPORT_C void PhoneVanityDialingUtils::DoVanityNumberConversion( TDes& aDes )
       
   107     {
       
   108     if ( CouldBeVanityNumber( aDes ) )
       
   109         {
       
   110         for ( TInt i = 0; i < aDes.Length(); i++ )
       
   111             {
       
   112             switch ( aDes[i] )
       
   113                 {
       
   114                 case KCharA:
       
   115                 case KCharB:
       
   116                 case KCharC:
       
   117                     aDes[i] = KChar2;
       
   118                     break;
       
   119                 case KCharD:
       
   120                 case KCharE:
       
   121                 case KCharF:
       
   122                     aDes[i] = KChar3;
       
   123                     break;
       
   124                 case KCharG:
       
   125                 case KCharH:
       
   126                 case KCharI:
       
   127                     aDes[i] = KChar4;
       
   128                     break;
       
   129                 case KCharJ:
       
   130                 case KCharK:
       
   131                 case KCharL:
       
   132                     aDes[i] = KChar5;
       
   133                     break;
       
   134                 case KCharM:
       
   135                 case KCharN:
       
   136                 case KCharO:
       
   137                     aDes[i] = KChar6;
       
   138                     break;
       
   139                 case KCharP:
       
   140                 case KCharQ:
       
   141                 case KCharR:
       
   142                 case KCharS:
       
   143                     aDes[i] = KChar7;
       
   144                     break;
       
   145                 case KCharT:
       
   146                 case KCharU:
       
   147                 case KCharV:
       
   148                     aDes[i] = KChar8;
       
   149                     break;
       
   150                 case KCharW:
       
   151                 case KCharX:
       
   152                 case KCharY:
       
   153                 case KCharZ:
       
   154                     aDes[i] = KChar9;
       
   155                     break;
       
   156                 default:
       
   157                     break;
       
   158                 }
       
   159             }
       
   160         }
       
   161     }
       
   162 
       
   163 // End of File