libUTL++
utl::URI Class Reference

Generic URI (Universal Resource Identifier). More...

#include <URI.h>

Inheritance diagram for utl::URI:

Public Member Functions

 URI (const String &uri)
 Constructor. More...
 
virtual void copy (const Object &rhs)
 Copy another instance. More...
 
virtual void steal (Object &rhs)
 "Steal" the internal representation from another instance. More...
 
virtual int compare (const Object &rhs) const
 Compare with another object. More...
 
virtual String toString () const
 Return a string representation of self. More...
 
virtual size_t innerAllocatedSize () const
 Get the "inner" allocated size. More...
 
Getters
bool isRelative () const
 Relative URI?
 
String get () const
 Get the complete (percent-encoded) URI. More...
 
const Stringscheme () const
 Get the scheme. More...
 
String authority () const
 Get the authority string. More...
 
String userinfo () const
 Get the userinfo string. More...
 
const Stringusername () const
 Get the username. More...
 
const Stringpassword () const
 Get the password. More...
 
const Stringhostname () const
 Get the hostname. More...
 
uint_t port () const
 Get the port. More...
 
String fullPath () const
 Get the full path (path + filename + extension). More...
 
const Stringpath () const
 Get the path. More...
 
String fullFilename () const
 Get the full filename (filename + extension). More...
 
const Stringfilename () const
 Get the filename. More...
 
const Stringextension () const
 Get the extension. More...
 
size_t numSegments () const
 Get the number of segments in the path. More...
 
String segment (size_t id) const
 Get the (id)th segment of the path. More...
 
String query () const
 Get the query string. More...
 
size_t queryVarsCount () const
 Get the number of query variables. More...
 
void queryVarNameValue (size_t id, String &name, String &value) const
 Get the (id)th query variable's name and value. More...
 
void queryVarsCopy (Collection &col) const
 Copy query variables (as utl::Pair objects) into the given collection. More...
 
const Stringfragment () const
 Get the fragment identifier. More...
 
Setters / Modification
void clear ()
 Revert to initial/empty state. More...
 
void set (const String &uri)
 Set the uri. More...
 
void appendSlash ()
 Append trailing slash to the full path. More...
 
void removeSlash ()
 Remove trailing slash from full path. More...
 
void setScheme (const String &scheme)
 Set the scheme. More...
 
void setUserinfo (const String &username, const String &password)
 Set the "userinfo" (username & password). More...
 
void setHostname (const String &hostname)
 Set the hostname. More...
 
void setPort (uint_t port)
 Set the port. More...
 
void setFullPath (const String &fp)
 Set the full path (path + filename + extension). More...
 
void setPath (const String &path)
 Set the path. More...
 
void addQueryVariable (const String &name, const String &value)
 Add a query variable. More...
 
void setFilename (const String &filename)
 Set the filename. More...
 
void setExtension (const String &extension)
 Set the extension. More...
 
Interoperation with String
 operator String () const
 Get the complete (percent-encoded) URI. More...
 
URI operator+ (const char *rhs) const
 Get a copy of self with the given string appended to the full path. More...
 
URI operator+ (const String &rhs) const
 Get a copy of self with the given string appended to the full path. More...
 
URIoperator+= (const char *rhs)
 Append the given string to the full path. More...
 
URIoperator+= (const String &rhs)
 Append the given string to the full path. More...
 
- Public Member Functions inherited from utl::Object
void clear ()
 Revert to initial state. More...
 
virtual void vclone (const Object &rhs)
 Make an exact copy of another instance. More...
 
virtual void dump (Stream &os, uint_t level=uint_t_max) const
 Dump a human-readable representation of self to the given output stream. More...
 
void dumpWithClassName (Stream &os, uint_t indent=4, uint_t level=uint_t_max) const
 Front-end for dump() that prints the object's class name. More...
 
virtual const ObjectgetKey () const
 Get the key for this object. More...
 
bool hasKey () const
 Determine whether or not the object has a key. More...
 
virtual const ObjectgetProxiedObject () const
 Get the proxied object (= self if none). More...
 
virtual ObjectgetProxiedObject ()
 Get the proxied object (= self if none). More...
 
virtual size_t hash (size_t size) const
 Get the hash code for the object. More...
 
bool _isA (const RunTimeClass *runTimeClass) const
 Determine whether self's class is a descendent of the given class. More...
 
 operator String () const
 Conversion to String. More...
 
size_t allocatedSize () const
 Get the total allocated size of this object. More...
 
virtual void addOwnedIt (const class FwdIt *it) const
 Notify self that it owns the given iterator. More...
 
virtual void removeOwnedIt (const class FwdIt *it) const
 Notify self that the given owned iterator has been destroyed. More...
 
bool operator< (const Object &rhs) const
 Less-than operator. More...
 
bool operator<= (const Object &rhs) const
 Less-than-or-equal-to operator. More...
 
bool operator> (const Object &rhs) const
 Greater-than operator. More...
 
bool operator>= (const Object &rhs) const
 Greater-than-or-equal-to operator. More...
 
