Ticket #9789: config_file.cpp.patch

File config_file.cpp.patch, 1.2 KB (added by gkorolev@…, 7 years ago)

such a solution would be appropriate?

  • config_file.cpp

     
    7676                return s.substr(n, n2-n+1);
    7777            }
    7878        }
     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        }
    7992    }
    8093
    81 
    8294    void common_config_file_iterator::get()
    8395    {
    8496        string s;
     
    8799
    88100        while(this->getline(s)) {
    89101
    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));
    94103
    95104            if (!s.empty()) {
    96105                // Handle section name