17 void IniFile::parse(std::istream &inputStream)
20 enum State { Init, Comment, ScopeName, Key,
Value } state = Init;
24 unsigned int whitespace = 0;
26 string scope, key, value;
32 const auto finishKeyValue = [&state, &scope, &key, &value, &whitespace,
this] {
33 if (key.empty() && value.empty() && state !=
Value) {
36 if (m_data.empty() || m_data.back().first != scope) {
37 m_data.emplace_back(make_pair(scope, decltype(m_data)::value_type::second_type()));
39 m_data.back().second.insert(make_pair(key, value));
45 const auto addChar = [&whitespace, &c](
string &to) {
61 inputStream.exceptions(ios_base::failbit | ios_base::badbit);
64 while (inputStream.get(c)) {
137 }
catch (
const std::ios_base::failure &) {
138 if (!inputStream.eof()) {
150 void IniFile::make(ostream &outputStream)
153 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
154 for (
const auto &scope : m_data) {
155 outputStream <<
'[' << scope.first <<
']' <<
'\n';
156 for (
const auto &field : scope.second) {
157 outputStream << field.first <<
'=' << field.second <<
'\n';
159 outputStream <<
'\n';