#include <confparser.h>
Public Member Functions | |
| StringConfigurationParser (std::istream *str) | |
| std::string | setCommentsSet (std::string set) |
| std::string | setBlankSet (std::string set) |
| std::string | setDeliminersSet (std::string set) |
| void | skip () |
| bool | parse (std::string &key, std::string &value) |
| bool | eod () |
Private Attributes | |
| std::string | delimiterSet |
| std::string | commentsSet |
| std::string | blankSet |
Static Private Attributes | |
| static const size_t | LINELENGTH = 1024 |
Simple string parser. Reads input stream by lines and split line according delimiter. Everything before delimiters member is marked as key and everything after as value.
Deliminers are specified as set of characters where each stands for separator.
| configuration::StringConfigurationParser::StringConfigurationParser | ( | std::istream * | str | ) | [inline] |
Initialization constructor.
| str | Input stream with data. |
Initializes stream field with str and initializes *Set fields with default values.
References blankSet, commentsSet, and delimiterSet.
| bool configuration::StringConfigurationParser::eod | ( | ) | [inline, virtual] |
Returns istream::eof(). If no stream is specified, returns with true.
Implements configuration::IConfigurationParser< std::string, std::string >.
References configuration::IConfigurationParser< std::string, std::string >::stream.
| bool configuration::StringConfigurationParser::parse | ( | std::string & | key, | |
| std::string & | value | |||
| ) | [inline, virtual] |
Parses valid line. Reads line from current stream position. Removes comments (everything behind membet of commentsSet character). Removes intials and trailing blanks (all characters from blankSet). If result data are empty, parses following line. Otherwise starts parsing.
Parsing process is very simple and just searches first occurence of character from delimiterSet. Everything before separator is used to initialize key parameter and everything behind to value parameter. If none from delimiterSet is found assumes that value is empty and key is whole parsed string.
Both key and value are trimed (leading and trailing blanks - all from blankSet are removed).
If any error occures while reading or end of file occured, returns with false and key, value parameters are not filled.
If no stream is set, immediately returns with false.
Note that input stream can't contain 0 characters.
Implements configuration::IConfigurationParser< std::string, std::string >.
References blankSet, commentsSet, delimiterSet, LINELENGTH, configuration::IConfigurationParser< std::string, std::string >::stream, and configuration::utils::trim().
| std::string configuration::StringConfigurationParser::setBlankSet | ( | std::string | set | ) | [inline] |
Sets new blankSet.
| set | Set of characters. |
References blankSet.
| std::string configuration::StringConfigurationParser::setCommentsSet | ( | std::string | set | ) | [inline] |
Sets new commentsSet.
| set | Set of characters. |
References commentsSet.
| std::string configuration::StringConfigurationParser::setDeliminersSet | ( | std::string | set | ) | [inline] |
Sets new delimiterSet.
| set | Set of characters. |
References delimiterSet.
| void configuration::StringConfigurationParser::skip | ( | ) | [inline, virtual] |
Reads one line and throw it away.
If no stream is specified, immediately returns.
Implements configuration::IConfigurationParser< std::string, std::string >.
References LINELENGTH, and configuration::IConfigurationParser< std::string, std::string >::stream.
std::string configuration::StringConfigurationParser::blankSet [private] |
Set of characters for blanks. Default value contains ` ', `' characters.
Referenced by parse(), setBlankSet(), and StringConfigurationParser().
std::string configuration::StringConfigurationParser::commentsSet [private] |
Set of characters for comments. Default value contains `', `#' characters.
Referenced by parse(), setCommentsSet(), and StringConfigurationParser().
std::string configuration::StringConfigurationParser::delimiterSet [private] |
Set of delimiters. Each character is one delimiter. Default value contains `:' character.
Referenced by parse(), setDeliminersSet(), and StringConfigurationParser().
const size_t configuration::StringConfigurationParser::LINELENGTH = 1024 [static, private] |