Page Speed Optimization Libraries
1.13.35.1
|
#include "string_multi_map.h"
Public Member Functions | |
bool | empty () const |
void | Clear () |
int | num_names () const |
Returns the number of distinct names. | |
int | num_values () const |
bool | Lookup (const StringPiece &name, ConstStringStarVector *values) const |
const GoogleString * | Lookup1 (const StringPiece &name) 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 GoogleString * | value (int index) const |
Note that the value can be NULL. | |
void | Add (const StringPiece &key, const StringPiece &value) |
Add a new variable. The value can be null. More... | |
void | AddFromNameValuePairs (const StringPiece &name_value_list, const StringPiece &separators, char value_separator, bool omit_if_no_value) |
void | CopyFrom (const StringMultiMap &string_multi_map) |
Implements an ordered string map, providing case-sensitive and case insensitive versions. The order of insertion is retained and names/value pairs can be accessed by index or looked up by name.
The keys and values in the map may contain embedded NUL characters. The values can also be the NULL pointer, which the API retains distinctly from empty strings.
|
inline |
Add a new variable. The value can be null.
To avoid letting you corrupt the comparison sanity of an STL set, the 'insert' method returns an iterator that returns you only a const reference to the stored entry. However, the mutation we are going to do here is to change the key to point to storage we'll own in the entry, which we want to allocate only the first time it is added.
We also need to be able to mutate the entry to allow adding new value entries.
The first time we insert, make a copy of the key in storage we own.
|
inline |
Parse and add from a string of name-value pairs. For example, "name1=value1,name2=value2,name3=" where separators is "," and value_separator is '='. If omit_if_no_value is true, a name-value pair with an empty value will not be added.
|
inline |
Find the value(s) associated with a variable. Note that you may specify a variable multiple times by calling Add multiple times with the same variable, and each of these values will be returned in the vector.
|
inline |
Looks up a single value. Returns NULL if the name is not found or more than one value is found.
|
inline |
Returns the number of distinct values, which can be larger than num_names if Add is called twice with the same name.
|
inline |
Remove all variables by name. Returns true if anything was removed.
The 'names' vector must be sorted based on StringCompare.
compare implements <, and we want <= to allow for for duplicate entries, such as the two Set-Cookie entries that occur in ResponseHeadersTest.TestUpdateFrom. We could also require call-sites to de-dup but this seems easier. We can implement a<=b via !compare(b, a).
Keep around dummy entry for stuffing in keys and doing lookups. The values field for this instance is unused.
First, see if any of the names are in the map. This way we'll avoid making any allocations if there is no work to be done. We cannot actually remove the map entries, though, until we rebuild the vector, since the map owns the StringPiece key storage used by the vector.
< Temp variable for new vector.