From 0930fdc014bf36fb9e2715b3d14bff5fedf354a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Tue, 22 Mar 2016 00:40:15 +0100 Subject: Parser refactoring. * Use new style * Update to C++11 * Use more std::string than char* --- src/configparser.cc | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'src/configparser.cc') diff --git a/src/configparser.cc b/src/configparser.cc index ac8b876..1ada879 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]; } -- cgit v1.2.3