45 bool load(
const std::string& path) {
46 std::ifstream file(path);
47 if (!file.is_open()) {
54 while (std::getline(file, line)) {
57 if (!line.empty() && line.back() ==
'\r') line.pop_back();
59 std::string content = strip_inline_comment(line);
60 content = trim(content);
61 if (content.empty())
continue;
64 if (content.front() ==
'[') {
65 if (content.back() !=
']') {
66 throw std::runtime_error(
"INI parse error at line " + std::to_string(line_no) +
67 ": malformed section header");
69 section = trim(content.substr(1, content.size() - 2));
74 std::size_t eq = content.find(
'=');
75 if (eq == std::string::npos) {
76 throw std::runtime_error(
"INI parse error at line " + std::to_string(line_no) +
77 ": expected 'key = value'");
79 std::string key = trim(content.substr(0, eq));
80 std::string value = unquote(trim(content.substr(eq + 1)));
82 throw std::runtime_error(
"INI parse error at line " + std::to_string(line_no) +
85 std::string full_key = section.empty() ? key : (section +
"." + key);
86 values_[full_key] = value;