LCOV - code coverage report
Current view: top level - ucb/source/ucp/tdoc - tdoc_uri.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 36 77.8 %
Date: 2015-06-13 12:38:46 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        4777 : void Uri::init() const
      43             : {
      44             :     // Already inited?
      45        4777 :     if ( m_eState == UNKNOWN )
      46             :     {
      47        2638 :         m_eState = INVALID;
      48             : 
      49             :         // Check for proper length: must be at least length of <sheme>:/
      50        2638 :         if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
      51             :         {
      52             :             // Invalid length (to short).
      53           0 :             return;
      54             :         }
      55             : 
      56             :         // Check for proper scheme. (Scheme is case insensitive.)
      57             :         OUString aScheme
      58        2638 :             = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
      59        2638 :         if ( aScheme != TDOC_URL_SCHEME )
      60             :         {
      61             :             // Invalid scheme.
      62           0 :             return;
      63             :         }
      64             : 
      65             :         // Remember normalized scheme string.
      66        2638 :         m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
      67             : 
      68        2638 :         if ( m_aUri[ TDOC_URL_SCHEME_LENGTH ] != ':' )
      69             :         {
      70             :             // Invalid (no ':' after <scheme>).
      71           0 :             return;
      72             :         }
      73             : 
      74        2638 :         if ( m_aUri[ TDOC_URL_SCHEME_LENGTH + 1 ] != '/' )
      75             :         {
      76             :             // Invalid (no '/' after <scheme>:).
      77           0 :             return;
      78             :         }
      79             : 
      80        2638 :         m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
      81             : 
      82             :         // Note: There must be at least one slash; see above.
      83        2638 :         sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
      84        2638 :         bool bTrailingSlash = false;
      85        2638 :         if ( nLastSlash == m_aUri.getLength() - 1 )
      86             :         {
      87             :             // ignore trailing slash
      88         328 :             bTrailingSlash = true;
      89         328 :             nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
      90             :         }
      91             : 
      92        2638 :         if ( nLastSlash != -1 ) // -1 is valid for the root folder
      93             :         {
      94        2310 :             m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
      95             : 
      96        2310 :             if ( bTrailingSlash )
      97           0 :                 m_aName = m_aUri.copy( nLastSlash + 1,
      98           0 :                                        m_aUri.getLength() - nLastSlash - 2 );
      99             :             else
     100        2310 :                 m_aName = m_aUri.copy( nLastSlash + 1 );
     101             : 
     102        2310 :             m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
     103             : 
     104        2310 :             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
     105        2310 :             if ( nSlash == -1 )
     106        2310 :                 m_aDocId = m_aPath.copy( 1 );
     107             :             else
     108           0 :                 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
     109             :         }
     110             : 
     111        2638 :         if ( !m_aDocId.isEmpty() )
     112             :         {
     113        2310 :             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
     114        2310 :             if ( nSlash != - 1 )
     115           0 :                 m_aInternalPath = m_aPath.copy( nSlash );
     116             :             else
     117        2310 :                 m_aInternalPath = "/";
     118             :         }
     119             : 
     120        2638 :         m_eState = VALID;
     121             :     }
     122             : }
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11