18 void IniFile::parse(std::istream &inputStream)
21 enum State { Init, Comment, ScopeName, Key,
Value } state = Init;
25 unsigned int whitespace = 0;
27 string scope, key, value;
33 const auto finishKeyValue = [&state, &scope, &key, &value, &whitespace,
this] {
34 if (key.empty() && value.empty() && state !=
Value) {
37 if (m_data.empty() || m_data.back().first != scope) {
38 m_data.emplace_back(make_pair(scope, decltype(m_data)::value_type::second_type()));
40 m_data.back().second.insert(make_pair(key, value));
46 const auto addChar = [&whitespace, &c](
string &to) {
62 inputStream.exceptions(ios_base::failbit | ios_base::badbit);
65 while (inputStream.get(c)) {
140 if (inputStream.eof()) {
153 void IniFile::make(ostream &outputStream)
156 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
157 for (
const auto &scope : m_data) {
158 outputStream <<
'[' << scope.first <<
']' <<
'\n';
159 for (
const auto &field : scope.second) {
160 outputStream << field.first <<
'=' << field.second <<
'\n';
162 outputStream <<
'\n';
CPP_UTILITIES_EXPORT void throwIoFailure(const char *what)
Throws an std::ios_base::failure with the specified message.
Contains utility classes helping to read and write streams.
CPP_UTILITIES_EXPORT const char * catchIoFailure()
Provides a workaround for GCC Bug 66145.