LCOV - code coverage report
Current view: top level - libreoffice/ucb/source/ucp/tdoc - tdoc_uri.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 31 90.3 %
Date: 2012-12-27 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : /**************************************************************************
      22             :                                 TODO
      23             :  **************************************************************************
      24             : 
      25             :  *************************************************************************/
      26             : 
      27             : #include "rtl/ustrbuf.hxx"
      28             : #include "../inc/urihelper.hxx"
      29             : 
      30             : #include "tdoc_uri.hxx"
      31             : 
      32             : using namespace tdoc_ucp;
      33             : 
      34             : //=========================================================================
      35             : //=========================================================================
      36             : //
      37             : // Uri Implementation.
      38             : //
      39             : //=========================================================================
      40             : //=========================================================================
      41             : 
      42          74 : void Uri::init() const
      43             : {
      44             :     // Already inited?
      45          74 :     if ( m_eState == UNKNOWN )
      46             :     {
      47          41 :         m_eState = INVALID;
      48             : 
      49             :         // Check for proper length: must be at least length of <sheme>:/
      50          41 :         if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
      51             :         {
      52             :             // Invaild length (to short).
      53             :             return;
      54             :         }
      55             : 
      56             :         // Check for proper scheme. (Scheme is case insensitive.)
      57             :         rtl::OUString aScheme
      58          41 :             = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
      59          41 :         if ( aScheme != TDOC_URL_SCHEME )
      60             :         {
      61             :             // Invaild scheme.
      62             :             return;
      63             :         }
      64             : 
      65             :         // Remember normalized scheme string.
      66          41 :         m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
      67             : 
      68          41 :         if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ]
      69             :                 != sal_Unicode( ':' ) )
      70             :         {
      71             :             // Invaild (no ':' after <scheme>).
      72             :             return;
      73             :         }
      74             : 
      75          41 :         if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ]
      76             :                 != sal_Unicode( '/' ) )
      77             :         {
      78             :             // Invaild (no '/' after <scheme>:).
      79             :             return;
      80             :         }
      81             : 
      82          41 :         m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
      83             : 
      84             :         // Note: There must be at least one slash; see above.
      85          41 :         sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
      86          41 :         bool bTrailingSlash = false;
      87          41 :         if ( nLastSlash == m_aUri.getLength() - 1 )
      88             :         {
      89             :             // ignore trailing slash
      90           5 :             bTrailingSlash = true;
      91           5 :             nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
      92             :         }
      93             : 
      94          41 :         if ( nLastSlash != -1 ) // -1 is valid for the root folder
      95             :         {
      96          36 :             m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
      97             : 
      98          36 :             if ( bTrailingSlash )
      99             :                 m_aName = m_aUri.copy( nLastSlash + 1,
     100           0 :                                        m_aUri.getLength() - nLastSlash - 2 );
     101             :             else
     102          36 :                 m_aName = m_aUri.copy( nLastSlash + 1 );
     103             : 
     104          36 :             m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
     105             : 
     106          36 :             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
     107          36 :             if ( nSlash == -1 )
     108          36 :                 m_aDocId = m_aPath.copy( 1 );
     109             :             else
     110           0 :                 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
     111             :         }
     112             : 
     113          41 :         if ( !m_aDocId.isEmpty() )
     114             :         {
     115          36 :             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
     116          36 :             if ( nSlash != - 1 )
     117           0 :                 m_aInternalPath = m_aPath.copy( nSlash );
     118             :             else
     119          36 :                 m_aInternalPath = rtl::OUString("/");
     120             :         }
     121             : 
     122          41 :         m_eState = VALID;
     123             :     }
     124             : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10