#include <Uri.h> [code]
Represents URIs as defined in http://www.rfc-editor.org/rfc/rfc3986.txt.
Uri supports both hierarchical and non-hierarchical URIs. The following fileds are provided (example from RFC 3986):
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
The field authority is additionally subdivided into userInfo, host and port.
Relative URIs (scheme, authority, path possibly omitted) are also supported.
Registry-based naming authorities that use the generic syntax are now defined within the host rule. This change allows current implementations, where whatever name provided is simply fed to the local name resolution mechanism, to be consistent with the specification. It also removes the need to re-specify DNS name formats here. Furthermore, it allows the host component to contain percent-encoded octets, which is necessary to enable internationalized domain names to be provided in URIs, processed in their native character encodings at the application layers above URI processing, and passed to an IDNA library as a registered name in the UTF-8 character encoding. The server, hostport, hostname, domainlabel, toplabel, and alphanum rules have been removed.
For most systems, an unreserved character appearing within a URI component is interpreted as representing the data octet corresponding to that character's encoding in US-ASCII. Consumers of URIs assume that the letter "X" corresponds to the octet "01011000", and even when that assumption is incorrect, there is no harm in making it. A system that internally provides identifiers in the form of a different character encoding, such as EBCDIC, will generally perform character translation of textual identifiers to UTF-8 [STD63] (or some other superset of the US-ASCII character encoding) at an internal interface, thereby providing more meaningful identifiers than those resulting from simply percent-encoding the original octets.
Definition at line 82 of file Uri.h.
Public Types | |
| typedef QPair< QByteArray, QByteArray > | QueryItem |
| typedef QList< QueryItem > | QueryItemList |
| enum | Field { Scheme = 0x01, UserInfo = 0x02, Host = 0x04, Port = 0x08, Authority = UserInfo | Host | Port, Path = 0x10, Query = 0x20, Fragment = 0x40, AllFields = Scheme | Authority | Path | Query | Fragment } |
Public Member Functions | |
| Uri (const Uri &) | |
| Copy constructor. | |
| Uri & | operator= (const Uri &) |
| Assignment operator. | |
| bool | operator== (const Uri &) const |
| Equality comparison. | |
| bool | operator!= (const Uri &) const |
| Inequality comparison. | |
| Q_DECLARE_FLAGS (Fields, Field) | |
| Uri () | |
| Constructs a Null Uri object. | |
| QByteArray | scheme () const |
| Returns the scheme component of the URI. | |
| QByteArray | userInfo () const |
| Returns the userInfo component of the URI. | |
| QByteArray | host () const |
| Returns the host component of the URI. | |
| QByteArray | port () const |
| Returns the port component of the URI. | |
| QByteArray | authority () const |
| Returns the authority component of the URI. | |
| QByteArray | path () const |
| Returns the path component of the URI. | |
| QByteArray | query () const |
| Returns the query component of the URI. | |
| QByteArray | queryItemValue (const QByteArray &key) const |
| Returns the value associated with the key from the query part. | |
| QueryItemList | queryItems () const |
| Returns the query component split in query items. | |
| QByteArray | fragment () const |
| Returns the fragment component of the URI. | |
| QByteArray | unencoded (Fields fields=AllFields) const |
| Returns the unencoded URI representation of this Uri object. | |
| QByteArray | encoded (Fields fields=AllFields) const |
| Produces an URI representation of this URI object in encoded form. | |
| void | setScheme (const QByteArray &) |
| Sets the scheme component of the URI. | |
| void | setAuthority (const QByteArray &) |
| Sets the authority part of the URI. | |
| void | setAuthority (const QByteArray &userInfo, const QByteArray &host, const QByteArray &port) |
| Sets the individual fields of the authority component. | |
| void | setPath (const QByteArray &) |
| Sets the path component of the URI. | |
| void | setQuery (const QByteArray &) |
| Sets the query component of the URI. | |
| void | appendQuery (const QByteArray &bytes) |
| Appends bytes to the query URI component. | |
| void | appendQueryItem (const QByteArray &key, const QByteArray &value) |
| Appends a query item (key, value pair) to the query URI component. | |
| void | appendQueryItem (const QueryItem &item) |
| void | appendQueryItems (const QueryItemList &itemList) |
| Appends a list of query items (key, value pairs) to the query URI component. | |
| void | setFragment (const QByteArray &) |
| Sets the fragment component of the URI. | |
Static Public Member Functions | |
| static Uri | fromUnencoded (const QByteArray &) |
| Named ctor for creating an Uri object from unencoded raw bytes. | |
| static Uri | fromEncoded (const QByteArray &) |
| Named ctor for creating an Uri object from encoded raw bytes. | |
Private Member Functions | |
| QByteArray | toQByteArray (Fields fields, bool encode) const |
| Builds the Uri object representation in raw bytes. | |
| bool | parse (const QByteArray &bytes, bool decode) |
| bool | parseAuthority (const QByteArray &authority, bool decode) |
| Helper to split the authority component into userInfo, host, port. | |
Static Private Member Functions | |
| static QByteArray | doEncode (const QByteArray &bytes, bool encode, const QByteArray &charsToExclude) |
| Helper to percent encode a given string if necessary. | |
| static bool | shouldEncode (char ch, const QByteArray &charsToExclude) |
| Helper that checks whether a character should be percent encoded or not. | |
| static char | hex (char) |
| Helper that returns the hexadecimal digit for a given value. | |
| static QByteArray | quoted (char) |
| Helper that returns the percent encoded version of a character. | |
| static bool | doDecode (QByteArray &bytes, bool decode) |
| Helper to actually percent decode a string if required. | |
| static bool | fromHex (char &) |
| Helper that converts a hex character to its integral value. | |
| static char | unquoted (char hex1, char hex2) |
| Helper that produces the unquoted version of two hex values. | |
| static void | ensureNotNull (QByteArray &bytes) |
| Helper that makes sure bytes.isNull() will return false. | |
Private Attributes | |
| QSharedDataPointer< PrivateData > | d |
| Private data with implicit sharing. | |
Static Private Attributes | |
| static const QByteArray | UserInfoEncodeExcludeChars |
| static const QByteArray | HostEncodeExcludeChars |
| static const QByteArray | PathEncodeExcludeChars |
| static const QByteArray | QueryEncodeExcludeChars |
| static const QByteArray | QueryItemEncodeExcludeChars |
| static const QByteArray | FragmentEncodeExcludeChars |
Classes | |
| struct | PrivateData |
| Stores Uri's private implicitly shared data. More... | |
|
|
|
|
|
|
|
|
|
|
|
Copy constructor.
|
|
|
Constructs a Null Uri object.
|
|
|
Appends bytes to the query URI component.
|
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
||||||||||||
|
Appends a query item (key, value pair) to the query URI component.
If the query component is not empty when this function is called, then the character '&' will be appended before appending key and value. |
|
|
Appends a list of query items (key, value pairs) to the query URI component.
|
|
|
Returns the authority component of the URI. The authority component is built from the userInfo, host and port URI components: authority = [userInfo "@"] host [":" port] |
|
||||||||||||
|
Helper to actually percent decode a string if required.
If decode is true, then bytes is modified to contain the decoded version of bytes.
|
|
||||||||||||||||
|
Helper to percent encode a given string if necessary.
|
|
|
Produces an URI representation of this URI object in encoded form.
Under normal circumstances, the only time when octets within a URI are percent-encoded is during the process of producing the URI from its component parts. This is when an implementation determines which of the reserved characters are to be used as subcomponent delimiters and which can be safely used as data. Once produced, a URI is always in its percent-encoded form. URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers. |
|
|
Helper that makes sure bytes.isNull() will return false.
This is used to determine whether an URI component is not set at all or is just empty. isEmpty() is not enough to make this destinction. |
|
|
Returns the fragment component of the URI.
|
|
|
Named ctor for creating an Uri object from encoded raw bytes.
|
|
|
Helper that converts a hex character to its integral value.
|
|
|
Named ctor for creating an Uri object from unencoded raw bytes.
|
|
|
Helper that returns the hexadecimal digit for a given value.
|
|
|
Returns the host component of the URI.
|
|
|
Inequality comparison.
|
|
|
Assignment operator.
|
|
|
Equality comparison.
|
|
||||||||||||
|
Helper to parse a raw representation of an URI into this Uri object.
^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
12 3 4 5 6 7 8 9
|
|
||||||||||||
|
Helper to split the authority component into userInfo, host, port.
|
|
|
Returns the path component of the URI.
|
|
|
Returns the port component of the URI.
|
|
||||||||||||
|
|
|
|
Returns the query component of the URI.
|
|
|
Returns the query component split in query items.
|
|
|
Returns the value associated with the key from the query part.
|
|
|
Helper that returns the percent encoded version of a character.
|
|
|
Returns the scheme component of the URI.
|
|
||||||||||||||||
|
Sets the individual fields of the authority component.
|
|
|
Sets the authority part of the URI.
|
|
|
Sets the fragment component of the URI.
|
|
|
Sets the path component of the URI.
|
|
|
Sets the query component of the URI.
|
|
|
Sets the scheme component of the URI.
|
|
||||||||||||
|
Helper that checks whether a character should be percent encoded or not.
|
|
||||||||||||
|
Builds the Uri object representation in raw bytes.
|
|
|
Returns the unencoded URI representation of this Uri object.
|
|
||||||||||||
|
Helper that produces the unquoted version of two hex values.
|
|
|
Returns the userInfo component of the URI.
|
|
|
Private data with implicit sharing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|