DART  6.10.1
dart::common::Uri Struct Referencefinal

The Uri struct provides URI parsing and merging functionality based on RFC 3986. More...

#include <Uri.hpp>

Public Member Functions

 Uri ()=default
 Constructor. More...
 
 Uri (const std::string &_input)
 Constructor that takes a URI or local path. More...
 
 Uri (const char *_input)
 Constructor that takes a URI or local path as const char*. More...
 
void clear ()
 Clear the URI by reset()ing all components. More...
 
bool fromString (const std::string &_input)
 Parse a URI from a string; return success. More...
 
bool fromPath (const std::string &_path)
 Parse a local path (i.e. More...
 
bool fromStringOrPath (const std::string &_input)
 Parse a URI or local path (i.e. More...
 
bool fromRelativeUri (const std::string &_base, const std::string &_relative, bool _strict=false)
 Resolve a relative path reference; return success. More...
 
bool fromRelativeUri (const char *_base, const char *_relative, bool _strict=false)
 Resolve a relative path reference; return success. More...
 
bool fromRelativeUri (const Uri &_base, const std::string &_relative, bool _strict=false)
 Resolve a relative path reference; return success. More...
 
bool fromRelativeUri (const Uri &_base, const char *_relative, bool _strict=false)
 Resolve a relative path reference; return success. More...
 
bool fromRelativeUri (const Uri &_base, const Uri &_relative, bool _strict=false)
 Resolve a relative path reference; return success. More...
 
std::string toString () const
 Combine the parts of the URI into a string. More...
 
std::string getPath () const
 Get the path component of the URI as a string. More...
 
std::string getFilesystemPath () const
 Get the path in the local filesystem as a string. More...
 

Static Public Member Functions

static Uri createFromString (const std::string &_input)
 Create URI from a string; return an empty URI on failure. More...
 
static Uri createFromPath (const std::string &_path)
 Create file URI from a string; return an empty URI on failure. More...
 
static Uri createFromStringOrPath (const std::string &_input)
 Create general URI or file URI from a string; return an empty URI on failure. More...
 
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. More...
 
static Uri createFromRelativeUri (const Uri &_base, const std::string &_relative, bool _strict=false)
 Create URI resolving a relative path reference; return an empty URI on failure. More...
 
static Uri createFromRelativeUri (const Uri &_base, const Uri &_relative, bool _strict=false)
 Create URI resolving a relative path reference; return an empty URI on failure. More...
 
static std::string getUri (const std::string &_input)
 Parse a URI from a string; return an empty string on failure. More...
 
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. More...
 
static std::string getRelativeUri (const Uri &_base, const std::string &_relative, bool _strict=false)
 Resolve a relative path reference; return an empty string on failure. More...
 
static std::string getRelativeUri (const Uri &_base, const Uri &_relative, bool _strict=false)
 Resolve a relative path reference; return an empty string on failure. More...
 

Public Attributes

UriComponent mScheme
 Scheme, e.g. 'http', 'file', 'package'. More...
 
UriComponent mAuthority
 Authority, e.g. 'google.com', 'en.wikipedia.org'. More...
 
UriComponent mPath
 Path, e.g. '/index.html', '/foo/bar.txt'. More...
 
UriComponent mQuery
 Query string, i.e. the part of the URI after the ? More...
 
UriComponent mFragment
 Fragment, e.g. the part of the URI after the #. More...
 

Static Private Member Functions

static std::string mergePaths (const Uri &_base, const Uri &_relative)
 Implement section 5.2.3 of RFC 3986. More...
 
static std::string removeDotSegments (const std::string &_path)
 Implement section 5.2.4 of RFC 3986. More...
 

Detailed Description

The Uri struct provides URI parsing and merging functionality based on RFC 3986.

We have Uri as a struct rather than class to expose member variables. Many ResourceRetreiver classes rewrite URIs to other types of URIs (e.g, resolve 'package://' URIs to 'file://' URIs), which is easier to implement if you have direct access to the URI components.

Constructor & Destructor Documentation

◆ Uri() [1/3]

dart::common::Uri::Uri ( )
default

Constructor.

◆ Uri() [2/3]

dart::common::Uri::Uri ( const std::string &  _input)

Constructor that takes a URI or local path.

Internally, this is equivalent to calling fromStringOrPath(_input) after default constructor.

We don't declare this constructor as explicit in order to allow implicit conversion from string so that you can pass in string parameter to a function that takes Uri.

◆ Uri() [3/3]

dart::common::Uri::Uri ( const char *  _input)

Constructor that takes a URI or local path as const char*.

The behavior is identical to Uri(const std::string&).

Member Function Documentation

◆ clear()

void dart::common::Uri::clear ( )

Clear the URI by reset()ing all components.

◆ createFromPath()

Uri dart::common::Uri::createFromPath ( const std::string &  _path)
static

Create file URI from a string; return an empty URI on failure.

◆ createFromRelativeUri() [1/3]

Uri dart::common::Uri::createFromRelativeUri ( const std::string &  _base,
const std::string &  _relative,
bool  _strict = false 
)
static

Create URI resolving a relative path reference; return an empty URI on failure.

◆ createFromRelativeUri() [2/3]

Uri dart::common::Uri::createFromRelativeUri ( const Uri _base,
const std::string &  _relative,
bool  _strict = false 
)
static

Create URI resolving a relative path reference; return an empty URI on failure.

◆ createFromRelativeUri() [3/3]

Uri dart::common::Uri::createFromRelativeUri ( const Uri _base,
const Uri _relative,
bool  _strict = false 
)
static

Create URI resolving a relative path reference; return an empty URI on failure.

◆ createFromString()

Uri dart::common::Uri::createFromString ( const std::string &  _input)
static

Create URI from a string; return an empty URI on failure.

◆ createFromStringOrPath()

Uri dart::common::Uri::createFromStringOrPath ( const std::string &  _input)
static

Create general URI or file URI from a string; return an empty URI on failure.

◆ fromPath()

bool dart::common::Uri::fromPath ( const std::string &  _path)

Parse a local path (i.e.

URI with no schema) from a string; return success. Note that the input path should be absolute path. All the components will be cleared on failure.

◆ fromRelativeUri() [1/5]

bool dart::common::Uri::fromRelativeUri ( const char *  _base,
const char *  _relative,
bool  _strict = false 
)

Resolve a relative path reference; return success.

All the components will be cleared on failure.

◆ fromRelativeUri() [2/5]

bool dart::common::Uri::fromRelativeUri ( const std::string &  _base,
const std::string &  _relative,
bool  _strict = false 
)

Resolve a relative path reference; return success.

All the components will be cleared on failure.

◆ fromRelativeUri() [3/5]

bool dart::common::Uri::fromRelativeUri ( const Uri _base,
const char *  _relative,
bool  _strict = false 
)

Resolve a relative path reference; return success.

All the components will be cleared on failure.

◆ fromRelativeUri() [4/5]

bool dart::common::Uri::fromRelativeUri ( const Uri _base,
const std::string &  _relative,
bool  _strict = false 
)

Resolve a relative path reference; return success.

All the components will be cleared on failure.

◆ fromRelativeUri() [5/5]

bool dart::common::Uri::fromRelativeUri ( const Uri _base,
const Uri _relative,
bool  _strict = false 
)

Resolve a relative path reference; return success.

All the components will be cleared on failure.

◆ fromString()

bool dart::common::Uri::fromString ( const std::string &  _input)

Parse a URI from a string; return success.

All the components will be cleared on failure.

◆ fromStringOrPath()

bool dart::common::Uri::fromStringOrPath ( const std::string &  _input)

Parse a URI or local path (i.e.

URI with no schema) from a string; return success. We assume that any string without a scheme is a path. All the components will be cleared on failure.

◆ getFilesystemPath()

std::string dart::common::Uri::getFilesystemPath ( ) const

Get the path in the local filesystem as a string.

You should use this function rather than getPath() if you are trying to access a local file. Note that this function is identical to getPath() for Unix systems, but differ by the leading '/' on Windows.

◆ getPath()

std::string dart::common::Uri::getPath ( ) const

Get the path component of the URI as a string.

◆ getRelativeUri() [1/3]

std::string dart::common::Uri::getRelativeUri ( const std::string &  _base,
const std::string &  _relative,
bool  _strict = false 
)
static

Resolve a relative path reference; return an empty string on failure.

◆ getRelativeUri() [2/3]

std::string dart::common::Uri::getRelativeUri ( const Uri _base,
const std::string &  _relative,
bool  _strict = false 
)
static

Resolve a relative path reference; return an empty string on failure.

◆ getRelativeUri() [3/3]

std::string dart::common::Uri::getRelativeUri ( const Uri _base,
const Uri _relative,
bool  _strict = false 
)
static

Resolve a relative path reference; return an empty string on failure.

◆ getUri()

std::string dart::common::Uri::getUri ( const std::string &  _input)
static

Parse a URI from a string; return an empty string on failure.

◆ mergePaths()

std::string dart::common::Uri::mergePaths ( const Uri _base,
const Uri _relative 
)
staticprivate

Implement section 5.2.3 of RFC 3986.

◆ removeDotSegments()

std::string dart::common::Uri::removeDotSegments ( const std::string &  _path)
staticprivate

Implement section 5.2.4 of RFC 3986.

◆ toString()

std::string dart::common::Uri::toString ( ) const

Combine the parts of the URI into a string.

Member Data Documentation

◆ mAuthority

UriComponent dart::common::Uri::mAuthority

Authority, e.g. 'google.com', 'en.wikipedia.org'.

◆ mFragment

UriComponent dart::common::Uri::mFragment

Fragment, e.g. the part of the URI after the #.

◆ mPath

UriComponent dart::common::Uri::mPath

Path, e.g. '/index.html', '/foo/bar.txt'.

◆ mQuery

UriComponent dart::common::Uri::mQuery

Query string, i.e. the part of the URI after the ?

◆ mScheme

UriComponent dart::common::Uri::mScheme

Scheme, e.g. 'http', 'file', 'package'.