#include <MURI.h>
Manipulating Uniform Resource Identifiers.
The MURI class implements the W3 URI standard. It can parse and and construct URIs (Uniform Resource Identifiers). It is based on URI specification RFC 3986 (Uniform Resource Identifier: Generic Syntax).
The scheme and path components are required, although the path may be empty (no characters). When the authority is present, the path must either be empty or begin with a slash ("/") character. When the authority is not present, the path cannot begin with two slash characters ("//").
URI objects are often initialized using URI string values. An MURI object can be constructed from an MString value, or set from a string using the setURI() method.
A URI can also be constructed from its individual components using methods setScheme(), setUserName(), setPassword(), setHost(), setPort(), setPath(), addQueryItem() and setFragment().
Convenience methods such as setAuthority() and setUserInfo() are also available to initialize groups of related components. Methods for configuring the query components of the URI are also provided: setQueryItems(), addQueryItem(), removeQueryItem() and setQueryDelimiters().
The string representation of the URI object is obtained by calling asString(). Individual components of the URI are accessed by calling the corresponding get methods.
The MURI can be validated at any point by calling the isValid() method. In addition, a static method isValidURI() is available to determine if an MString represents a valid URI.
Public Member Functions | |
MURI () | |
Class constructor. More... | |
MURI (const MString &URI) | |
Creates a new MURI object and initializes it using a URI string value. More... | |
MURI (const MURI &other) | |
Copy constructor. More... | |
~MURI () | |
Class destructor. | |
MURI & | operator= (const MURI &rhs) |
Assignment operator. More... | |
MURI & | operator= (const MString &URI) |
Assignment operator. More... | |
bool | operator== (const MURI &rhs) const |
Equality operator. More... | |
bool | operator!= (const MURI &rhs) const |
Inequality operator. More... | |
MStatus | copy (const MURI &other) |
Copy the contents of one URI object to another. More... | |
MStatus | setURI (const MString &URI) |
Initialize the MURI from a string value. More... | |
MStatus | setScheme (const MString &scheme) |
Sets the scheme component of the URI. More... | |
MStatus | setPath (const MString &path) |
Sets the path component of the URI. More... | |
MStatus | setFragment (const MString &fragment) |
Sets the fragment component of the URI. More... | |
MStatus | setFileName (const MString &fileName) |
Sets just the filename portion of the URI (i.e. More... | |
MStatus | setDirectory (const MString &directory) |
Sets just the directory portion of the URI (i.e. More... | |
MStatus | setAuthority (const MString &authority) |
Set the authority portion of the URI. More... | |
MStatus | setUserInfo (const MString &userInfo) |
Decomposes the userInfo string to fill out the userInfo-related component values. More... | |
MStatus | setUserName (const MString &userName) |
Sets the user name part of the user info component. More... | |
MStatus | setPassword (const MString &password) |
Sets the password part of the user info component. More... | |
MStatus | setHost (const MString &host) |
Set the host component of the URI. More... | |
MStatus | setPort (int port) |
Set the port component of the URI. More... | |
MStatus | addQueryItem (const MString &key, const MString &value) |
Add a key/value pair to the query string of the URI. More... | |
MStatus | setQueryDelimiters (char valueDelimiter, char pairDelimiter) |
Sets the delimiter characters used in the query string of the URI. More... | |
MString | asString () const |
Returns the string representation of the URI. More... | |
MString | getScheme () const |
Returns the scheme of the URI. More... | |
MString | getPath () const |
Returns the path component of the URI. More... | |
MString | getFragment () const |
Returns the fragment component of the URI. More... | |
MString | getFileName (bool includeExtension=true) const |
Returns just the file name portion of the URI, with or without the extension. More... | |
MString | getDirectory () const |
Returns just the file directory portion of the URI, without the file name. More... | |
MString | getAuthority () const |
Returns the authority component of the URI. More... | |
MString | getUserInfo () const |
Returns the user info component of the URI. More... | |
MString | getUserName () const |
Returns the user name component of the URI. More... | |
MString | getPassword () const |
Returns the password component of the URI. More... | |
MString | getHost () const |
Returns the host component of the URI. More... | |
int | getPort () const |
Returns the port component of the URI, or -1 if the port is not defined. More... | |
MStringArray | getAllQueryItemKeys () const |
Returns an array containing the keys from all query string pairs. More... | |
MString | getQueryItemValue (const MString &key) const |
Returns the value from the first query string pair in the URI which has a given key. More... | |
MStringArray | getAllQueryItemValues (const MString &key) const |
Returns an array containing the values from all query string pairs which have a given key. More... | |
char | getQueryValueDelimiter () const |
Returns the character used to delimit keys and values in the query string of the URI. More... | |
char | getQueryPairDelimiter () const |
Returns the character used to delimit between key-value pairs in the query string of the URI. More... | |
MStatus | removeQueryItem (const MString &key) |
Removes the first query string pair with a given key from the URI. More... | |
MStatus | removeAllQueryItems (const MString &key) |
Removes all query string pairs having a given key from the URI. More... | |
bool | isEmpty () const |
Determines if the URI does not contain any data. More... | |
bool | isValid () const |
Determines if the URI is valid. More... | |
MStatus | clear () |
Clears the contents of the MURI object. More... | |
Static Public Member Functions | |
static bool | isValidURI (const MString &URI) |
Determines if a string value represents a valid URI. More... | |
static const char * | className () |
Returns the name of this class. More... | |
Creates a new MURI object and initializes it using a URI string value.
[in] | URI | The URI string. This must be a properly formatted URI (e.g. "file:///C:/dir/texture.jpg" on Windows). The individual components of the URI will be set based on the contents of the string. |
Note that the directory separator for all platforms, including Windows, is a forward slash ('/'). Backslashes ('\') are treated as normal characters by this method but should be avoided as they may be interpreted as escape characters in other contexts. A regular file path (e.g. "C:\dir\texture.jpg" on Windows) is not a valid URI. See also isValid() and isValidURI().
Assignment operator.
Set the URI from a string value. The individual components of the URI will be set based on the contents of the string.
[in] | URI | The URI string. |
bool operator== | ( | const MURI & | rhs | ) | const |
Equality operator.
Compares two MURI objects to see if they contain the same value.
[in] | rhs | Right operand. |
bool operator!= | ( | const MURI & | rhs | ) | const |
Inequality operator.
Compares two MURI objects to see if they differ.
[in] | rhs | Right operand. |
Copy the contents of one URI object to another.
[in] | other | The URI object to copy. |
Initialize the MURI from a string value.
The individual components of the URI will be set based on the contents of the string.
[in] | URI | The URI string. |
Sets the scheme component of the URI.
The scheme identifies the type of the URI. It is the first element of the URI and consists of all the characters preceeding the first ':'. The scheme is expected to contain only ASCII characters.
[in] | scheme | The scheme to set |
Sets the path component of the URI.
The path can contain both a directory and a file name. See also setFileName() and setDirectory().
[in] | path | The path to set |
Sets the fragment component of the URI.
The fragment is the last part of the URI, after the '#'.
[in] | fragment | The fragment to set |
Sets just the filename portion of the URI (i.e.
not including the directory). See also setPath() and setDirectory().
[in] | fileName | The file name to set |
Sets just the directory portion of the URI (i.e.
not including the filename). See also setPath() and setFileName().
Note that the directory separator for all platforms, including Windows, is a forward slash ('/'). Backslashes ('\') are treated as normal characters by this method but should be avoided as they may be interpreted as escape characters in other contexts.
If there is no directory separator at the end of the directory path, one will be added.
[in] | directory | The file directory to set |
Set the authority portion of the URI.
Decomposes the authority string to set the authority-related component values. The user info and host are separated by a '@', and the host and port are separated by a ':'. See also setUserName(), setPassword(), setHost() and setPort().
username:passw:8042 ord@ examp le.c om
[in] | authority | The authority value to set |
Decomposes the userInfo string to fill out the userInfo-related component values.
The user info consists of a user name and password separated by a colon ':'. The password is optional, if not specified, no colon is used. See also setAuthority(), setUserName(), setPassword().
username:password
[in] | userInfo | The userInfo to set |
Sets the user name part of the user info component.
See also setAuthority(), setUserInfo(), setPassword().
[in] | userName | The user name to set |
Sets the password part of the user info component.
See also setAuthority(), setUserInfo(), setUserName().
[in] | password | The password to set |
Set the host component of the URI.
See also setAuthority(), setPort()
[in] | host | The host to set |
MStatus setPort | ( | int | port | ) |
Set the port component of the URI.
See also setAuthority(), setHost()
[in] | port | The port to set |
Add a key/value pair to the query string of the URI.
[in] | key | The key to set |
[in] | value | The value to set |
MStatus setQueryDelimiters | ( | char | valueDelimiter, |
char | pairDelimiter | ||
) |
Sets the delimiter characters used in the query string of the URI.
The value delimiter is used between the key and the value in each pair. The pair delimeter separates pairs in the string.
The default value delimiter is '=' and the default pair delimiter is '&'.
See also getQueryValueDelimiter(), getQueryPairDelimiter().
[in] | valueDelimiter | The valueDelimiter to set |
[in] | pairDelimiter | The pairDelimiter to set |
MString asString | ( | ) | const |
Returns the string representation of the URI.
MString getScheme | ( | ) | const |
Returns the scheme of the URI.
An empty string is returned if the scheme is undefined or the current URI is invalid.
MString getPath | ( | ) | const |
Returns the path component of the URI.
The path of the URI is composed of the file directory and file name. See also getFileName() and getDirectory() to access the file directory and file name components of the path individually.
MString getFragment | ( | ) | const |
Returns the fragment component of the URI.
If the fragment is undefined, an empty string is returned.
MString getFileName | ( | bool | includeExtension = true | ) | const |
Returns just the file name portion of the URI, with or without the extension.
The file directory is not included. See also getPath() and getDirectory().
[in] | includeExtension | If true include the extension (e.g. "file.jpg"), otherwise do not (e.g. "file"). Its default value is true. |
MString getDirectory | ( | ) | const |
Returns just the file directory portion of the URI, without the file name.
See also getPath() and getFileName().
MString getAuthority | ( | ) | const |
Returns the authority component of the URI.
If the authority is undefined, an empty string is returned.
MString getUserInfo | ( | ) | const |
Returns the user info component of the URI.
If the user info is not defined, an empty string is returned. See also getUserName(), getPassword(), getHost(), getPort().
MString getUserName | ( | ) | const |
Returns the user name component of the URI.
If the user name is not defined, an empty string is returned. See also getUserInfo(), getPassword().
MString getPassword | ( | ) | const |
Returns the password component of the URI.
If the password is not defined, an empty string is returned. See also getUserInfo(), getUserName().
MString getHost | ( | ) | const |
Returns the host component of the URI.
If the host is not defined, an empty string is returned. See also getUserInfo(), getPort().
int getPort | ( | ) | const |
Returns the port component of the URI, or -1 if the port is not defined.
See also getUserInfo(), getHost().
MStringArray getAllQueryItemKeys | ( | ) | const |
Returns an array containing the keys from all query string pairs.
Returns the value from the first query string pair in the URI which has a given key.
[in] | key | The key to query |
MStringArray getAllQueryItemValues | ( | const MString & | key | ) | const |
Returns an array containing the values from all query string pairs which have a given key.
[in] | key | The key to query |
char getQueryValueDelimiter | ( | ) | const |
Returns the character used to delimit keys and values in the query string of the URI.
See also setQueryDelimiters().
char getQueryPairDelimiter | ( | ) | const |
Returns the character used to delimit between key-value pairs in the query string of the URI.
Removes the first query string pair with a given key from the URI.
[in] | key | The key of the query item to remove |
Removes all query string pairs having a given key from the URI.
[in] | key | The key of the query items to remove |
bool isEmpty | ( | ) | const |
Determines if the URI does not contain any data.
bool isValid | ( | ) | const |
Determines if the URI is valid.
MStatus clear | ( | ) |
Clears the contents of the MURI object.
After clearing, the URI will be empty.
|
static |
Determines if a string value represents a valid URI.
[in] | URI | the URI string to validate |
|
static |
Returns the name of this class.