LCOV - code coverage report
Current view: top level - stoc/source/uriproc - UriReference.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 94 92.6 %
Date: 2012-08-25 Functions: 19 20 95.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 63 116 54.3 %

           Branch data     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                 :            : #include "UriReference.hxx"
      22                 :            : 
      23                 :            : #include "osl/diagnose.h"
      24                 :            : #include "osl/mutex.hxx"
      25                 :            : #include "rtl/string.h"
      26                 :            : #include "rtl/ustrbuf.hxx"
      27                 :            : #include "rtl/ustring.hxx"
      28                 :            : #include "sal/types.h"
      29                 :            : 
      30                 :            : namespace css = com::sun::star;
      31                 :            : using stoc::uriproc::UriReference;
      32                 :            : 
      33                 :       9043 : UriReference::UriReference(
      34                 :            :     rtl::OUString const & scheme, bool bIsHierarchical, bool bHasAuthority,
      35                 :            :     rtl::OUString const & authority, rtl::OUString const & path,
      36                 :            :     bool bHasQuery, rtl::OUString const & query):
      37                 :            :     m_scheme(scheme),
      38                 :            :     m_authority(authority),
      39                 :            :     m_path(path),
      40                 :            :     m_query(query),
      41                 :            :     m_isHierarchical(bIsHierarchical),
      42                 :            :     m_hasAuthority(bHasAuthority),
      43                 :            :     m_hasQuery(bHasQuery),
      44                 :       9043 :     m_hasFragment(false)
      45                 :            : {
      46                 :            :     OSL_ASSERT(!scheme.isEmpty() || bIsHierarchical);
      47                 :            :     OSL_ASSERT(!bHasAuthority || bIsHierarchical);
      48                 :            :     OSL_ASSERT(authority.isEmpty() || bHasAuthority);
      49                 :            :     OSL_ASSERT(!bHasQuery || bIsHierarchical);
      50                 :            :     OSL_ASSERT(query.isEmpty() || bHasQuery);
      51                 :       9043 : }
      52                 :            : 
      53                 :       9043 : UriReference::~UriReference() {}
      54                 :            : 
      55                 :       3306 : rtl::OUString UriReference::getUriReference() throw (css::uno::RuntimeException)
      56                 :            : {
      57         [ +  - ]:       3306 :     osl::MutexGuard g(m_mutex);
      58                 :       3306 :     rtl::OUStringBuffer buf;
      59         [ +  + ]:       3306 :     if (!m_scheme.isEmpty()) {
      60         [ +  - ]:       3280 :         buf.append(m_scheme);
      61         [ +  - ]:       3280 :         buf.append(static_cast< sal_Unicode >(':'));
      62                 :            :     }
      63         [ +  - ]:       3306 :     appendSchemeSpecificPart(buf);
      64         [ +  + ]:       3306 :     if (m_hasFragment) {
      65         [ +  - ]:          8 :         buf.append(static_cast< sal_Unicode >('#'));
      66         [ +  - ]:          8 :         buf.append(m_fragment);
      67                 :            :     }
      68 [ +  - ][ +  - ]:       3306 :     return buf.makeStringAndClear();
      69                 :            : }
      70                 :            : 
      71                 :       3392 : sal_Bool UriReference::isAbsolute() throw (css::uno::RuntimeException) {
      72                 :       3392 :     return !m_scheme.isEmpty();
      73                 :            : }
      74                 :            : 
      75                 :       1785 : rtl::OUString UriReference::getScheme() throw (css::uno::RuntimeException) {
      76                 :       1785 :     return m_scheme;
      77                 :            : }
      78                 :            : 
      79                 :          0 : rtl::OUString UriReference::getSchemeSpecificPart()
      80                 :            :     throw (css::uno::RuntimeException)
      81                 :            : {
      82         [ #  # ]:          0 :     osl::MutexGuard g(m_mutex);
      83                 :          0 :     rtl::OUStringBuffer buf;
      84         [ #  # ]:          0 :     appendSchemeSpecificPart(buf);
      85 [ #  # ][ #  # ]:          0 :     return buf.makeStringAndClear();
      86                 :            : }
      87                 :            : 
      88                 :       1673 : sal_Bool UriReference::isHierarchical() throw (css::uno::RuntimeException) {
      89         [ +  - ]:       1673 :     osl::MutexGuard g(m_mutex);
      90         [ +  - ]:       1673 :     return m_isHierarchical;
      91                 :            : }
      92                 :            : 
      93                 :       4677 : sal_Bool UriReference::hasAuthority() throw (css::uno::RuntimeException) {
      94         [ +  - ]:       4677 :     osl::MutexGuard g(m_mutex);
      95         [ +  - ]:       4677 :     return m_hasAuthority;
      96                 :            : }
      97                 :            : 
      98                 :       1583 : rtl::OUString UriReference::getAuthority() throw (css::uno::RuntimeException) {
      99         [ +  - ]:       1583 :     osl::MutexGuard g(m_mutex);
     100         [ +  - ]:       1583 :     return m_authority;
     101                 :            : }
     102                 :            : 
     103                 :       4604 : rtl::OUString UriReference::getPath() throw (css::uno::RuntimeException) {
     104         [ +  - ]:       4604 :     osl::MutexGuard g(m_mutex);
     105         [ +  - ]:       4604 :     return m_path;
     106                 :            : }
     107                 :            : 
     108                 :       1571 : sal_Bool UriReference::hasRelativePath() throw (css::uno::RuntimeException) {
     109         [ +  - ]:       1571 :     osl::MutexGuard g(m_mutex);
     110                 :       1571 :     return m_isHierarchical && !m_hasAuthority
     111 [ +  - ][ +  - ]:       1571 :         && (m_path.isEmpty() || m_path[0] != '/');
         [ +  - ][ +  + ]
                 [ +  - ]
     112                 :            : }
     113                 :            : 
     114                 :       3245 : sal_Int32 UriReference::getPathSegmentCount() throw (css::uno::RuntimeException)
     115                 :            : {
     116         [ +  - ]:       3245 :     osl::MutexGuard g(m_mutex);
     117 [ +  - ][ -  + ]:       3245 :     if (!m_isHierarchical || m_path.isEmpty()) {
                 [ -  + ]
     118                 :          0 :         return 0;
     119                 :            :     } else {
     120                 :       3245 :         sal_Int32 n = m_path[0] == '/' ? 0 : 1;
     121                 :       8345 :         for (sal_Int32 i = 0;; ++i) {
     122                 :       8345 :             i = m_path.indexOf('/', i);
     123         [ +  + ]:       8345 :             if (i < 0) {
     124                 :       3245 :                 break;
     125                 :            :             }
     126                 :       5100 :             ++n;
     127                 :            :         }
     128                 :       3245 :         return n;
     129         [ +  - ]:       3245 :     }
     130                 :            : }
     131                 :            : 
     132                 :       8275 : rtl::OUString UriReference::getPathSegment(sal_Int32 index)
     133                 :            :     throw (css::uno::RuntimeException)
     134                 :            : {
     135         [ +  - ]:       8275 :     osl::MutexGuard g(m_mutex);
     136 [ +  - ][ +  - ]:       8275 :     if (m_isHierarchical && !m_path.isEmpty() && index >= 0) {
         [ +  - ][ +  - ]
     137         [ +  + ]:      17492 :         for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
     138         [ +  + ]:      17492 :             if (index-- == 0) {
     139                 :       8275 :                 sal_Int32 j = m_path.indexOf('/', i);
     140         [ +  + ]:       8275 :                 return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
     141                 :            :             }
     142                 :       9217 :             i = m_path.indexOf('/', i);
     143         [ -  + ]:       9217 :             if (i < 0) {
     144                 :          0 :                 break;
     145                 :            :             }
     146                 :            :         }
     147                 :            :     }
     148         [ +  - ]:       8275 :     return rtl::OUString();
     149                 :            : }
     150                 :            : 
     151                 :       1577 : sal_Bool UriReference::hasQuery() throw (css::uno::RuntimeException) {
     152         [ +  - ]:       1577 :     osl::MutexGuard g(m_mutex);
     153         [ +  - ]:       1577 :     return m_hasQuery;
     154                 :            : }
     155                 :            : 
     156                 :          4 : rtl::OUString UriReference::getQuery() throw (css::uno::RuntimeException) {
     157         [ +  - ]:          4 :     osl::MutexGuard g(m_mutex);
     158         [ +  - ]:          4 :     return m_query;
     159                 :            : }
     160                 :            : 
     161                 :       1577 : sal_Bool UriReference::hasFragment() throw (css::uno::RuntimeException) {
     162         [ +  - ]:       1577 :     osl::MutexGuard g(m_mutex);
     163         [ +  - ]:       1577 :     return m_hasFragment;
     164                 :            : }
     165                 :            : 
     166                 :         10 : rtl::OUString UriReference::getFragment() throw (css::uno::RuntimeException) {
     167         [ +  - ]:         10 :     osl::MutexGuard g(m_mutex);
     168         [ +  - ]:         10 :     return m_fragment;
     169                 :            : }
     170                 :            : 
     171                 :         20 : void UriReference::setFragment(rtl::OUString const & fragment)
     172                 :            :     throw (css::uno::RuntimeException)
     173                 :            : {
     174         [ +  - ]:         20 :     osl::MutexGuard g(m_mutex);
     175                 :         20 :     m_hasFragment = true;
     176         [ +  - ]:         20 :     m_fragment = fragment;
     177                 :         20 : }
     178                 :            : 
     179                 :       3133 : void UriReference::clearFragment() throw (css::uno::RuntimeException) {
     180         [ +  - ]:       3133 :     osl::MutexGuard g(m_mutex);
     181                 :       3133 :     m_hasFragment = false;
     182         [ +  - ]:       3133 :     m_fragment = rtl::OUString();
     183                 :       3133 : }
     184                 :            : 
     185                 :       3306 : void UriReference::appendSchemeSpecificPart(rtl::OUStringBuffer & buffer) const
     186                 :            : {
     187         [ +  + ]:       3306 :     if (m_hasAuthority) {
     188                 :       3224 :         buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
     189                 :       3224 :         buffer.append(m_authority);
     190                 :            :     }
     191                 :       3306 :     buffer.append(m_path);
     192         [ +  + ]:       3306 :     if (m_hasQuery) {
     193                 :          4 :         buffer.append(static_cast< sal_Unicode >('?'));
     194                 :          4 :         buffer.append(m_query);
     195                 :            :     }
     196                 :       3306 : }
     197                 :            : 
     198                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10