LCOV - code coverage report
Current view: top level - ucb/source/ucp/tdoc - tdoc_uri.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 31 90.3 %
Date: 2012-08-25 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 24 66.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : /**************************************************************************
      31                 :            :                                 TODO
      32                 :            :  **************************************************************************
      33                 :            : 
      34                 :            :  *************************************************************************/
      35                 :            : 
      36                 :            : #include "rtl/ustrbuf.hxx"
      37                 :            : #include "../inc/urihelper.hxx"
      38                 :            : 
      39                 :            : #include "tdoc_uri.hxx"
      40                 :            : 
      41                 :            : using namespace tdoc_ucp;
      42                 :            : 
      43                 :            : //=========================================================================
      44                 :            : //=========================================================================
      45                 :            : //
      46                 :            : // Uri Implementation.
      47                 :            : //
      48                 :            : //=========================================================================
      49                 :            : //=========================================================================
      50                 :            : 
      51                 :       1518 : void Uri::init() const
      52                 :            : {
      53                 :            :     // Already inited?
      54         [ +  + ]:       1518 :     if ( m_eState == UNKNOWN )
      55                 :            :     {
      56                 :        837 :         m_eState = INVALID;
      57                 :            : 
      58                 :            :         // Check for proper length: must be at least length of <sheme>:/
      59         [ +  - ]:        837 :         if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
      60                 :            :         {
      61                 :            :             // Invaild length (to short).
      62                 :            :             return;
      63                 :            :         }
      64                 :            : 
      65                 :            :         // Check for proper scheme. (Scheme is case insensitive.)
      66                 :            :         rtl::OUString aScheme
      67                 :        837 :             = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
      68         [ -  + ]:        837 :         if ( aScheme != TDOC_URL_SCHEME )
      69                 :            :         {
      70                 :            :             // Invaild scheme.
      71                 :            :             return;
      72                 :            :         }
      73                 :            : 
      74                 :            :         // Remember normalized scheme string.
      75                 :        837 :         m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
      76                 :            : 
      77         [ -  + ]:        837 :         if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ]
      78                 :            :                 != sal_Unicode( ':' ) )
      79                 :            :         {
      80                 :            :             // Invaild (no ':' after <scheme>).
      81                 :            :             return;
      82                 :            :         }
      83                 :            : 
      84         [ -  + ]:        837 :         if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ]
      85                 :            :                 != sal_Unicode( '/' ) )
      86                 :            :         {
      87                 :            :             // Invaild (no '/' after <scheme>:).
      88                 :            :             return;
      89                 :            :         }
      90                 :            : 
      91                 :        837 :         m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
      92                 :            : 
      93                 :            :         // Note: There must be at least one slash; see above.
      94                 :        837 :         sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
      95                 :        837 :         bool bTrailingSlash = false;
      96         [ +  + ]:        837 :         if ( nLastSlash == m_aUri.getLength() - 1 )
      97                 :            :         {
      98                 :            :             // ignore trailing slash
      99                 :        105 :             bTrailingSlash = true;
     100                 :        105 :             nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
     101                 :            :         }
     102                 :            : 
     103         [ +  + ]:        837 :         if ( nLastSlash != -1 ) // -1 is valid for the root folder
     104                 :            :         {
     105                 :        732 :             m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
     106                 :            : 
     107         [ -  + ]:        732 :             if ( bTrailingSlash )
     108                 :            :                 m_aName = m_aUri.copy( nLastSlash + 1,
     109                 :          0 :                                        m_aUri.getLength() - nLastSlash - 2 );
     110                 :            :             else
     111                 :        732 :                 m_aName = m_aUri.copy( nLastSlash + 1 );
     112                 :            : 
     113                 :        732 :             m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
     114                 :            : 
     115                 :        732 :             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
     116         [ +  - ]:        732 :             if ( nSlash == -1 )
     117                 :        732 :                 m_aDocId = m_aPath.copy( 1 );
     118                 :            :             else
     119                 :          0 :                 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
     120                 :            :         }
     121                 :            : 
     122         [ +  + ]:        837 :         if ( !m_aDocId.isEmpty() )
     123                 :            :         {
     124                 :        732 :             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
     125         [ -  + ]:        732 :             if ( nSlash != - 1 )
     126                 :          0 :                 m_aInternalPath = m_aPath.copy( nSlash );
     127                 :            :             else
     128                 :        732 :                 m_aInternalPath = rtl::OUString("/");
     129                 :            :         }
     130                 :            : 
     131         [ +  - ]:       1518 :         m_eState = VALID;
     132                 :            :     }
     133                 :            : }
     134                 :            : 
     135                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10