bool operator== (const Object &rhs) const
 Equal-to operator. More...
 
bool operator!= (const Object &rhs) const
 Unequal-to operator. More...
 
void serializeIn (Stream &is, uint_t mode=ser_default)
 Serialize from an input stream. More...
 
void serializeOut (Stream &os, uint_t mode=ser_default) const
 Serialize to an output stream. More...
 
virtual void serialize (Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize to or from a stream. More...
 
void serializeOutBoxed (Stream &os, uint_t mode=ser_default) const
 Serialize a boxed object to an output stream. More...
 

Static Public Member Functions

Percent-encoding (aka URL-encoding)
static String percentEncode (const String &str, bool isPath=false)
 Get a percent-encoded representation of the given string. More...
 
static String percentDecode (const String &str)
 Get a percent-decoded representation of the given string. More...
 
libUTL++ init,deInit
static void utl_init ()
 Perform global init (called by utl::init()). More...
 
static void utl_deInit ()
 Perform global deInit (called by utl::deInit()). More...
 
- Static Public Member Functions inherited from utl::Object
static ObjectserializeInNullable (Stream &is, uint_t mode=ser_default)
 Serialize a nullptr-able object from an input stream. More...
 
static void serializeOutNullable (const Object *object, Stream &os, uint_t mode=ser_default)
 Serialize a nullptr-able object to an output stream. More...
 
static void serializeNullable (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullptr-able object to or from a stream. More...
 
static ObjectserializeInBoxed (Stream &is, uint_t mode=ser_default)
 Serialize a boxed object from an input stream. More...
 
static void serializeBoxed (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object to or from a stream. More...
 

Detailed Description

Generic URI (Universal Resource Identifier).

The various components of a URI are illustrated by example:

URI uri("http://user:pass@xyz.com:80/path/to/res.txt?var=val#fragment");
assert(uri.scheme() == "http");
assert(uri.username() == "user");
assert(uri.password() == "pass");
assert(uri.hostname() == "xyz.com");
assert(uri.port() == 80);
assert(uri.path() == "/path/to/";
assert(uri.filename() == "res");
assert(uri.extension() == "txt");
assert(uri.segment(1) == "path");
assert(uri.segment(2) == "to");
assert(uri.segment(3) == "resource");
assert(uri.query() == "var=val");
assert(uri.queryVar(1) == "var");
assert(uri.queryVal(1) == "val");
assert(uri.fragment() == "fragment");
Author
Adam McKee

Definition at line 50 of file URI.h.

Constructor & Destructor Documentation

◆ URI()

utl::URI::URI ( const String uri)
inline

Constructor.

Parameters
uriURI

Definition at line 59 of file URI.h.

References utl::compare(), utl::copy(), utl::init(), and utl::toString().

Member Function Documentation

◆ copy()

virtual void utl::URI::copy ( const Object rhs)
virtual

Copy another instance.

When you override copy(), you should usually call the superclass's copy().

Parameters
rhsobject to copy

Reimplemented from utl::Object.

◆ steal()

virtual void utl::URI::steal ( Object rhs)
virtual

"Steal" the internal representation from another instance.

The default implementation just calls vclone(), so you have to override this if you want a "move" capability.

Reimplemented from utl::Object.

◆ compare()

virtual int utl::URI::compare ( const Object rhs) const
virtual

Compare with another object.

If no overridden version succeeds in doing the comparison, then an attempt will be made to re-start the comparison process using one or both of the objects' keys. Usually, an override of compare() should call the superclass's compare() if it doesn't know how to compare itself with the rhs object.

See also
getKey
Returns
< 0 if self < rhs, 0 if self = rhs, > 0 if self > rhs
Parameters
rhsobject to compare with

Reimplemented from utl::Object.

◆ toString()

virtual String utl::URI::toString ( ) const
virtual

Return a string representation of self.

Reimplemented from utl::Object.

◆ innerAllocatedSize()

virtual size_t utl::URI::innerAllocatedSize ( ) const
virtual

Get the "inner" allocated size.

Reimplemented from utl::Object.

◆ get()

String utl::URI::get ( ) const

Get the complete (percent-encoded) URI.

◆ scheme()

const String& utl::URI::scheme ( ) const
inline

Get the scheme.

Definition at line 89 of file URI.h.

References utl::emptyString.

◆ authority()

String utl::URI::authority ( ) const

Get the authority string.

◆ userinfo()

String utl::URI::userinfo ( ) const

Get the userinfo string.

◆ username()

const String& utl::URI::username ( ) const
inline

Get the username.

Definition at line 102 of file URI.h.

References utl::emptyString.

◆ password()

const String& utl::URI::password ( ) const
inline

Get the password.

Definition at line 109 of file URI.h.

References utl::emptyString.

◆ hostname()

const String& utl::URI::hostname ( ) const
inline

Get the hostname.

Definition at line 116 of file URI.h.

References utl::emptyString.

◆ port()

uint_t utl::URI::port ( ) const
inline

Get the port.

Definition at line 123 of file URI.h.

◆ fullPath()

String utl::URI::fullPath ( ) const

Get the full path (path + filename + extension).

◆ path()

const String& utl::URI::path ( ) const
inline

Get the path.

Definition at line 133 of file URI.h.

References utl::emptyString.

◆ fullFilename()

String utl::URI::fullFilename ( ) const

Get the full filename (filename + extension).

◆ filename()

const String& utl::URI::filename ( ) const
inline

Get the filename.

Definition at line 143 of file URI.h.

References utl::emptyString.

◆ extension()

const String& utl::URI::extension ( ) const
inline

Get the extension.

Definition at line 150 of file URI.h.

References utl::emptyString.

◆ numSegments()

size_t utl::URI::numSegments ( ) const

Get the number of segments in the path.

◆ segment()

String utl::URI::segment ( size_t  id) const

Get the (id)th segment of the path.

For example, if the path is /foo/bar/ then segment 1 is foo and segment 2 is bar.

Returns
requested segment
Parameters
id(1-based) id of requested segment

◆ query()

String utl::URI::query ( ) const

Get the query string.

◆ queryVarsCount()

size_t utl::URI::queryVarsCount ( ) const

Get the number of query variables.

◆ queryVarNameValue()

void utl::URI::queryVarNameValue ( size_t  id,
String name,
String value 
) const

Get the (id)th query variable's name and value.

Parameters
id(1-based) id of requested query variable name/value pair
namestores the name of the requested variable
valuestores the value of the requested variable

◆ queryVarsCopy()

void utl::URI::queryVarsCopy ( Collection col) const

Copy query variables (as utl::Pair objects) into the given collection.

Parameters
colcollection which will receive name/value utl::Pair objects

◆ fragment()

const String& utl::URI::fragment ( ) const
inline

Get the fragment identifier.

Definition at line 189 of file URI.h.

References utl::emptyString.

◆ clear()

void utl::URI::clear ( )

Revert to initial/empty state.

◆ set()

void utl::URI::set ( const String uri)

Set the uri.

◆ appendSlash()

void utl::URI::appendSlash ( )

Append trailing slash to the full path.

◆ removeSlash()

void utl::URI::removeSlash ( )

Remove trailing slash from full path.

◆ setScheme()

void utl::URI::setScheme ( const String scheme)
inline

Set the scheme.

Definition at line 211 of file URI.h.

◆ setUserinfo()

void utl::URI::setUserinfo ( const String username,
const String password 
)
inline

Set the "userinfo" (username & password).

Parameters
usernameui.username
passwordui.password

Definition at line 223 of file URI.h.

◆ setHostname()

void utl::URI::setHostname ( const String hostname)
inline

Set the hostname.

Definition at line 233 of file URI.h.

◆ setPort()

void utl::URI::setPort ( uint_t  port)
inline

Set the port.

Definition at line 241 of file URI.h.

◆ setFullPath()

void utl::URI::setFullPath ( const String fp)

Set the full path (path + filename + extension).

Referenced by operator+().

◆ setPath()

void utl::URI::setPath ( const String path)
inline

Set the path.

Definition at line 251 of file URI.h.

◆ addQueryVariable()

void utl::URI::addQueryVariable ( const String name,
const String value 
)

Add a query variable.

◆ setFilename()

void utl::URI::setFilename ( const String filename)
inline

Set the filename.

Definition at line 262 of file URI.h.

◆ setExtension()

void utl::URI::setExtension ( const String extension)
inline

Set the extension.

Definition at line 270 of file URI.h.

◆ operator String()

utl::URI::operator String ( ) const
inline

Get the complete (percent-encoded) URI.

Definition at line 280 of file URI.h.

◆ operator+() [1/2]

URI utl::URI::operator+ ( const char *  rhs) const
inline

Get a copy of self with the given string appended to the full path.

Definition at line 286 of file URI.h.

References setFullPath().

◆ operator+() [2/2]

URI utl::URI::operator+ ( const String rhs) const
inline

Get a copy of self with the given string appended to the full path.

Definition at line 294 of file URI.h.

References setFullPath().

◆ operator+=() [1/2]

URI& utl::URI::operator+= ( const char *  rhs)
inline

Append the given string to the full path.

Definition at line 302 of file URI.h.

◆ operator+=() [2/2]

URI& utl::URI::operator+= ( const String rhs)
inline

Append the given string to the full path.

Definition at line 309 of file URI.h.

References utl::deInit(), and utl::init().

◆ percentEncode()

static String utl::URI::percentEncode ( const String str,
bool  isPath = false 
)
static

Get a percent-encoded representation of the given string.

◆ percentDecode()

static String utl::URI::percentDecode ( const String str)
static

Get a percent-decoded representation of the given string.

◆ utl_init()

static void utl::URI::utl_init ( )
static

Perform global init (called by utl::init()).

◆ utl_deInit()

static void utl::URI::utl_deInit ( )
static

Perform global deInit (called by utl::deInit()).


The documentation for this class was generated from the following file: