LCOV - code coverage report
Current view: top level - stoc/source/uriproc - UriReference.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 86 94 91.5 %
Date: 2015-06-13 12:38:46 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      202138 : 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      202138 :     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      202138 : }
      51             : 
      52      202138 : UriReference::~UriReference() {}
      53             : 
      54        7966 : OUString UriReference::getUriReference() throw (css::uno::RuntimeException)
      55             : {
      56        7966 :     osl::MutexGuard g(m_mutex);
      57       15932 :     OUStringBuffer buf;
      58        7966 :     if (!m_scheme.isEmpty()) {
      59        7926 :         buf.append(m_scheme);
      60        7926 :         buf.append(':');
      61             :     }
      62        7966 :     appendSchemeSpecificPart(buf);
      63        7966 :     if (m_hasFragment) {
      64           6 :         buf.append('#');
      65           6 :         buf.append(m_fragment);
      66             :     }
      67       15932 :     return buf.makeStringAndClear();
      68             : }
      69             : 
      70       40584 : bool UriReference::isAbsolute() throw (css::uno::RuntimeException) {
      71       40584 :     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       20308 : bool UriReference::isHierarchical() throw (css::uno::RuntimeException) {
      85       20308 :     osl::MutexGuard g(m_mutex);
      86       20308 :     return m_isHierarchical;
      87             : }
      88             : 
      89       60614 : bool UriReference::hasAuthority() throw (css::uno::RuntimeException) {
      90       60614 :     osl::MutexGuard g(m_mutex);
      91       60614 :     return m_hasAuthority;
      92             : }
      93             : 
      94       20250 : OUString UriReference::getAuthority() throw (css::uno::RuntimeException) {
      95       20250 :     osl::MutexGuard g(m_mutex);
      96       20250 :     return m_authority;
      97             : }
      98             : 
      99      116337 : OUString UriReference::getPath() throw (css::uno::RuntimeException) {
     100      116337 :     osl::MutexGuard g(m_mutex);
     101      116337 :     return m_path;
     102             : }
     103             : 
     104       20194 : bool UriReference::hasRelativePath() throw (css::uno::RuntimeException) {
     105       20194 :     osl::MutexGuard g(m_mutex);
     106       20194 :     return m_isHierarchical && !m_hasAuthority
     107       40388 :         && (m_path.isEmpty() || m_path[0] != '/');
     108             : }
     109             : 
     110       40886 : sal_Int32 UriReference::getPathSegmentCount() throw (css::uno::RuntimeException)
     111             : {
     112       40886 :     osl::MutexGuard g(m_mutex);
     113       40886 :     if (!m_isHierarchical || m_path.isEmpty()) {
     114           0 :         return 0;
     115             :     } else {
     116       40886 :         sal_Int32 n = m_path[0] == '/' ? 0 : 1;
     117       99914 :         for (sal_Int32 i = 0;; ++i) {
     118       99914 :             i = m_path.indexOf('/', i);
     119       99914 :             if (i < 0) {
     120       40886 :                 break;
     121             :             }
     122       59028 :             ++n;
     123       59028 :         }
     124       40886 :         return n;
     125       40886 :     }
     126             : }
     127             : 
     128      106712 : OUString UriReference::getPathSegment(sal_Int32 index)
     129             :     throw (css::uno::RuntimeException)
     130             : {
     131      106712 :     osl::MutexGuard g(m_mutex);
     132      106712 :     if (m_isHierarchical && !m_path.isEmpty() && index >= 0) {
     133      178514 :         for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
     134      178514 :             if (index-- == 0) {
     135      106712 :                 sal_Int32 j = m_path.indexOf('/', i);
     136      106712 :                 return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
     137             :             }
     138       71802 :             i = m_path.indexOf('/', i);
     139       71802 :             if (i < 0) {
     140           0 :                 break;
     141             :             }
     142       71802 :         }
     143             :     }
     144           0 :     return OUString();
     145             : }
     146             : 
     147       20225 : bool UriReference::hasQuery() throw (css::uno::RuntimeException) {
     148       20225 :     osl::MutexGuard g(m_mutex);
     149       20225 :     return m_hasQuery;
     150             : }
     151             : 
     152           8 : OUString UriReference::getQuery() throw (css::uno::RuntimeException) {
     153           8 :     osl::MutexGuard g(m_mutex);
     154           8 :     return m_query;
     155             : }
     156             : 
     157       20222 : bool UriReference::hasFragment() throw (css::uno::RuntimeException) {
     158       20222 :     osl::MutexGuard g(m_mutex);
     159       20222 :     return m_hasFragment;
     160             : }
     161             : 
     162           5 : OUString UriReference::getFragment() throw (css::uno::RuntimeException) {
     163           5 :     osl::MutexGuard g(m_mutex);
     164           5 :     return m_fragment;
     165             : }
     166             : 
     167          12 : void UriReference::setFragment(OUString const & fragment)
     168             :     throw (css::uno::RuntimeException)
     169             : {
     170          12 :     osl::MutexGuard g(m_mutex);
     171          12 :     m_hasFragment = true;
     172          12 :     m_fragment = fragment;
     173          12 : }
     174             : 
     175        7438 : void UriReference::clearFragment() throw (css::uno::RuntimeException) {
     176        7438 :     osl::MutexGuard g(m_mutex);
     177        7438 :     m_hasFragment = false;
     178        7438 :     m_fragment.clear();
     179        7438 : }
     180             : 
     181        7966 : void UriReference::appendSchemeSpecificPart(OUStringBuffer & buffer) const
     182             : {
     183        7966 :     if (m_hasAuthority) {
     184        7894 :         buffer.append("//");
     185        7894 :         buffer.append(m_authority);
     186             :     }
     187        7966 :     buffer.append(m_path);
     188        7966 :     if (m_hasQuery) {
     189           4 :         buffer.append('?');
     190           4 :         buffer.append(m_query);
     191             :     }
     192        7966 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11