phoneclientserver/phoneclient/Src/PhCltUtils.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     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:  Utils
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "phcltutils.h" 
       
    21 
       
    22 
       
    23 // CONSTANTS
       
    24 _LIT( KPhCltValidChars, "+0123456789*#pwPW" );
       
    25 //Prefix for Sip.
       
    26 _LIT( KSipPrefix, "sip:" );
       
    27 //Prefix for Tel.
       
    28 _LIT( KTelPrefix, "tel:" );
       
    29 //Prefix for Sos.
       
    30 _LIT( KSosPrefix, "sos:" );
       
    31 // @ char
       
    32 _LIT( KAt, "@" );
       
    33 // Prefix length
       
    34 const TInt KPrefixLength = 4;
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // PhCltUtils::IsValidChar
       
    41 //
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C TBool PhCltUtils::IsValidChar( TChar aChar )
       
    45     {
       
    46     TPtrC valid( KPhCltValidChars );
       
    47 
       
    48     return valid.Locate( aChar ) != KErrNotFound;
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // PhCltUtils::RemoveInvalidChars
       
    54 //
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C void PhCltUtils::RemoveInvalidChars( TDes& aString )
       
    58     {
       
    59     TInt index = aString.Length() - 1;
       
    60 
       
    61     for ( ; index >= 0; index-- )
       
    62         {
       
    63         if ( !IsValidChar( aString[ index ] ) )
       
    64             {
       
    65             aString.Delete( index, 1 ); // one character
       
    66             }
       
    67         }
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // PhCltUtils::RemoveURIPrefixdAndDomainChars
       
    73 //
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C void PhCltUtils::RemoveURIPrefixdAndDomainChars( TDes& aString )
       
    77     {
       
    78       // Does number contains prefix. If yes then remove it
       
    79 
       
    80     if ( 0 == aString.FindC( KSipPrefix ) ||
       
    81          0 == aString.FindC( KTelPrefix ) ||
       
    82            0 == aString.FindC( KSosPrefix ) )
       
    83         {
       
    84         aString.Delete( 0, KPrefixLength );
       
    85           }
       
    86       // Does Number contains domain part. If yes remove it at beging of @ character.
       
    87     TInt atIndex = aString.Find( KAt );
       
    88     TInt telNumberLength = aString.Length();
       
    89       if ( 0 < atIndex && 
       
    90            atIndex < telNumberLength )
       
    91         {
       
    92             aString.Delete( atIndex, telNumberLength - atIndex );
       
    93             }
       
    94     }
       
    95 //  End of File