svgtopt/SVG/SVGImpl/src/SVGStringTokenizer.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 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:  SVG Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "SVGStringTokenizer.h"
       
    20 
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 //
       
    24 // ---------------------------------------------------------------------------
       
    25 TStringTokenizer::TStringTokenizer( const TDesC& aSrc, const TDesC& aDelim ) : iSrc( aSrc ),
       
    26                                                                                iDelim( aDelim )
       
    27     {
       
    28     SkipDeliminator( iDelim );
       
    29     }
       
    30 
       
    31 //
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 // ---------------------------------------------------------------------------
       
    35 TPtrC TStringTokenizer::NextToken()
       
    36     {
       
    37     return NextToken( iDelim );
       
    38     }
       
    39 
       
    40 //
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 // ---------------------------------------------------------------------------
       
    44 TPtrC TStringTokenizer::NextToken( const TDesC& aDelim )
       
    45     {
       
    46     iSrc.Mark();
       
    47     TChar tmpchar = iSrc.Peek();
       
    48     while ( !isDeliminator( tmpchar, aDelim ) && !iSrc.Eos() )
       
    49         {
       
    50         iSrc.Inc();
       
    51         tmpchar = iSrc.Peek();
       
    52         }
       
    53     TPtrC token = iSrc.MarkedToken();
       
    54     SkipDeliminator( aDelim );
       
    55     return token;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 // ---------------------------------------------------------------------------
       
    61 TBool TStringTokenizer::HasMoreTokens()
       
    62     {
       
    63     return !iSrc.Eos();
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 // ---------------------------------------------------------------------------
       
    69 TBool TStringTokenizer::isDeliminator( TChar aChar, const TDesC& aDelim )
       
    70     {
       
    71     TUint16 ch = ( TUint16 ) ( TUint ) aChar;
       
    72     
       
    73     TInt32 delimLength = aDelim.Length();
       
    74     for ( TInt32 i = 0; i < delimLength; i++ )
       
    75         {
       
    76         if ( ch == aDelim[i] )
       
    77             return ETrue;
       
    78         }
       
    79 
       
    80     return EFalse;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 // ---------------------------------------------------------------------------
       
    86 void TStringTokenizer::SkipDeliminator( const TDesC& aDelim )
       
    87     {
       
    88     TChar tmpchar = iSrc.Peek();
       
    89     while ( isDeliminator( tmpchar, aDelim ) && !iSrc.Eos() )
       
    90         {
       
    91         iSrc.Inc();
       
    92         tmpchar = iSrc.Peek();
       
    93         }
       
    94     }
       
    95