Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
net_instaweb::QueryParams Class Reference

Parses and rewrites URL query parameters. More...

#include "query_params.h"

Public Member Functions

void ParseFromUrl (const GoogleUrl &gurl)
 
void ParseFromUntrustedString (StringPiece query_param_string)
 
GoogleString ToEscapedString () const
 Generates an escaped query-string.
 
int size () const
 
bool empty () const
 
void Clear ()
 
bool LookupEscaped (const StringPiece &name, ConstStringStarVector *values) const
 
const GoogleStringLookup1Escaped (const StringPiece &name) const
 
bool Lookup1Unescaped (const StringPiece &name, GoogleString *escaped_value) const
 
bool Has (const StringPiece &name) const
 
bool RemoveAll (const StringPiece &key)
 Remove all variables by name. Returns true if anything was removed.
 
bool RemoveAllFromSortedArray (const StringPiece *names, int names_size)
 
StringPiece name (int index) const
 
const GoogleStringEscapedValue (int index) const
 
bool UnescapedValue (int index, GoogleString *escaped_val) const
 
void AddEscaped (const StringPiece &key, const StringPiece &value)
 Add a new variable. The value can be null.
 
void CopyFrom (const QueryParams &query_param)
 

Detailed Description

Parses and rewrites URL query parameters.

Member Function Documentation

const GoogleString* net_instaweb::QueryParams::EscapedValue ( int  index) const
inline

Returns an indexed value. Note that the returned value can be NULL, which indicates the query-param did not have an "=" sign, or it might be an empty string, indicating the query-param had an "=" but no value after it.

The return value is left in its original escaped form.

const GoogleString* net_instaweb::QueryParams::Lookup1Escaped ( const StringPiece &  name) const
inline

Note: there is no LookupUnescaped currently. If we did define one it might have this API: bool LookupUnescaped(const StringPiece& name, StringVector* values) const and we'd have to answer the question of what the semantics should be if some of the values were successfully unescaped, and others not. Looks up a single value. Returns NULL if the name is not found or more than one value is found. The Escaped version will be %-encoded per http://en.wikipedia.org/wiki/Query_string#URL_encoding, the Unescaped version will have those evaluated out, e.g. the escaped form "Hello%2c+World%21" corresponds to the unescaped form "Hello, World!".

bool net_instaweb::QueryParams::Lookup1Unescaped ( const StringPiece &  name,
GoogleString escaped_value 
) const

Looks up a single value. Returns false if the name is not found, more than one value is found, or there is an error encountered when unescaping. See the documentation for Lookup1Unescaped

bool net_instaweb::QueryParams::LookupEscaped ( const StringPiece &  name,
ConstStringStarVector *  values 
) const
inline

Find the value(s) associated with a variable. Note that you may specify a variable multiple times by adding it multiple times with the same variable, and each of these values will be returned in the vector.

Any non alphanumerics besides "-_.~" will be %-encoded, the Unescaped version will have those evaluted out. See http://en.wikipedia.org/wiki/Query_string#URL_encoding

If you want to get back values with %-encodings as originally specified in the query_string passed to Parse(), use the Escaped APIs. If you want to get those values back decoded, uses the Unescaped APIs.

void net_instaweb::QueryParams::ParseFromUntrustedString ( StringPiece  query_param_string)

Parse the given untrusted string containing just query parameters, for example "x=0&y=1&z=2". This is a wrapper method that constructs a GoogleUrl from a dummy URL with the given string appended as query params, then calls ParseFromUrl. Accordingly, the given string will be sanitized by the GoogleUrl constructor: anything after an embedded '#' will be discarded, ''s & '
's & ''s will be discarded, control chars will be %-encoded, ' ' & '"' & '<' & '>' & DEL will be %-encoded, and, when building for open source, which uses chromium's version of url_canon, single-quote ("'") is also %-encoded.

void net_instaweb::QueryParams::ParseFromUrl ( const GoogleUrl gurl)

Parse the query part of the given URL, for example "x=0&y=1&z=2".

Note that a query param value can be NULL, indicating that the name was not followed by a '='. So given "a=0&b&c=", the values will be {"0", NULL, ""}.

bool net_instaweb::QueryParams::RemoveAllFromSortedArray ( const StringPiece *  names,
int  names_size 
)
inline

Remove all variables by name. Returns true if anything was removed.

The 'names' vector must be sorted based on StringCompareSensitive.

bool net_instaweb::QueryParams::UnescapedValue ( int  index,
GoogleString escaped_val 
) const

Sets *escaped_val to the unescaped value at an index. Returns false if there is no value (no "=" in the query param) or if the query parameter could not be decoded.


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