wxURI

wxURI is used to extract information from a URI (Uniform Resource Identifier).

For information about URIs, see RFC 3986 (#2).

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

<uri.h>



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();



wxURI::wxURI



wxURI(void)

Creates an empty URI.



wxURI(const wxChar* uri)

Constructor for quick creation.

uri
string to initialize with



wxURI(const wxURI& uri)

Copies this URI from another URI.

uri
URI (Uniform Resource Identifier) to initialize with



wxURI::BuildURI

wxString BuildURI(void) const

Builds the URI from its individual components and adds proper seperators.

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(void) const

Builds the URI from its individual components, adds proper seperators, 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 wxString& uri)

Creates this URI from the string uri.

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

uri
string to initialize from



wxURI::GetFragment

const wxString& GetFragment(void) 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(void) 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(void) 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(void) 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(void) 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(void) 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(void) const

Returns the Scheme component of the URI.

The first part of the uri.

<scheme>://mysite.com



wxURI::GetServer

const wxString& GetServer(void) 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(void) 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(void) 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(void) const

Returns TRUEif the Fragment component of the URI exists.



wxURI::HasPath

bool HasPath(void) const

Returns TRUEif the Path component of the URI exists.



wxURI::HasPort

bool HasPort(void) const

Returns TRUEif the Port component of the URI exists.



wxURI::HasQuery

bool HasQuery(void) const

Returns TRUEif the Query component of the URI exists.



wxURI::HasScheme

bool HasScheme(void) const

Returns TRUEif the Scheme component of the URI exists.



wxURI::HasServer

bool HasServer(void) const

Returns TRUEif the Server component of the URI exists.



wxURI::HasUser

bool HasUser(void) const

Returns TRUEif the User component of the URI exists.



wxURI::IsReference

bool IsReference(void) const

Returns TRUEif 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 TRUEif this URI equals uricomp, otherwise it returns FALSE.

uricomp
URI to compare to



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
Base URI to inherit from. Must be a full URI and not a reference
flags
Currently either wxURI_STRICT or $0$, in non strict mode some compatibility layers are enabled to allow loopholes from RFCs prior to 2396



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
string with escaped characters to convert

ymasuda 平成17年11月19日