--- smsdaemon/ConfigFile.cpp 2008/12/18 23:29:23 202 +++ smsdaemon/ConfigFile.cpp 2008/12/19 22:29:25 205 @@ -1,7 +1,11 @@ #include "ConfigFile.h" +#include "Util.h" #include #include +#include + +#include const char SEPERATOR = '/'; @@ -123,3 +127,39 @@ } return ss.str(); } + + +namespace ConfigHelper +{ + std::map ParseArguments(const std::string& args) + { + std::map config; + + std::vector sections = Util::str_split(args, ";"); + + for (unsigned i=0; i params = Util::str_split( current, "="); + if (params.size() != 2) + throw std::runtime_error(std::string("syntax error in config line: ") + args); + + std::string key = Util::str_tolower(Util::str_trim(params[0])); + std::string val = Util::str_trim(params[1]); + config[key] = val; + } + + return config; + } + + int StringToInt(const std::string& input) + { + char* endptr = (char*) input.c_str(); + int retval = strtol(input.c_str(), &endptr, 10); + + if ( *endptr != 0) + throw std::runtime_error( std::string("Error: can not convert this to a number: ") + input); + + return retval; + } +}