LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/uriproc - UriReference.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 94 75.5 %
Date: 2012-12-27 Functions: 16 20 80.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             : #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        2726 : UriReference::UriReference(
      33             :     rtl::OUString const & scheme, bool bIsHierarchical, bool bHasAuthority,
      34             :     rtl::OUString const & authority, rtl::OUString const & path,
      35             :     bool bHasQuery, rtl::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        2726 :     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        2726 : }
      51             : 
      52        2726 : UriReference::~UriReference() {}
      53             : 
      54         704 : rtl::OUString UriReference::getUriReference() throw (css::uno::RuntimeException)
      55             : {
      56         704 :     osl::MutexGuard g(m_mutex);
      57         704 :     rtl::OUStringBuffer buf;
      58         704 :     if (!m_scheme.isEmpty()) {
      59         704 :         buf.append(m_scheme);
      60         704 :         buf.append(static_cast< sal_Unicode >(':'));
      61             :     }
      62         704 :     appendSchemeSpecificPart(buf);
      63         704 :     if (m_hasFragment) {
      64           0 :         buf.append(static_cast< sal_Unicode >('#'));
      65           0 :         buf.append(m_fragment);
      66             :     }
      67         704 :     return buf.makeStringAndClear();
      68             : }
      69             : 
      70        1122 : sal_Bool UriReference::isAbsolute() throw (css::uno::RuntimeException) {
      71        1122 :     return !m_scheme.isEmpty();
      72             : }
      73             : 
      74         561 : rtl::OUString UriReference::getScheme() throw (css::uno::RuntimeException) {
      75         561 :     return m_scheme;
      76             : }
      77             : 
      78           0 : rtl::OUString UriReference::getSchemeSpecificPart()
      79             :     throw (css::uno::RuntimeException)
      80             : {
      81           0 :     osl::MutexGuard g(m_mutex);
      82           0 :     rtl::OUStringBuffer buf;
      83           0 :     appendSchemeSpecificPart(buf);
      84           0 :     return buf.makeStringAndClear();
      85             : }
      86             : 
      87         561 : sal_Bool UriReference::isHierarchical() throw (css::uno::RuntimeException) {
      88         561 :     osl::MutexGuard g(m_mutex);
      89         561 :     return m_isHierarchical;
      90             : }
      91             : 
      92        1683 : sal_Bool UriReference::hasAuthority() throw (css::uno::RuntimeException) {
      93        1683 :     osl::MutexGuard g(m_mutex);
      94        1683 :     return m_hasAuthority;
      95             : }
      96             : 
      97         561 : rtl::OUString UriReference::getAuthority() throw (css::uno::RuntimeException) {
      98         561 :     osl::MutexGuard g(m_mutex);
      99         561 :     return m_authority;
     100             : }
     101             : 
     102        1665 : rtl::OUString UriReference::getPath() throw (css::uno::RuntimeException) {
     103        1665 :     osl::MutexGuard g(m_mutex);
     104        1665 :     return m_path;
     105             : }
     106             : 
     107         561 : sal_Bool UriReference::hasRelativePath() throw (css::uno::RuntimeException) {
     108         561 :     osl::MutexGuard g(m_mutex);
     109         561 :     return m_isHierarchical && !m_hasAuthority
     110        1122 :         && (m_path.isEmpty() || m_path[0] != '/');
     111             : }
     112             : 
     113        1140 : sal_Int32 UriReference::getPathSegmentCount() throw (css::uno::RuntimeException)
     114             : {
     115        1140 :     osl::MutexGuard g(m_mutex);
     116        1140 :     if (!m_isHierarchical || m_path.isEmpty()) {
     117           0 :         return 0;
     118             :     } else {
     119        1140 :         sal_Int32 n = m_path[0] == '/' ? 0 : 1;
     120        2591 :         for (sal_Int32 i = 0;; ++i) {
     121        2591 :             i = m_path.indexOf('/', i);
     122        2591 :             if (i < 0) {
     123        1140 :                 break;
     124             :             }
     125        1451 :             ++n;
     126             :         }
     127        1140 :         return n;
     128        1140 :     }
     129             : }
     130             : 
     131        2624 : rtl::OUString UriReference::getPathSegment(sal_Int32 index)
     132             :     throw (css::uno::RuntimeException)
     133             : {
     134        2624 :     osl::MutexGuard g(m_mutex);
     135        2624 :     if (m_isHierarchical && !m_path.isEmpty() && index >= 0) {
     136        4276 :         for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
     137        4276 :             if (index-- == 0) {
     138        2624 :                 sal_Int32 j = m_path.indexOf('/', i);
     139        2624 :                 return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
     140             :             }
     141        1652 :             i = m_path.indexOf('/', i);
     142        1652 :             if (i < 0) {
     143           0 :                 break;
     144             :             }
     145             :         }
     146             :     }
     147           0 :     return rtl::OUString();
     148             : }
     149             : 
     150         561 : sal_Bool UriReference::hasQuery() throw (css::uno::RuntimeException) {
     151         561 :     osl::MutexGuard g(m_mutex);
     152         561 :     return m_hasQuery;
     153             : }
     154             : 
     155           0 : rtl::OUString UriReference::getQuery() throw (css::uno::RuntimeException) {
     156           0 :     osl::MutexGuard g(m_mutex);
     157           0 :     return m_query;
     158             : }
     159             : 
     160         561 : sal_Bool UriReference::hasFragment() throw (css::uno::RuntimeException) {
     161         561 :     osl::MutexGuard g(m_mutex);
     162         561 :     return m_hasFragment;
     163             : }
     164             : 
     165           0 : rtl::OUString UriReference::getFragment() throw (css::uno::RuntimeException) {
     166           0 :     osl::MutexGuard g(m_mutex);
     167           0 :     return m_fragment;
     168             : }
     169             : 
     170           0 : void UriReference::setFragment(rtl::OUString const & fragment)
     171             :     throw (css::uno::RuntimeException)
     172             : {
     173           0 :     osl::MutexGuard g(m_mutex);
     174           0 :     m_hasFragment = true;
     175           0 :     m_fragment = fragment;
     176           0 : }
     177             : 
     178         686 : void UriReference::clearFragment() throw (css::uno::RuntimeException) {
     179         686 :     osl::MutexGuard g(m_mutex);
     180         686 :     m_hasFragment = false;
     181         686 :     m_fragment = rtl::OUString();
     182         686 : }
     183             : 
     184         704 : void UriReference::appendSchemeSpecificPart(rtl::OUStringBuffer & buffer) const
     185             : {
     186         704 :     if (m_hasAuthority) {
     187         704 :         buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("//"));
     188         704 :         buffer.append(m_authority);
     189             :     }
     190         704 :     buffer.append(m_path);
     191         704 :     if (m_hasQuery) {
     192           0 :         buffer.append(static_cast< sal_Unicode >('?'));
     193           0 :         buffer.append(m_query);
     194             :     }
     195         704 : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10