diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-03-22 00:40:15 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-03-22 17:16:03 +0100 |
commit | 0728a11284f15100a8f8e0d9da0192019a056d6a (patch) | |
tree | dd430619bc74314ae21941102f1f1f92769d9ddc /src/configparser.cc | |
parent | 8e2124ad955b51efb2f539998a369d7ca07cbc73 (diff) |
Parser refactoring.
* Use new style
* Update to C++11
* Use more std::string than char*
Diffstat (limited to 'src/configparser.cc')
-rw-r--r-- | src/configparser.cc | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/configparser.cc b/src/configparser.cc index 86219dd..e8a6d12 100644 --- a/src/configparser.cc +++ b/src/configparser.cc @@ -32,39 +32,40 @@ ConfigParser::ConfigParser() { - str = NULL; + str = nullptr; } -void ConfigParser::characterData(std::string &data) +void ConfigParser::characterData(const std::string& data) { - if(str) str->append(data); + if(str) + { + str->append(data); + } } -void ConfigParser::startTag(std::string name, attr_t attr) +void ConfigParser::startTag(const std::string& name, attr_t& attr) { - if(name == "value" && attr.find("name") != attr.end()) { - values[attr["name"]] = ""; - str = &values[attr["name"]]; - } + if(name == "value" && attr.find("name") != attr.end()) + { + values[attr["name"]] = ""; + str = &values[attr["name"]]; + } } -void ConfigParser::endTag(std::string name) +void ConfigParser::endTag(const std::string& name) { - if(name == "value") str = NULL; + if(name == "value") + { + str = nullptr; + } } -std::string ConfigParser::value(std::string name, std::string def) +std::string ConfigParser::value(const std::string& name, const std::string& def) { - if(values.find(name) == values.end()) return def; - return values[name]; -} + if(values.find(name) == values.end()) + { + return def; + } -void ConfigParser::parseError(char *buf, size_t len, std::string error, - int lineno) -{ - std::string buffer; - buffer.append(buf, len); - ERR(configparser, "sax parser error '%s' at line %d. " - "Buffer: [%d bytes]<%s>\n", - error.c_str(), lineno, (int)len, buffer.c_str()); + return values[name]; } |