Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ini_stream.h"
- namespace stream
- {
- ini_stream & ini_stream::operator >> (section & section)
- {
- std::string line;
- int index = 0;
- while (std::getline(fs, line))
- {
- if (is_comment(line) || is_empty(line)) continue;
- if (is_section(line))
- {
- if (index != 0) {
- for (size_t i = 0; i <= line.length(); i++)
- {
- fs.unget();
- }
- return *this;
- }
- section.name = line.substr(1, line.size() - 2);
- ++index;
- }
- else if (is_pair(line)) {
- auto s = split(line);
- section.pairs.push_back(pair{ s[0],s[1],§ion});
- }
- }
- return *this;
- }
- std::ostream & operator<<(std::ostream & os, const section & section)
- {
- os << "[" << section.name << "]" << std::endl;
- for (auto p : section.pairs) os << p << std::endl;
- return os;
- }
- std::ostream & operator<<(std::ostream & os, const pair & pair)
- {
- return os << pair.name << "=" << pair.value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement