std::string line;
std::string section;
- while (std::getline(file,line)) {
+ while (std::getline(file,line, '\n')) {
if (!line.length() || line[0] == '#' || line[0] == ';' || line[0] == '{') {
+ line.clear();
continue;
}
-// else if (line[0] == '#') {
-// continue;
-// } else if (line[0] == ';') {
-// continue;
-// }
-
-
if (line[0] =='[') { //section
auto sectionEnd = line.find(']');
if (sectionEnd == std::string::npos) {
mdclog_write(MDCLOG_ERR, "Error section definition: %s ", line.c_str());
section.clear();
return -1;
-// continue;
}
section = line.substr(1, sectionEnd - 1) + ".";
+ section = trim(section);
+ line.clear();
continue;
}
if (mdclog_level_get() >= MDCLOG_INFO) {
auto leftHand = line.find('=');
if (leftHand == std::string::npos) {
mdclog_write(MDCLOG_ERR, "problematic entry: %s no equal sign", line.c_str());
+ line.clear();
continue;
}
-// auto name = line.substr(0,leftHand);
-// trim(name);
auto name = section + trim(line.substr(0, leftHand));
auto value = line.substr(leftHand + 1);
if (value.length() == 0) {
mdclog_write(MDCLOG_ERR, "problematic entry: %s no value ", line.c_str());
+ line.clear();
continue;
-
}
- trim(value);
+ line.clear();
+
+ value = trim(value);
if (mdclog_level_get() >= MDCLOG_INFO) {
mdclog_write(MDCLOG_INFO, "entry = %s value = %s", name.c_str(), value.c_str());
}
return str;
}
- inline static std::string& trim(basic_string<char> str, const std::string& chars = "\t\n\v\f\r ") {
+ inline static std::string& trim(std::string str, const std::string& chars = "\t\n\v\f\r ") {
return ltrim(rtrim(str, chars), chars);
}
};