Google APIs Client Library for C++
ParsedUrl Class Reference

Parses a url as described in 2.4 of RFC 1808. More...

#include "client/util/uri_utils.h"

List of all members.

Public Types

typedef pair< StringPiece, string > QueryParameterAssignment
 Type used for getting individual query parameter bindings.

Public Member Functions

 ParsedUrl (const StringPiece &url)
 Construct the parsed url from a URL.
 ~ParsedUrl ()
 Standard destructor.
const string & url () const
 Returns the URL that was parsed.
StringPiece scheme () const
 Returns the URL's scheme.
StringPiece netloc () const
 Returns the URL's network location.
StringPiece path () const
 Returns the URL's path.
StringPiece params () const
 Returns the URL's parameters.
StringPiece query () const
 Returns the URL's query string.
StringPiece fragment () const
 Returns the URL's fragment.
bool IsValid () const
 Returns whether the URL was valid or not.
const vector
< QueryParameterAssignment > & 
GetQueryParameterAssignments () const
 Returns the detailed assignments for individual query parameters.
bool GetQueryParameter (const StringPiece &name, string *value) const
 Looks up value of query paraemter if it is there.

Static Public Member Functions

static string SegmentOrEmpty (bool join, const StringPiece &a, const StringPiece &b)
 Conditionally joins two strings for a URL segment.

Detailed Description

Parses a url as described in 2.4 of RFC 1808.

This is an extension of RFC 1738 that includes fragments.

In RFC 1808 the URL is in the form: [scheme]://[netloc]/[path];[params]?[query]#[fragment] Each of these parts is optional.

In RFC 1738 the URL form is a function of the scheme, but for http it is http://[host]:[port]/[path]?[searchpart] where here we:

  • treat [netloc] = [host]:[port]
  • allow [path] to have ';'[params]
  • subdivide [searchpart] into [query]'#'[fragment]

Note that the [fragment] and '#' that proceeds it is not actually part of the URL but is here because it is commonly used within the same string context as a URL as specified in RFC 1808.


Member Typedef Documentation

typedef pair<StringPiece, string> QueryParameterAssignment

Type used for getting individual query parameter bindings.

The values will be unescaped.


Constructor & Destructor Documentation

ParsedUrl ( const StringPiece &  url) [explicit]

Construct the parsed url from a URL.

~ParsedUrl ( )

Standard destructor.


Member Function Documentation

StringPiece fragment ( ) const [inline]

Returns the URL's fragment.

Returns:
The URL's fragment does not include the leading '#'. It may be empty.
bool GetQueryParameter ( const StringPiece &  name,
string *  value 
) const

Looks up value of query paraemter if it is there.

Parameters:
[in]nameThe value to look for.
[out]valueThe [unescaped] value found.
Returns:
true if parameter was present, false if not.

Returns the detailed assignments for individual query parameters.

This method is not thread-safe for the first invocation.

bool IsValid ( ) const

Returns whether the URL was valid or not.

StringPiece netloc ( ) const [inline]

Returns the URL's network location.

Returns:
The network location, including port if explicitly specified (e.g. 'www.googleapis.com'). This might be empty.
StringPiece params ( ) const [inline]

Returns the URL's parameters.

Returns:
The URL's parameters are the content between the ';' and query parameters or fragment or end of string. It may be empty.
StringPiece path ( ) const [inline]

Returns the URL's path.

Returns:
The URL's path (e.g. '/drive/v2/files'). This might be empty.
StringPiece query ( ) const [inline]

Returns the URL's query string.

Returns:
The URL's query string is the URL content between the '?' and fragment (or end of string if no fragment). It may be empty.
StringPiece scheme ( ) const [inline]

Returns the URL's scheme.

Returns:
The scheme (e.g. 'https') or empty if none
static string SegmentOrEmpty ( bool  join,
const StringPiece &  a,
const StringPiece &  b 
) [inline, static]

Conditionally joins two strings for a URL segment.

This is a helper function for joining together an attribute with its separator.

Parameters:
[in]joinIf true then join the strings, if false then return empty.
[in]aThe prefix of the joined string.
[in]bThe postfix of the joined string.
Returns:
Either a + b or "".
const string& url ( ) const [inline]

Returns the URL that was parsed.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines