tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / stoc / source / uriproc / UriReference.cxx
blobfc272014143ac33e1e91da4d9ecb22c94bc55b75
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <cassert>
24 #include "UriReference.hxx"
26 #include <rtl/ustrbuf.hxx>
27 #include <rtl/ustring.hxx>
28 #include <utility>
29 #include <sal/types.h>
31 using stoc::uriproc::UriReference;
33 UriReference::UriReference(
34 OUString scheme, bool bHasAuthority,
35 OUString const & authority, OUString path,
36 bool bHasQuery, OUString const & query):
37 m_path(std::move(path)),
38 m_scheme(std::move(scheme)),
39 m_authority(authority),
40 m_query(query),
41 m_hasAuthority(bHasAuthority),
42 m_hasQuery(bHasQuery),
43 m_hasFragment(false)
45 assert(authority.isEmpty() || bHasAuthority);
46 assert(query.isEmpty() || bHasQuery);
49 UriReference::~UriReference() {}
51 OUString UriReference::getUriReference()
53 std::lock_guard g(m_mutex);
54 OUStringBuffer buf(128);
55 if (!m_scheme.isEmpty()) {
56 buf.append(m_scheme + ":");
58 appendSchemeSpecificPart(buf);
59 if (m_hasFragment) {
60 buf.append("#" + m_fragment);
62 return buf.makeStringAndClear();
65 bool UriReference::isAbsolute() const {
66 return !m_scheme.isEmpty();
70 OUString UriReference::getSchemeSpecificPart()
72 std::lock_guard g(m_mutex);
73 OUStringBuffer buf;
74 appendSchemeSpecificPart(buf);
75 return buf.makeStringAndClear();
78 bool UriReference::isHierarchical() {
79 std::lock_guard g(m_mutex);
80 return m_scheme.isEmpty() || m_hasAuthority || m_path.startsWith("/");
83 bool UriReference::hasAuthority() const {
84 return m_hasAuthority;
87 const OUString& UriReference::getAuthority() const {
88 return m_authority;
91 OUString UriReference::getPath() {
92 std::lock_guard g(m_mutex);
93 return m_path;
96 bool UriReference::hasRelativePath() {
97 std::lock_guard g(m_mutex);
98 return !m_hasAuthority
99 && (m_path.isEmpty() || m_path[0] != '/');
102 sal_Int32 UriReference::getPathSegmentCount()
104 std::lock_guard g(m_mutex);
105 if (m_path.isEmpty()) {
106 return 0;
107 } else {
108 sal_Int32 n = m_path[0] == '/' ? 0 : 1;
109 for (sal_Int32 i = 0;; ++i) {
110 i = m_path.indexOf('/', i);
111 if (i < 0) {
112 break;
114 ++n;
116 return n;
120 OUString UriReference::getPathSegment(sal_Int32 index)
122 std::lock_guard g(m_mutex);
123 if (!m_path.isEmpty() && index >= 0) {
124 for (sal_Int32 i = m_path[0] == '/' ? 1 : 0;; ++i) {
125 if (index-- == 0) {
126 sal_Int32 j = m_path.indexOf('/', i);
127 return j < 0 ? m_path.copy(i) : m_path.copy(i, j - i);
129 i = m_path.indexOf('/', i);
130 if (i < 0) {
131 break;
135 return OUString();
138 bool UriReference::hasQuery() const {
139 return m_hasQuery;
142 const OUString& UriReference::getQuery() const {
143 return m_query;
146 bool UriReference::hasFragment() {
147 std::lock_guard g(m_mutex);
148 return m_hasFragment;
151 OUString UriReference::getFragment() {
152 std::lock_guard g(m_mutex);
153 return m_fragment;
156 void UriReference::setFragment(OUString const & fragment)
158 std::lock_guard g(m_mutex);
159 m_hasFragment = true;
160 m_fragment = fragment;
163 void UriReference::clearFragment() {
164 std::lock_guard g(m_mutex);
165 m_hasFragment = false;
166 m_fragment.clear();
169 void UriReference::appendSchemeSpecificPart(OUStringBuffer & buffer) const
171 if (m_hasAuthority) {
172 buffer.append("//");
173 buffer.append(m_authority);
175 buffer.append(m_path);
176 if (m_hasQuery) {
177 buffer.append('?');
178 buffer.append(m_query);
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */