summaryrefslogtreecommitdiffstats
path: root/src/Common/ConfigManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/ConfigManager.cpp')
-rw-r--r--src/Common/ConfigManager.cpp72
1 files changed, 33 insertions, 39 deletions
diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp
index bfb38a0..487e901 100644
--- a/src/Common/ConfigManager.cpp
+++ b/src/Common/ConfigManager.cpp
@@ -21,7 +21,7 @@
#include "ConfigEntry.h"
#include "Configurable.h"
#include "Logger.h"
-#include "Util.h"
+#include "Tokenizer.h"
#include <fstream>
#include <stdexcept>
@@ -55,67 +55,61 @@ void ConfigManager::handleConfigEntry(const ConfigEntry &entry) {
bool ConfigManager::loadFile(const std::string &filename, bool finish) {
std::ifstream file(filename.c_str());
ConfigEntry entry;
- std::vector<std::string> subEntry;
- std::string line;
+ std::string line, input;
+ char delim;
+ std::vector<std::string> splitLine, lastConfigLine;
if(!file.good())
return false;
- while(!(file.eof() && line.empty())) {
- std::string nextLine;
- char bracket = 0;
+ while(!(file.eof() && line.empty() && input.empty())) {
+ while(input.empty() && !file.eof())
+ std::getline(file, input);
- if(line.empty()) {
- std::getline(file, line);
+ if(input.empty())
+ break;
- size_t pos = line.find_first_of('#');
- if(pos != std::string::npos)
- line = line.substr(0, pos);
-
- line = Util::trim(line);
-
- if(line.empty())
- continue;
+ size_t pos = input.find_first_of("#{}");
+ if(pos == std::string::npos) {
+ line += input;
+ delim = 0;
+ input.clear();
+ }
+ else {
+ line += input.substr(0, pos);
+ delim = input[pos];
+ input = input.substr(pos+1);
}
- size_t pos = line.find_first_of("{}");
+ if(!Tokenizer::tokenize(line, splitLine)) {
+ if(delim)
+ line += delim;
- if(pos != std::string::npos) {
- bracket = line[pos];
- line = Util::trim(line.substr(0, pos));
- try {
- nextLine = Util::trim(line.substr(pos+1));
- }
- catch(std::out_of_range& e) {}
+ continue;
}
- if(!line.empty()) {
+ if(!splitLine.empty()) {
pos = line.find_first_of(" \t");
- subEntry.clear();
-
- if(pos == std::string::npos) {
- subEntry.push_back(line);
- }
- else {
- subEntry.push_back(line.substr(0, pos));
- subEntry.push_back(Util::trim(line.substr(pos)));
- }
-
- entry.push(subEntry);
+ entry.push(splitLine);
handleConfigEntry(entry);
entry.pop();
+
+ lastConfigLine = splitLine;
}
- switch(bracket) {
+ switch(delim) {
+ case '#':
+ input.clear();
+ break;
case '{':
- entry.push(subEntry);
+ entry.push(lastConfigLine);
break;
case '}':
entry.pop();
}
- line = nextLine;
+ line.clear();
}
// TODO Depth check