1 |
#include "ConfigFile.h" |
#include "ConfigFile.h" |
2 |
|
#include "Util.h" |
3 |
|
|
4 |
#include <fstream> |
#include <fstream> |
5 |
#include <sstream> |
#include <sstream> |
6 |
|
#include <stdexcept> |
7 |
|
|
8 |
|
#include <stdlib.h> |
9 |
|
|
10 |
const char SEPERATOR = '/'; |
const char SEPERATOR = '/'; |
11 |
|
|
127 |
} |
} |
128 |
return ss.str(); |
return ss.str(); |
129 |
} |
} |
130 |
|
|
131 |
|
|
132 |
|
namespace ConfigHelper |
133 |
|
{ |
134 |
|
std::map<std::string, std::string> ParseArguments(const std::string& args) |
135 |
|
{ |
136 |
|
std::map<std::string, std::string> config; |
137 |
|
|
138 |
|
std::vector<std::string> sections = Util::str_split(args, ";"); |
139 |
|
|
140 |
|
for (unsigned i=0; i<sections.size(); i++) |
141 |
|
{ |
142 |
|
std::string current = Util::str_trim(sections[i]); |
143 |
|
std::vector<std::string> params = Util::str_split( current, "="); |
144 |
|
if (params.size() != 2) |
145 |
|
throw std::runtime_error(std::string("syntax error in config line: ") + args); |
146 |
|
|
147 |
|
std::string key = Util::str_tolower(Util::str_trim(params[0])); |
148 |
|
std::string val = Util::str_trim(params[1]); |
149 |
|
config[key] = val; |
150 |
|
} |
151 |
|
|
152 |
|
return config; |
153 |
|
} |
154 |
|
|
155 |
|
int StringToInt(const std::string& input) |
156 |
|
{ |
157 |
|
char* endptr = (char*) input.c_str(); |
158 |
|
int retval = strtol(input.c_str(), &endptr, 10); |
159 |
|
|
160 |
|
if ( *endptr != 0) |
161 |
|
throw std::runtime_error( std::string("Error: can not convert this to a number: ") + input); |
162 |
|
|
163 |
|
return retval; |
164 |
|
} |
165 |
|
} |