]>
description | Compile-time INI config parser in modern C++ |
owner | Clyne Sullivan |
last change | Wed, 10 Feb 2021 13:00:44 +0000 (08:00 -0500) |
A single-header library that converts INI-formatted string literals to a key-value pair list at compile-time.
Requires C++20; tested on gcc 10.1 and clang trunk. Passes -Wall -Wextra -pedantic
.
key=value
pairs (extra whitespace is okay)```cpp
// Simply place the _ini suffix at the end of your config string: constexpr auto config = R"( someflag = true
[Cat] color = gray lives = 9 )"_ini;
// Or, go for a more functional look:
//constexpr auto config = makeiniconfig
auto KVPcount = config.size(); // = 3
for (auto kvp : config) {} // Iterate through all KVPs
// (or use begin()/end())
for (auto kvp : config.section("Cat")) {} // Iterate through all KVPs under [Cat] section
// (or use begin("Cat")/end("Cat"))
config.get("someflag"); // Searches entire config for "someflag", picks first match
// This call gets compile-time evaluated to "true"
config.get("Cat", "lives"); // Searches "Cat" section, compile-time evaluated to "9"
config.get
config.tryget(argv[2]); // Same interface and behavior as get(), // use this when run-time evaluation is necessary config.trycontains("color"); // Run-time evaluated to true ``` See the header file for further documentation.
4 years ago | master | shortlog | log | tree |