forked from sAusk3/Brown_Belt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathini.cpp
More file actions
35 lines (27 loc) · 740 Bytes
/
Copy pathini.cpp
File metadata and controls
35 lines (27 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "ini.h"
namespace Ini {
Document Load(istream& input) {
Document result;
Section* current_section = nullptr;
for (string line; getline(input, line); ) {
if (!line.empty()) {
if (line[0] == '[') {
current_section = &result.AddSection(line.substr(1, line.size() - 2));
} else {
size_t eq_pos = line.find('=');
current_section->insert({line.substr(0, eq_pos), line.substr(eq_pos + 1)});
}
}
}
return result;
}
Section& Document::AddSection(string name) {
return sections[name];
}
const Section& Document::GetSection(const string& name) const {
return sections.at(name);
}
size_t Document::SectionCount() const {
return sections.size();
}
} /* namespace Ini */