LibreOffice Module stoc (master) 1
UriReference.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <cassert>
23
24#include "UriReference.hxx"
25
26#include <rtl/ustrbuf.hxx>
27#include <rtl/ustring.hxx>
28#include <utility>
29#include <sal/types.h>
30
32
33UriReference::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)
44{
45 assert(authority.isEmpty() || bHasAuthority);
46 assert(query.isEmpty() || bHasQuery);
47}
48
50
52{
53 std::lock_guard g(m_mutex);
54 OUStringBuffer buf(128);
55 if (!m_scheme.isEmpty()) {
56 buf.append(m_scheme + ":");
57 }
59 if (m_hasFragment) {
60 buf.append("#" + m_fragment);
61 }
62 return buf.makeStringAndClear();
63}
64
66 return !m_scheme.isEmpty();
67}
68
69
71{
72 std::lock_guard g(m_mutex);
73 OUStringBuffer buf;
75 return buf.makeStringAndClear();
76}
77
79 std::lock_guard g(m_mutex);
80 return m_scheme.isEmpty() || m_hasAuthority || m_path.startsWith("/");
81}
82
84 return m_hasAuthority;
85}
86
87const OUString& UriReference::getAuthority() const {
88 return m_authority;
89}
90
92 std::lock_guard g(m_mutex);
93 return m_path;
94}
95
97 std::lock_guard g(m_mutex);
98 return !m_hasAuthority
99 && (m_path.isEmpty() || m_path[0] != '/');
100}
101
103{
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;
113 }
114 ++n;
115 }
116 return n;
117 }
118}
119
120OUString UriReference::getPathSegment(sal_Int32 index)
121{
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);
128 }
129 i = m_path.indexOf('/', i);
130 if (i < 0) {
131 break;
132 }
133 }
134 }
135 return OUString();
136}
137
139 return m_hasQuery;
140}
141
142const OUString& UriReference::getQuery() const {
143 return m_query;
144}
145
147 std::lock_guard g(m_mutex);
148 return m_hasFragment;
149}
150
152 std::lock_guard g(m_mutex);
153 return m_fragment;
154}
155
156void UriReference::setFragment(OUString const & fragment)
157{
158 std::lock_guard g(m_mutex);
159 m_hasFragment = true;
161}
162
164 std::lock_guard g(m_mutex);
165 m_hasFragment = false;
166 m_fragment.clear();
167}
168
169void UriReference::appendSchemeSpecificPart(OUStringBuffer & buffer) const
170{
171 if (m_hasAuthority) {
172 buffer.append("//");
173 buffer.append(m_authority);
174 }
175 buffer.append(m_path);
176 if (m_hasQuery) {
177 buffer.append('?');
178 buffer.append(m_query);
179 }
180}
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & getAuthority() const
void setFragment(OUString const &fragment)
void appendSchemeSpecificPart(OUStringBuffer &buffer) const
OUString getPathSegment(sal_Int32 index)
const OUString & getQuery() const
sal_Int64 n
int i
index
int fragment
store_handle_type *SAL_CALL query(OStoreObject *pHandle, store_handle_type *)