A "URI-reference" is either a URI or a relative reference.
Syntax: Note that it is up to the application to correctly compose a URI reference with a missing scheme or authority, i.e. to make sure the initial path chars (if any) do not look like a scheme or authority (it helps with this library that the path
class cannot have empty segments so it cannot have a URI authority-like prefix).
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] relative-ref = relative-part [ "?" query ] [ "#" fragment ] relative-part = "//" authority path-abempty | path-absolute | path-noscheme | path-empty hier-part = "//" authority path-abempty | path-absolute | path-rootless | path-empty path-abempty = *( "/" segment ) path-absolute = "/" [ segment-nz *( "/" segment ) ] path-noscheme = segment-nz-nc *( "/" segment ) path-rootless = segment-nz *( "/" segment ) path-empty = 0<pchar>
Example:
uripp::uri u("http://mydomain.com/a/b/c?id=12345&s=x%20y"); assert(u.scheme().string() == "http"); assert(u.authority().host() == "mydomain.com"); assert(u.path().absolute()); uripp::path::const_iterator it = u.path().begin(); assert(*it == "a" && *++it == "b" && *++it == "c" && ++it == u.path().end()); int id; std::string s; bool is_null; assert(u.query().find("id", id, is_null) && id == 12345 && !is_null); assert(u.query().find("s", s, is_null) && s == "x y" && !is_null); assert(!u.query().find("foo", s, is_null));
Public Types | |
typedef uripp::scheme | scheme_type |
scheme type | |
typedef uripp::authority | authority_type |
authority type | |
typedef uripp::path | path_type |
path type | |
typedef uripp::query | query_type |
query type | |
typedef uripp::fragment | fragment_type |
fragment type | |
Public Member Functions | |
uri () | |
uri (const std::string &v) | |
bool | empty () const |
Test if null/empty. | |
bool | is_null () const |
Test if null/empty. | |
bool | relative () const |
Test if relative (null scheme). | |
const scheme_type & | scheme () const |
Get scheme (null if relative). | |
scheme_type & | scheme () |
Get scheme (null if relative). | |
const authority_type & | authority () const |
Get authority. | |
authority_type & | authority () |
Get authority. | |
const path_type & | path () const |
Get path. | |
path_type & | path () |
Get path. | |
const query_type & | query () const |
Get query. | |
query_type & | query () |
Get query. | |
const fragment_type & | fragment () const |
Get fragment. | |
fragment_type & | fragment () |
Get fragment. | |
std::string | encoding () const |
Calculate encoded string. | |
std::ostream & | operator<< (std::ostream &os) const |
Stream out encoding. | |
Friends | |
bool URIPP_API | parse (std::string::const_iterator &first, std::string::const_iterator last, uri &v, std::string *errs) |
uripp::uri::uri | ( | ) |
Construct.
uripp::uri::uri | ( | const std::string & | v | ) |
Construct from encoded string.
std::invalid_argument | if invalid encoding |
bool URIPP_API parse | ( | std::string::const_iterator & | first, | |
std::string::const_iterator | last, | |||
uri & | v, | |||
std::string * | errs | |||
) | [friend] |
Parse URI, returning whether found or not and advancing first and setting URI if found. Does not skip leading space.
If errs
is specified parsing is more lax allowing decoding and other errors and setting errs
with the error messages. See the individual component parse
functions for details.