#include <key_value_parser.h>
Public Member Functions | |
key_value_parser (const string &line) | |
Creates a new key_value_parser and runs parse( line ). | |
key_value_parser () | |
Creates an empty key_value_parser. | |
bool | parse (const string &line, const string &delimiter="=") |
Parses 'line' into a key/value pair. | |
const string & | key () const |
Returns the parsed-out key. | |
void | key (const string &v) |
Sets this object's key(). | |
const string & | value () const |
Returns the parsed-out value (may be empty). | |
void | value (const string &v) |
Sets this object's value(). | |
const string & | line () const |
Returns the last whole line passed to parse(). |
Definition at line 18 of file key_value_parser.h.
|
Returns the parsed-out key. Only valid if parse() returned true. Definition at line 75 of file key_value_parser.h. |
|
Parses 'line' into a key/value pair. To be parseable the line must be in the form: key=value Extra whitespace around the '=' removed, as are leading and trailing whitespace around the key and value. This behaviour is arguable but probably desireable in most cases (it is in all of mine, and i wrote the damned thing ;). todo: add a whitespace removal policy as optional 3rd argument? delimiter is the string which separates the key and value, so a line in the format: key{alternateDelimiter}value... (minus the braces) is parseable. alternateDelimiter can be a set of possible delimiters, such as " \t". That is: parse( "one;two",";" ) results in key() == "one" and value() == "two" This function returns false if it does not consider the line to be parseable. Use key() and value() to get the parsed values. Use line() to get the whole string passed to parse (as if you'd ever need it, though subclasses might). line() /is/ guaranteed to be set to line by this call, unlike key() and value(). If this function returns false, the values returned by key() and value() cannot be considered reliable (i.e., they are undefined). This function will return false if a line contains no key (like '=value'), but empty values are not an error (i.e., they will not cause this function to return false). BUG: in some cases (when delimiter is a space) a no-value key can fail to parse. |
|
Returns the parsed-out value (may be empty). Only valid if parse() returned true. Definition at line 90 of file key_value_parser.h. |