contents up previous next

wxuri

wxuri is used to extract information from a uri (uniform resource identifier).

for information about uris, see rfc 3986.

in short, a url is a uri. in other words, url is a subset of a uri - all acceptable urls are also acceptable uris.

wxuri automatically escapes invalid characters in a string, so there is no chance of wxuri "failing" on construction/creation.

wxuri supports copy construction and standard assignment operators. wxuri can also be inherited from to provide furthur functionality.

derived from

wxobject

include files

<wx/uri.h>

see also

wxurl

members

obtaining individual components
deviations from the rfc
wxuri::wxuri
wxuri::builduri
wxuri::buildunescapeduri
wxuri::create
wxuri::getfragment
wxuri::gethosttype
wxuri::getpassword
wxuri::getpath
wxuri::getport
wxuri::getquery
wxuri::getscheme
wxuri::getserver
wxuri::getuser
wxuri::getuserinfo
wxuri::hasfragment
wxuri::haspath
wxuri::hasport
wxuri::hasquery
wxuri::hasscheme
wxuri::hasserver
wxuri::hasuser
wxuri::isreference
wxuri::operator ==
wxuri::resolve
wxuri::unescape


obtaining individual components

to obtain individual components you can use one of the following methods

getscheme
getuserinfo
getserver
getport
getpath
getquery
getfragment

however, you should check hasxxx before calling a get method, which determines whether or not the component referred to by the method is defined according to rfc 2396.

consider an undefined component equivalent to a null c string.

hasscheme
hasuserinfo
hasserver
hasport
haspath
hasquery
hasfragment

example:

//protocol will hold the http protocol (i.e. "http")
wxstring protocol;
wxuri myuri(wxt("http://mysite.com"));
if(myuri.hasscheme())
   protocol = myuri.getscheme();

deviations from the rfc

note that on uris with a "file" scheme wxuri does not parse the userinfo, server, or port portion. this is to keep compatability with wxfilesystem, the old wxurl, and older url specifications.


wxuri::wxuri

wxuri()

creates an empty uri.

wxuri(const wxchar* uri)

constructor for quick creation.

uri

wxuri(const wxuri& uri)

copies this uri from another uri.

uri


wxuri::builduri

wxstring builduri() const

builds the uri from its individual components and adds proper separators.

if the uri is not a reference or is not resolved, the uri that is returned from get is the same one passed to create.


wxuri::buildunescapeduri

wxstring buildunescapeduri() const

builds the uri from its individual components, adds proper separators, and returns escape sequences to normal characters.

note that it is preferred to call this over unescape(builduri()) since buildunescapeduri performs some optimizations over the plain method.


wxuri::create

const wxchar* create(const wxstringuri)

creates this uri from the string uri.

returns the position at which parsing stopped (there is no such thing as an "invalid" wxuri).

uri


wxuri::getfragment

const wxstring getfragment() const

obtains the fragment of this uri.

the fragment of a uri is the last value of the uri, and is the value after a '' character after the path of the uri.

http://mysite.com/mypath#<fragment>


wxuri::gethosttype

const hosttype& gethosttype() const

obtains the host type of this uri, which is of type wxuri::hosttype:

wxuri_regname server is a host name, or the server component itself is undefined.
wxuri_ipv4address server is a ip version 4 address (xxx.xxx.xxx.xxx)
wxuri_ipv6address server is a ip version 6 address ((xxx:)xxx::(xxx)xxx:xxx
wxuri_ipvfuture server is an ip address, but not versions 4 or 6


wxuri::getpassword

const wxstring getpassword() const

returns the password part of the userinfo component of this uri. note that this is explicitly depreciated by rfc 1396 and should generally be avoided if possible.

http://<user>:<password>@mysite.com/mypath


wxuri::getpath

const wxstring getpath() const

returns the (normalized) path of the uri.

the path component of a uri comes directly after the scheme component if followed by zero or one slashes ('/'), or after the server/port component.

absolute paths include the leading '/' character.

http://mysite.com<path>


wxuri::getport

const wxstring getport() const

returns a string representation of the uri's port.

the port of a uri is a value after the server, and must come after a colon (:).

http://mysite.com:<port>

note that you can easily get the numeric value of the port by using wxatoi or wxstring::format.


wxuri::getquery

const wxstring getquery() const

returns the query component of the uri.

the query component is what is commonly passed to a cgi application, and must come after the path component, and after a '?' character.

http://mysite.com/mypath?<query>


wxuri::getscheme

const wxstring getscheme() const

returns the scheme component of the uri.

the first part of the uri.

<scheme>://mysite.com


wxuri::getserver

const wxstring getserver() const

returns the server component of the uri.

the server of the uri can be a server name or a type of ip address. see gethosttype for the possible values for the host type of the server component.

http://<server>/mypath


wxuri::getuser

const wxstring getuser() const

returns the username part of the userinfo component of this uri. note that this is explicitly depreciated by rfc 1396 and should generally be avoided if possible.

http://<user>:<password>@mysite.com/mypath


wxuri::getuserinfo

const wxstring getuserinfo() const

returns the userinfo component of the uri.

the component of a uri before the server component that is postfixed by a '@' character.

http://<userinfo>@mysite.com/mypath


wxuri::hasfragment

bool hasfragment() const

returns true if the fragment component of the uri exists.


wxuri::haspath

bool haspath() const

returns true if the path component of the uri exists.


wxuri::hasport

bool hasport() const

returns true if the port component of the uri exists.


wxuri::hasquery

bool hasquery() const

returns true if the query component of the uri exists.


wxuri::hasscheme

bool hasscheme() const

returns true if the scheme component of the uri exists.


wxuri::hasserver

bool hasserver() const

returns true if the server component of the uri exists.


wxuri::hasuser

bool hasuser() const

returns true if the user component of the uri exists.


wxuri::isreference

bool isreference() const

returns true if a valid [absolute] uri, otherwise this uri is a uri reference and not a full uri, and isreference returns false.


wxuri::operator ==

void operator ==(const wxuri& uricomp)

compares this uri to another uri, and returns true if this uri equals uricomp, otherwise it returns false.

uricomp


wxuri::resolve

void resolve(const wxuri& base, int flags = wxuri_strict)

inherits this uri from a base uri - components that do not exist in this uri are copied from the base, and if this uri's path is not an absolute path (prefixed by a '/'), then this uri's path is merged with the base's path.

for instance, resolving "../mydir" from "http://mysite.com/john/doe" results in the scheme (http) and server (mysite.com) being copied into this uri, since they do not exist. in addition, since the path of this uri is not absolute (does not begin with '/'), the path of the base's is merged with this uri's path, resulting in the uri "http://mysite.com/john/mydir".

base

flags


wxuri::unescape

wxstring unescape(const wxstring& uri)

translates all escape sequences (normal characters and returns the result.

this is the preferred over deprecated wxurl::convertfromuri.

if you want to unescape an entire wxuri, use buildunescapeduri instead, as it performs some optimizations over this method.

uri