Index: config_file.cpp =================================================================== --- config_file.cpp (revision 86799) +++ config_file.cpp (working copy) @@ -76,9 +76,21 @@ return s.substr(n, n2-n+1); } } + + string strip_comments(const string& s) + { + string::size_type pos = string::npos; + for (size_t n = 0, slashes = 0; n < s.size(); ++n) { + if (s[n] == '\\') { ++slashes; continue; } + if ((s[n] == '#' || s[n] == ';') && !(slashes % 2)) { // not escaped comment symbol + pos = n; break; + } + slashes = 0; + } + return (pos != string::npos) ? s.substr(0, pos) : s; + } } - void common_config_file_iterator::get() { string s; @@ -87,10 +99,7 @@ while(this->getline(s)) { - // strip '#' comments and whitespace - if ((n = s.find('#')) != string::npos) - s = s.substr(0, n); - s = trim_ws(s); + s = trim_ws(strip_comments(s)); if (!s.empty()) { // Handle section name