contentpublishingsrv/contentharvester/factorysettingsplugin/src/chfactsetutils.cpp
changeset 93 82b66994846c
parent 92 782e3408c2ab
child 94 dbb8300717f7
equal deleted inserted replaced
92:782e3408c2ab 93:82b66994846c
     1 /*
       
     2 * Copyright (c) 2008 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 methods.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "chfactsetutils.h"
       
    22 #include "chfactorysettingsglobals.h"
       
    23 #include "cpdebug.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // FactSetCHUtils::StrDec2Int
       
    29 // (other items were commented in a header).
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 TUint FactSetCHUtils::StrDec2Uint( const TDesC& aStr )
       
    33     {
       
    34     CP_DEBUG(_L8("FactSetCHUtils::StrDec2Uint" ));
       
    35     TLex lexer(aStr);
       
    36     TInt ret;
       
    37     if ( lexer.Val( ret ) )
       
    38         {
       
    39         _LIT(KDesc, "Int");
       
    40         BadArgument( KDesc, aStr, KErrArgument ) ;
       
    41         }
       
    42     return ret;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // FactSetCHUtils::Str2Uint
       
    47 // (other items were commented in a header).
       
    48 // -----------------------------------------------------------------------------
       
    49 //   
       
    50 TUint FactSetCHUtils::Str2Uint( const TDesC& aStr )
       
    51     {
       
    52     TUint ret(Str2Int( aStr ) );
       
    53     return ret;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // FactSetCHUtils::Str2Bool
       
    58 // (other items were commented in a header).
       
    59 // -----------------------------------------------------------------------------
       
    60 //   
       
    61 TBool FactSetCHUtils::Str2Bool( const TDesC& aStr )
       
    62     {
       
    63     CP_DEBUG(_L8("FactSetCHUtils::Str2Bool" ));
       
    64     TBool ret;
       
    65     if ( !aStr.Compare( KTrue ) )
       
    66         {
       
    67         ret = ETrue;
       
    68         }
       
    69     else if ( !aStr.Compare( KFalse ) )
       
    70         {
       
    71         ret = EFalse;
       
    72         }
       
    73     else
       
    74         ret = (Str2Int( aStr ) );
       
    75     return ret;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // FactSetCHUtils::Str2Int
       
    80 // (other items were commented in a header).
       
    81 // -----------------------------------------------------------------------------
       
    82 //   
       
    83 TInt FactSetCHUtils::Str2Int( const TDesC& aStr )
       
    84     {
       
    85     CP_DEBUG(_L8("FactSetCHUtils::Str2Int" ));
       
    86     // if a string starts from '0x' then convert aStr from hex to int.
       
    87     // else send aStr to the StrDec2Uint	
       
    88     _LIT(KHexStart,"0x");
       
    89 
       
    90     TInt position(aStr.Find( KHexStart ) );
       
    91     TInt ret(KErrArgument);
       
    92     if ( position == 0 )
       
    93         {
       
    94         // is hex
       
    95         TPtrC string(aStr.Mid( KHexStart().Length( ) ) );
       
    96 
       
    97         ret = StrHex2Uint( string );
       
    98         }
       
    99     else
       
   100         {
       
   101         ret = StrDec2Uint( aStr );
       
   102         }
       
   103     return ret;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // FactSetCHUtils::StrHex2UintL
       
   108 // (other items were commented in a header).
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TUint FactSetCHUtils::StrHex2Uint( const TDesC& aStr )
       
   112     {
       
   113     CP_DEBUG(_L8("FactSetCHUtils::StrHex2Uint" ));
       
   114     TLex lexer(aStr);
       
   115     TUint ret;
       
   116     if ( lexer.Val( ret, EHex ) )
       
   117         {
       
   118         _LIT(KDesc, "Hex");
       
   119         BadArgument( KDesc, aStr, KErrArgument );
       
   120         }
       
   121     return ret;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // FactSetCHUtils::Str2Str8L
       
   126 // (other items were commented in a header).
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 HBufC8* FactSetCHUtils::Str2Str8LC( const TDesC& aStr )
       
   130     {
       
   131     CP_DEBUG(_L8("FactSetCHUtils::Str2Str8LC" ));
       
   132     HBufC8* ret = HBufC8::NewLC( aStr.Length( ) );
       
   133     ret->Des().Copy( aStr );
       
   134     return ret;
       
   135     }
       
   136 // -----------------------------------------------------------------------------
       
   137 // FactSetCHUtils::Str2UidL
       
   138 // (other items were commented in a header).
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TUid FactSetCHUtils::Str2Uid( const TDesC& aStr )
       
   142     {
       
   143     return TUid( TUid::Uid( Str2Uint( aStr ) ) );
       
   144     }
       
   145 // -----------------------------------------------------------------------------
       
   146 // FactSetCHUtils::Str2UidL
       
   147 // (other items were commented in a header).
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TReal FactSetCHUtils::Str2Real( const TDesC& aStr )
       
   151     {
       
   152     CP_DEBUG(_L8("FactSetCHUtils::Str2Real" ));
       
   153     TLex lexer(aStr);
       
   154     TReal ret;
       
   155     if ( lexer.Val( ret ) )
       
   156         {
       
   157         _LIT(KDesc, "Real");
       
   158         BadArgument( KDesc, aStr, KErrArgument );
       
   159         }
       
   160     return ret;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // FactSetCHUtils::Str2IntL
       
   165 // (other items were commented in a header).
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TInt32 FactSetCHUtils::Str2Int32( const TDesC& aStr )
       
   169     {
       
   170     TInt32 ret(Str2Int( aStr ) );
       
   171     return ret;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // FactSetCHUtils::BadArgument
       
   176 // (other items were commented in a header).
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void FactSetCHUtils::BadArgument( const TDesC& aCategory,
       
   180     const TDesC& aArgument, TInt aReason )
       
   181     {
       
   182     TRAP_IGNORE( BadArgumentL(aCategory, aArgument, aReason) );
       
   183     }
       
   184 // -----------------------------------------------------------------------------
       
   185 // FactSetCHUtils::BadArgumentL
       
   186 // (other items were commented in a header).
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void FactSetCHUtils::BadArgumentL( const TDesC& aCategory,
       
   190     const TDesC& aArgument, TInt aReason )
       
   191     {
       
   192     CP_DEBUG(_L8("FactSetCHUtils::BadArgumentL" ));
       
   193     _LIT(K2Dot,":");
       
   194     HBufC* buf = HBufC::NewLC( aCategory.Length( ) + aArgument.Length( )
       
   195             + K2Dot().Length( ) );
       
   196     TPtr ptr(buf->Des( ) );
       
   197     ptr.Copy( aCategory );
       
   198     ptr.Append( K2Dot );
       
   199     ptr.Append( aArgument );
       
   200     BadArgument( ptr, aReason );
       
   201     CleanupStack::PopAndDestroy( buf );
       
   202     }
       
   203 // -----------------------------------------------------------------------------
       
   204 // FactSetCHUtils::BadArgument
       
   205 // (other items were commented in a header).
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void FactSetCHUtils::BadArgument( const TDesC& aCategory, TInt aArgument,
       
   209     TInt aReason )
       
   210     {
       
   211     TBuf<KMaxIntString> buf;
       
   212     buf.Num( aArgument );
       
   213     BadArgument( aCategory, buf, aReason );
       
   214     }
       
   215 // -----------------------------------------------------------------------------
       
   216 // FactSetCHUtils::BadArgument
       
   217 // (other items were commented in a header).
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void FactSetCHUtils::BadArgument( const TDesC& aCategory, TInt aReason )
       
   221     {
       
   222     User::Panic( aCategory, aReason );
       
   223     }
       
   224 
       
   225 //  End of File