svgtopt/SVG/SVGImpl/src/SVGRelToAbsPath.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     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 <f32file.h>
       
    20 
       
    21 #include "SVGRelToAbsPath.h"
       
    22 
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 // ---------------------------------------------------------------------------
       
    27 TInt TSvgRelToAbsPath::GetFullPath( TParse& aParse,
       
    28                                     const TText8* upath,
       
    29                                     RFs& aSession,
       
    30                                     TDes* aFileName )
       
    31     {
       
    32     TInt r;
       
    33     TBuf<4> drive;
       
    34     TFileName nextBit;
       
    35     TText8 c =* upath;
       
    36 
       
    37     if ( c && upath[1] == KDriveDelimiter )
       
    38         {
       
    39         // drive name specified
       
    40         drive.Copy( TPtrC8( upath, 2 ) );
       
    41         drive.UpperCase();
       
    42         upath += 2;
       
    43         drive.Append( TChar( KPathDelimiter ) );
       
    44         }
       
    45     else
       
    46         {
       
    47         // no leading drive specifier
       
    48         drive.Zero();
       
    49         if ( c == KPathDelimiter || c == '/' )
       
    50             {
       
    51             upath += 1;
       
    52             drive.Append( TChar( KPathDelimiter ) );
       
    53             }
       
    54         }
       
    55 
       
    56     r = aSession.Parse( drive, aParse );
       
    57 
       
    58     // upath now looks like a relative pathname, to be added onto
       
    59     // aParse a directory at a time.
       
    60 
       
    61     c = *upath;
       
    62     while ( c && ( r == KErrNone ) )
       
    63         {
       
    64         const TText8* ustart = upath;
       
    65         do
       
    66             c = *upath++;
       
    67         while ( c && c != KPathDelimiter && c != '/' );
       
    68 
       
    69         TInt len = ( upath - ustart ) - 1; // excludes delimiter
       
    70         if ( len == 0 )
       
    71             continue;
       
    72         if ( ustart[0] == '.' )
       
    73             {
       
    74             if ( len == 1 )
       
    75                 continue; // directory . ignored
       
    76             if ( len == 2 && ustart[1] == '.' )
       
    77                 {
       
    78                 // directory ..
       
    79                 aParse.PopDir();
       
    80                 continue;
       
    81                 }
       
    82             }
       
    83         if ( len >= KMaxFileName )
       
    84             return KErrBadName;
       
    85         if ( c == '\0' && aFileName != NULL )
       
    86             {
       
    87             // it's the trailing filename
       
    88             aFileName->Copy( TPtrC8( ustart, len ) );
       
    89             break;
       
    90             }
       
    91         else
       
    92             {
       
    93             // it's a component of the accumulating path
       
    94             nextBit.Copy( TPtrC8( ustart, len ) );
       
    95             r = aParse.AddDir( nextBit );
       
    96             }
       
    97         }
       
    98     return( r );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 // ---------------------------------------------------------------------------
       
   104 TInt TSvgRelToAbsPath::GetFullFile( TFileName& aName,
       
   105                                     const TText8* upath,
       
   106                                     RFs& aSession )
       
   107     {
       
   108     TParse path;
       
   109     TInt err = GetFullPath( path, upath, aSession, & aName );
       
   110     if ( !err )
       
   111         {
       
   112         err = path.SetNoWild( path.DriveAndPath(), NULL, & aName );
       
   113         if ( !err )
       
   114             aName = path.FullName();
       
   115         }
       
   116     return err;
       
   117     }
       
   118 
       
   119