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

Generated by: LCOV version 1.10