Ticket #9789: config_file.cpp.patch
File config_file.cpp.patch, 1.2 KB (added by , 7 years ago) |
---|
-
config_file.cpp
76 76 return s.substr(n, n2-n+1); 77 77 } 78 78 } 79 80 string strip_comments(const string& s) 81 { 82 string::size_type pos = string::npos; 83 for (size_t n = 0, slashes = 0; n < s.size(); ++n) { 84 if (s[n] == '\\') { ++slashes; continue; } 85 if ((s[n] == '#' || s[n] == ';') && !(slashes % 2)) { // not escaped comment symbol 86 pos = n; break; 87 } 88 slashes = 0; 89 } 90 return (pos != string::npos) ? s.substr(0, pos) : s; 91 } 79 92 } 80 93 81 82 94 void common_config_file_iterator::get() 83 95 { 84 96 string s; … … 87 99 88 100 while(this->getline(s)) { 89 101 90 // strip '#' comments and whitespace 91 if ((n = s.find('#')) != string::npos) 92 s = s.substr(0, n); 93 s = trim_ws(s); 102 s = trim_ws(strip_comments(s)); 94 103 95 104 if (!s.empty()) { 96 105 // Handle section name