17 #ifndef COM_BORA_SOFTWARE__BALAU_RESOURCE__URI_COMPONENTS 18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__URI_COMPONENTS 64 public:
const std::string &
getUri()
const {
124 return hostOffset != -1;
133 return userinfoOffset != -1;
142 return hostOffset != -1;
151 return portOffset != -1;
160 return queryOffset != -1;
169 return fragmentOffset != -1;
177 public: std::string_view
scheme()
const {
178 return std::string_view(uri.c_str(), (size_t) schemeEndOffset);
190 return std::string_view();
193 const int endOffset = hostOffset - 1;
195 return std::string_view(uri.c_str() + userinfoOffset, (size_t) (endOffset - userinfoOffset));
205 public: std::string_view
host()
const {
207 return std::string_view();
210 const int endOffset =
hasPort()
215 return std::string_view(uri.c_str() + hostOffset, (size_t) (endOffset - hostOffset));
223 public:
unsigned short port()
const {
234 public: std::string_view
path()
const {
239 : (int) uri.length();
242 return std::string_view(uri.c_str() + pathOffset, (size_t) (endOffset - pathOffset));
252 public: std::string_view
query()
const {
254 return std::string_view();
259 : (int) uri.length();
262 return std::string_view(uri.c_str() + queryOffset, (size_t) (endOffset - queryOffset));
274 return std::string_view();
277 return std::string_view(uri.c_str() + fragmentOffset, (size_t) (uri.length() - fragmentOffset));
288 return std::string_view(uri.c_str() + pathOffset, (size_t) (uri.length() - pathOffset));
293 friend struct UriComponentsTest;
297 short schemeEndOffset_,
298 short userinfoOffset_,
303 short fragmentOffset_,
304 unsigned short parsedPort_)
305 : uri(std::move(uri_))
306 , schemeEndOffset(schemeEndOffset_)
307 , userinfoOffset(userinfoOffset_)
308 , hostOffset(hostOffset_)
309 , portOffset(portOffset_)
310 , pathOffset(pathOffset_)
311 , queryOffset(queryOffset_)
312 , fragmentOffset(fragmentOffset_)
313 , parsedPort(parsedPort_) {}
315 private: std::string uri;
316 private:
short schemeEndOffset;
317 private:
short userinfoOffset;
318 private:
short hostOffset;
319 private:
short portOffset;
320 private:
short pathOffset;
321 private:
short queryOffset;
322 private:
short fragmentOffset;
323 private:
unsigned short parsedPort;
336 return lhs.uri == rhs.uri;
346 template <
typename AllocatorT>
348 return toString<AllocatorT>(uriComponents.
getUri());
359 return uriComponents.
getUri();
364 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__URI_COMPONENTS Pre-defined universal to-string functions.
friend bool operator==(const UriComponents &lhs, const UriComponents &rhs)
Returns true if the two URI component instances are equal.
Definition: UriComponents.hpp:335
const std::string & getUri() const
Get the URI string contained within the URI component structure.
Definition: UriComponents.hpp:64
std::string_view fragment() const
Obtain a string view to the fragment.
Definition: UriComponents.hpp:272
unsigned short port() const
Obtain the port.
Definition: UriComponents.hpp:223
An abstract universal resource identifier.
Definition: Uri.hpp:131
UriComponents(const Uri &uri_)
Parse the URI into its components.
UriComponents & operator=(const UriComponents &)=default
Assign a URI components instance by copying the supplied instance.
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
std::string_view query() const
Obtain a string view to the query.
Definition: UriComponents.hpp:252
bool hasFragment() const
Returns true if the URI has a fragment.
Definition: UriComponents.hpp:168
std::string_view host() const
Obtain a string view to the host.
Definition: UriComponents.hpp:205
Balau::U8String< AllocatorT > toString(const File &file)
Print the file URI as a UTF-8 string.
Definition: File.hpp:724
static std::string normalizePath(std::string_view path)
Remove instances of "." and "blah/.." and remove any trailing slashes.
bool hasUserInfo() const
Returns true if the URI has user info.
Definition: UriComponents.hpp:132
bool hasAuthority() const
Returns true if the URI has an authority section.
Definition: UriComponents.hpp:123
bool hasHost() const
Returns true if the URI has a host entry.
Definition: UriComponents.hpp:141
std::string_view userInfo() const
Obtain a string view to the user info.
Definition: UriComponents.hpp:188
Assertion utilities for development purposes.
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
std::string_view pathQueryFragment() const
Obtain a string view to the path-query-fragment.
Definition: UriComponents.hpp:287
std::string_view scheme() const
Obtain a string view to the scheme.
Definition: UriComponents.hpp:177
bool hasQuery() const
Returns true if the URI has a query.
Definition: UriComponents.hpp:159
std::string_view path() const
Obtain a string view to the path.
Definition: UriComponents.hpp:234
bool hasPort() const
Returns true if the URI has port information.
Definition: UriComponents.hpp:150
static void assertion(bool test, StringFunctionT function)
If the bug test assertion fails, abort after logging the message supplied by the function.
Definition: Assert.hpp:49
Parses a URI and provides views into the URI's components.
Definition: UriComponents.hpp:52