Minor tweak to ConfigUtility

This commit is contained in:
Kayne Ruse
2014-07-31 17:14:40 +10:00
parent 414a0896c9
commit 46f02dcfdd
2 changed files with 13 additions and 19 deletions
+10 -10
View File
@@ -25,25 +25,25 @@
#include <fstream> #include <fstream>
#include <stdexcept> #include <stdexcept>
using namespace std; void ConfigUtility::Load(std::string fname) {
std::ifstream is(fname);
void ConfigUtility::Load(string fname) {
ifstream is(fname);
if (!is.is_open()) { if (!is.is_open()) {
throw(runtime_error("Failed to open config file")); throw(std::runtime_error("Failed to open config file"));
} }
string key, val; std::string key, val;
for (;;) { //forever while(true) { //forever
//eat whitespace //eat whitespace
while(isspace(is.peek())) while(isspace(is.peek())) {
is.ignore(); is.ignore();
}
//end of file //end of file
if (is.eof()) if (is.eof()) {
break; break;
}
//skip comment lines //skip comment lines
if (is.peek() == '#') { if (is.peek() == '#') {
@@ -64,7 +64,7 @@ void ConfigUtility::Load(string fname) {
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1); while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1); while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
//allow empty/wiped values //disallow empty/wiped values
if (key.size() == 0) { if (key.size() == 0) {
continue; continue;
} }
+3 -9
View File
@@ -39,15 +39,9 @@ public:
bool Boolean(std::string); bool Boolean(std::string);
//shorthand //shorthand
std::string& operator[](std::string s) { inline std::string& operator[](std::string s) { return String(s); }
return String(s); inline int Int(std::string s) { return Integer(s); }
} inline bool Bool(std::string s) { return Boolean(s); }
int Int(std::string s) {
return Integer(s);
}
bool Bool(std::string s) {
return Boolean(s);
}
//OO breaker //OO breaker
std::map<std::string, std::string>* GetMap() { std::map<std::string, std::string>* GetMap() {