LCOV - code coverage report
Current view: top level - stoc/source/uriproc - UriReference.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 86 94 91.5 %
Date: 2014-11-03 Functions: 18 19 94.7 %
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             : #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             : using stoc::uriproc::UriReference;
      31             : 
      32      164191 : UriReference::UriReference(
      33             :     OUString const & scheme, bool bIsHierarchical, bool bHasAuthority,
      34             :     OUString const & authority, OUString const & path,
      35             :     bool bHasQuery, OUString const & query):
      36             :     m_scheme(scheme),
      37             :     m_authority(authority),
      38             :     m_path(path),
      39             :     m_query(query),
      40             :     m_isHierarchical(bIsHierarchical),
      41             :     m_hasAuthority(bHasAuthority),
      42             :     m_hasQuery(bHasQuery),
      43      164191 :     m_hasFragment(false)
      44             : {
      45             :     OSL_ASSERT(!scheme.isEmpty() || bIsHierarchical);
      46             :     OSL_ASSERT(!bHasAuthority || bIsHierarchical);
      47             :     OSL_ASSERT(authority.isEmpty() || bHasAuthority);
      48             :     OSL_ASSERT(!bHasQuery || bIsHierarchical);
      49             :     OSL_ASSERT(query.isEmpty() || bHasQuery);
      50      164191 : }
      51             : 
      52      164191 : UriReference::~UriReference() {}
      53             : 
      54       11835 : OUString UriReference::getUriReference() throw (css::uno::RuntimeException)
      55             : {
      56       11835 :     osl::MutexGuard g(m_mutex);
      57       23670 :     OUStringBuffer buf;
      58       11835 :     if (!m_scheme.isEmpty()) {
      59       11769 :         buf.append(m_scheme);
      60       11769 :         buf.append(':');
      61             :     }
      62       11835 :     appendSchemeSpecificPart(buf);
      63       11835 :     if (m_hasFragment) {
      64           8 :         buf.append('#');
      65           8 :         buf.append(m_fragment);
      66             :     }
      67       23670 :     return buf.makeStringAndClear();
      68             : }
      69             : 
      70       76472 : bool UriReference::isAbsolute() throw (css::uno::RuntimeException) {
      71       76472 :     return !m_scheme.isEmpty();
      72             : }
      73             : 
      74             : 
      75           0 : OUString UriReference::getSchemeSpecificPart()
      76             :     throw (css::uno::RuntimeException)
      77             : {
      78           0 :     osl::MutexGuard g(m_mutex);
      79           0 :     OUStringBuffer buf;
      80           0 :     appendSchemeSpecificPart(buf);
      81           0 :     return buf.makeStringAndClear();
      82             : }
      83             : 
      84       38260 : bool UriReference::isHierarchical() throw (css::uno::RuntimeException) {
      85       38260 :     osl::MutexGuard g(m_mutex);
      86       38260 :     return m_isHierarchical;
      87             : }
      88             : 
      89      114218 : bool UriReference::hasAuthority() throw (css::uno::RuntimeException) {
      90      114218 :     osl::MutexGuard g(m_mutex);
      91      114218 :     return m_hasAuthority;
      92             : }
      93             : 
      94       38150 : OUString UriReference::getAuthority() throw (css::uno::RuntimeException) {
      95       38150 :     osl::MutexGuard g(m_mutex);
      96       38150 :     return m_authority;
      97             : }
      98             : 
      99      113842 : OUString UriReference::getPath() throw (css::uno::RuntimeException) {
     100      113842 :     osl::MutexGuard g(m_mutex);
     101      113842 :     return m_path;
     102             : }
     103             : 
     104       38058 : bool UriReference::hasRelativePath() throw (css::uno::RuntimeException) {
     105       38058 :     osl::MutexGuard g(m_mutex);
     106       38058 :     return m_isHierarchical && !m_hasAuthority
     107       76116 :         && (m_path.isEmpty() || m_path[0] != '/');
     108             : }
     109             : 
     110       76770 : sal_Int32 UriReference::getPathSegmentCount() throw (css::uno::RuntimeException)
     111             : {
     112       76770 :     osl::MutexGuard g(m_mutex);
     113       76770 :     if (!m_isHierarchical || m_path.isEmpty()) {
     114           0 :         return 0;
     115             :     } else {
     116       76770 :         sal_Int32 n = m_path[0] == '/' ? 0 : 1;
     117      182886 :         for (sal_Int32 i = 0;; ++i) {
     118      182886 :             i = m_path.indexOf('/', i);
     119      182886 :             if (i < 0) {
     120       76770 :                 break;
     121             :             }
     122      106116 :             ++n;
     123      106116 :         }
     124       76770 :         return n;
     125       76770 :     }
     126             : }
     127             : 
     128      196602 : OUString UriReference::getPathSegment(sal_Int32 index)
     129             :     throw (css::uno::RuntimeException)
     130             : {
     131      196602 :     osl::MutexGuard g(m_mutex);
     132      196602 :     if (m_isHierarchical && !m_path.isEmpty() && index >= 0) {
     133      299536 :         for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
     134      299536 :             if (index-- == 0) {
     135      196602 :                 sal_Int32 j = m_path.indexOf('/', i);
     136      196602 :                 return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
     137             :             }
     138      102934 :             i = m_path.indexOf('/', i);
     139      102934 :             if (i < 0) {
     140           0 :                 break;
     141             :             }
     142      102934 :         }
     143             :     }
     144           0 :     return OUString();
     145             : }
     146             : 
     147       38108 : bool UriReference::hasQuery() throw (css::uno::RuntimeException) {
     148       38108 :     osl::MutexGuard g(m_mutex);
     149       38108 :     return m_hasQuery;
     150             : }
     151             : 
     152          12 : OUString UriReference::getQuery() throw (css::uno::RuntimeException) {
     153          12 :     osl::MutexGuard g(m_mutex);
     154          12 :     return m_query;
     155             : }
     156             : 
     157       38104 : bool UriReference::hasFragment() throw (css::uno::RuntimeException) {
     158       38104 :     osl::MutexGuard g(m_mutex);
     159       38104 :     return m_hasFragment;
     160             : }
     161             : 
     162          10 : OUString UriReference::getFragment() throw (css::uno::RuntimeException) {
     163          10 :     osl::MutexGuard g(m_mutex);
     164          10 :     return m_fragment;
     165             : }
     166             : 
     167          20 : void UriReference::setFragment(OUString const & fragment)
     168             :     throw (css::uno::RuntimeException)
     169             : {
     170          20 :     osl::MutexGuard g(m_mutex);
     171          20 :     m_hasFragment = true;
     172          20 :     m_fragment = fragment;
     173          20 : }
     174             : 
     175       11123 : void UriReference::clearFragment() throw (css::uno::RuntimeException) {
     176       11123 :     osl::MutexGuard g(m_mutex);
     177       11123 :     m_hasFragment = false;
     178       11123 :     m_fragment = OUString();
     179       11123 : }
     180             : 
     181       11835 : void UriReference::appendSchemeSpecificPart(OUStringBuffer & buffer) const
     182             : {
     183       11835 :     if (m_hasAuthority) {
     184       11705 :         buffer.append("//");
     185       11705 :         buffer.append(m_authority);
     186             :     }
     187       11835 :     buffer.append(m_path);
     188       11835 :     if (m_hasQuery) {
     189           4 :         buffer.append('?');
     190           4 :         buffer.append(m_query);
     191             :     }
     192       11835 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10