DART  6.7.3
Uri.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_COMMON_URI_HPP_
34 #define DART_COMMON_URI_HPP_
35 
36 #include <string>
37 
38 namespace dart {
39 namespace common {
40 
41 class UriComponent final
42 {
43 public:
44  using value_type = std::string;
49 
50  UriComponent();
52 
53  operator bool() const;
54 
55  bool operator !() const;
56 
58 
61 
64 
65  void assign(reference_const_type _value);
66  void reset();
67 
69  reference_const_type get() const;
70 
73 
74 private:
75  bool mExists;
76  std::string mValue;
77 };
78 
86 struct Uri final
87 {
90 
93 
96 
99 
102 
104  Uri() = default;
105 
112  Uri(const std::string& _input);
113 
116  Uri(const char* _input);
117 
119  void clear();
120 
123  bool fromString(const std::string& _input);
124 
128  bool fromPath(const std::string& _path);
129 
133  bool fromStringOrPath(const std::string& _input);
134 
137  bool fromRelativeUri(const std::string& _base, const std::string& _relative,
138  bool _strict = false);
139 
142  bool fromRelativeUri(const char* _base, const char* _relative,
143  bool _strict = false);
144 
147  bool fromRelativeUri(const Uri& _base, const std::string& _relative,
148  bool _strict = false);
149 
152  bool fromRelativeUri(const Uri& _base, const char* _relative,
153  bool _strict = false);
154 
157  bool fromRelativeUri(const Uri& _base, const Uri& _relative,
158  bool _strict = false);
159 
161  std::string toString() const;
162 
164  static Uri createFromString(const std::string& _input);
165 
167  static Uri createFromPath(const std::string& _path);
168 
171  static Uri createFromStringOrPath(const std::string& _input);
172 
175  static Uri createFromRelativeUri(const std::string& _base,
176  const std::string& _relative,
177  bool _strict = false);
178 
181  static Uri createFromRelativeUri(const Uri& _base,
182  const std::string& _relative,
183  bool _strict = false);
184 
187  static Uri createFromRelativeUri(const Uri& _base,
188  const Uri& _relative,
189  bool _strict = false);
190 
192  static std::string getUri(const std::string& _input);
193 
195  static std::string getRelativeUri(const std::string& _base,
196  const std::string& _relative,
197  bool _strict = false);
198 
200  static std::string getRelativeUri(const Uri& _base,
201  const std::string& _relative,
202  bool _strict = false);
203 
205  static std::string getRelativeUri(const Uri& _base,
206  const Uri& _relative,
207  bool _strict = false);
208 
210  std::string getPath() const;
211 
216  std::string getFilesystemPath() const;
217 
218 private:
220  static std::string mergePaths(const Uri& _base, const Uri& _relative);
221 
223  static std::string removeDotSegments(const std::string& _path);
224 };
225 
226 } // namespace common
227 } // namespace dart
228 
229 #endif // ifndef DART_COMMON_URI_HPP_
Definition: Uri.hpp:42
reference_type get()
Definition: Uri.cpp:151
void reset()
Definition: Uri.cpp:145
value_type & reference_type
Definition: Uri.hpp:45
std::string mValue
Definition: Uri.hpp:76
const value_type & reference_const_type
Definition: Uri.hpp:46
reference_type get_value_or(reference_type _default)
Definition: Uri.cpp:165
value_type * pointer_type
Definition: Uri.hpp:47
pointer_type operator->()
Definition: Uri.cpp:126
bool mExists
Definition: Uri.hpp:75
UriComponent()
Definition: Uri.cpp:83
reference_type operator*()
Definition: Uri.cpp:114
bool operator!() const
Definition: Uri.cpp:101
const value_type * pointer_const_type
Definition: Uri.hpp:48
std::string value_type
Definition: Uri.hpp:44
UriComponent & operator=(reference_const_type _value)
Definition: Uri.cpp:107
void assign(reference_const_type _value)
Definition: Uri.cpp:138
Definition: BulletCollisionDetector.cpp:63
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87
static Uri createFromRelativeUri(const std::string &_base, const std::string &_relative, bool _strict=false)
Create URI resolving a relative path reference; return an empty URI on failure.
Definition: Uri.cpp:486
std::string getPath() const
Get the path component of the URI as a string.
Definition: Uri.cpp:581
UriComponent mFragment
Fragment, e.g. the part of the URI after the #.
Definition: Uri.hpp:101
static Uri createFromString(const std::string &_input)
Create URI from a string; return an empty URI on failure.
Definition: Uri.cpp:438
std::string toString() const
Combine the parts of the URI into a string.
Definition: Uri.cpp:415
bool fromStringOrPath(const std::string &_input)
Parse a URI or local path (i.e.
Definition: Uri.cpp:284
UriComponent mAuthority
Authority, e.g. 'google.com', 'en.wikipedia.org'.
Definition: Uri.hpp:92
void clear()
Clear the URI by reset()ing all components.
Definition: Uri.cpp:209
static std::string getUri(const std::string &_input)
Parse a URI from a string; return an empty string on failure.
Definition: Uri.cpp:538
bool fromRelativeUri(const std::string &_base, const std::string &_relative, bool _strict=false)
Resolve a relative path reference; return success.
Definition: Uri.cpp:313
bool fromString(const std::string &_input)
Parse a URI from a string; return success.
Definition: Uri.cpp:219
static Uri createFromStringOrPath(const std::string &_input)
Create general URI or file URI from a string; return an empty URI on failure.
Definition: Uri.cpp:470
bool fromPath(const std::string &_path)
Parse a local path (i.e.
Definition: Uri.cpp:266
static std::string removeDotSegments(const std::string &_path)
Implement section 5.2.4 of RFC 3986.
Definition: Uri.cpp:622
UriComponent mPath
Path, e.g. '/index.html', '/foo/bar.txt'.
Definition: Uri.hpp:95
static std::string getRelativeUri(const std::string &_base, const std::string &_relative, bool _strict=false)
Resolve a relative path reference; return an empty string on failure.
Definition: Uri.cpp:548
Uri()=default
Constructor.
UriComponent mQuery
Query string, i.e. the part of the URI after the ?
Definition: Uri.hpp:98
static std::string mergePaths(const Uri &_base, const Uri &_relative)
Implement section 5.2.3 of RFC 3986.
Definition: Uri.cpp:603
std::string getFilesystemPath() const
Get the path in the local filesystem as a string.
Definition: Uri.cpp:587
UriComponent mScheme
Scheme, e.g. 'http', 'file', 'package'.
Definition: Uri.hpp:89
static Uri createFromPath(const std::string &_path)
Create file URI from a string; return an empty URI on failure.
Definition: Uri.cpp:454