33 bool parse(
const std::string& filename)
35 std::ifstream file(filename);
38 grklog.debug(
"Failed to open file: %s", filename.c_str());
42 std::string current_section;
44 while(std::getline(file, line))
47 line.erase(0, line.find_first_not_of(
" \t"));
48 line.erase(line.find_last_not_of(
" \t") + 1);
51 if(line.empty() || line[0] ==
';' || line[0] ==
'#')
55 if(line[0] ==
'[' && line.back() ==
']')
57 current_section = line.substr(1, line.size() - 2);
63 size_t eq_pos = line.find(
'=');
64 if(eq_pos != std::string::npos)
66 std::string key = line.substr(0, eq_pos);
67 std::string value = line.substr(eq_pos + 1);
69 key.erase(0, key.find_first_not_of(
" \t"));
70 key.erase(key.find_last_not_of(
" \t") + 1);
71 value.erase(0, value.find_first_not_of(
" \t"));
72 value.erase(value.find_last_not_of(
" \t") + 1);
73 if(!current_section.empty() && !key.empty())
75 sections[current_section][key] = value;