-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_ini.cpp
45 lines (35 loc) · 1.33 KB
/
example_ini.cpp
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
36
37
38
39
40
41
42
43
44
45
#include <c2p/ini.hpp>
#include <c2p/json.hpp>
#include <iostream>
#include <optional>
#include <vector>
const c2p::Logger logger{
// clang-format off
[](const std::string& logStr) { std::cerr << "Error: " << logStr << std::endl; },
[](const std::string& logStr) { std::cout << "Warning: " << logStr << std::endl; },
[](const std::string& logStr) { std::cout << "Info: " << logStr << std::endl; },
// clang-format on
};
int main(int argc, char* argv[]) {
const std::string ini = R"(
; comment starts with ';'
# comment starts with '#'
; allow no-section key-value pairs at the beginning
name=John Doe
age= 30
city = New York
[ section 1 ] ; allow spaces before and after section header string
email = "name\u0040fake.com" ; same as "[email protected]"
home addr = 银河系 - 太阳系 - 地球: 北极点
[""] ; allow quoted string as empty section
empty info =
empty info2 = ; allow empty value string even without quotes
; comment starts with ';'
# comment starts with '#'
"" = value of empty key ; allow quoted string as empty key)";
auto tree = c2p::ini::parse(ini, logger);
std::cout << "---------- JSON ----------" << std::endl;
std::cout << c2p::json::dump(tree, true, 4) << std::endl;
std::cout << "---------- INI ----------" << std::endl;
std::cout << c2p::ini::dump(tree) << std::endl;
}