| 152 | } |
| 153 | |
| 154 | void common_config_file_iterator::get() |
| 155 | { |
| 156 | std::string s; |
| 157 | std::string::size_type n; |
| 158 | bool found = false; |
| 159 | |
| 160 | while (this->getline(s)) |
| 161 | { |
| 162 | |
| 163 | // strip '#' comments and whitespace |
| 164 | if (s.find('#') == s.find_first_not_of(" \t\r\n")) |
| 165 | continue; |
| 166 | s = trim_ws(s); |
| 167 | |
| 168 | if (!s.empty()) |
| 169 | { |
| 170 | // Handle section name |
| 171 | if (*s.begin() == '[' && *s.rbegin() == ']') |
| 172 | { |
| 173 | m_prefix = s.substr(1, s.size() - 2); |
| 174 | if (*m_prefix.rbegin() != '.') |
| 175 | m_prefix += '.'; |
| 176 | } |
| 177 | else if ((n = s.find('=')) != std::string::npos) |
| 178 | { |
| 179 | |
| 180 | std::string name = m_prefix + trim_ws(s.substr(0, n)); |
| 181 | std::string value = trim_ws(s.substr(n + 1)); |
| 182 | |
| 183 | bool registered = allowed_option(name); |
| 184 | if (!registered && !m_allow_unregistered) |
| 185 | boost::throw_exception(bpo::unknown_option(name)); |
| 186 | |
| 187 | found = true; |
| 188 | this->value().string_key = name; |
| 189 | this->value().value.clear(); |
| 190 | this->value().value.push_back(value); |
| 191 | this->value().unregistered = !registered; |
| 192 | this->value().original_tokens.clear(); |
| 193 | this->value().original_tokens.push_back(name); |
| 194 | this->value().original_tokens.push_back(value); |
| 195 | break; |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | boost::throw_exception( |
| 200 | bpo::invalid_config_file_syntax(s, bpo::invalid_syntax::unrecognized_line)); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | if (!found) |
| 205 | found_eof(); |
| 206 | } |
| 207 | |
| 208 | bool common_config_file_iterator::allowed_option(const std::string& s) const |
| 209 | { |