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)) {
141 if(inputStream.eof()) {
154 void IniFile::make(ostream &outputStream)
157 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
158 for(
const auto &scope : m_data) {
159 outputStream <<
'[' << scope.first <<
']' <<
'\n';
160 for(
const auto &field : scope.second) {
161 outputStream << field.first <<
'=' << field.second <<
'\n';
163 outputStream <<
'\n';
CPP_UTILITIES_EXPORT void throwIoFailure(const char *what)
Throws a 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.