From 1226366351300139f2d8b7c10fee29d744591426 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 22 Oct 2008 20:56:56 +0200 Subject: Alte Split-Funktion durch neuen Tokenizer ersetzt --- src/Common/ConfigManager.cpp | 72 ++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 39 deletions(-) (limited to 'src/Common/ConfigManager.cpp') 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 #include @@ -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 subEntry; - std::string line; + std::string line, input; + char delim; + std::vector 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 -- cgit v1.2.3