Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ortfero/confetti
C++17 one-header library to parse ini files with toml extensions
https://github.com/ortfero/confetti
Last synced: 3 months ago
JSON representation
C++17 one-header library to parse ini files with toml extensions
- Host: GitHub
- URL: https://github.com/ortfero/confetti
- Owner: ortfero
- License: mit
- Created: 2020-04-07T12:01:40.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T17:43:28.000Z (almost 3 years ago)
- Last Synced: 2024-08-01T00:41:13.593Z (6 months ago)
- Language: C++
- Homepage:
- Size: 215 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesomecpp - confetti - - C++17 one-header library to parse ini files with toml extensions. (Configuration)
README
# confetti
C++17 one-header library to parse ini files with some toml extensions.
## Info
* Support for arrays, tables, inline tables
* Keys and section names are case insensitive (downcased)
* Keys are ASCII-only, but values can be UTF-8
* Zero allocation parser
* No dependencies## Snippets
### Open config
```cpp
#include
#includeint main() {
confetti::result const parsed = confetti::parse("example.ini");
if(!parsed) {
std::printf("Error at line %d: %s\n",
parsed.line_no,
parsed.error_code.message().data());
return -1;
}return 0;
}
```### Read basic properties
```cpp
#include
#includeint main() {
confetti::result const parsed = confetti::parse_text(
"a = -1\n"
"b = 3.14\n"
"c = value\n"
"d = 'string value'\n"
"e = false\n");
if(!parsed)
return -1;
confetti::value const& section = parsed.config["default"];
std::optional const a = section["a"] | 0;
std::optional const b = section["b"] | 0.0;
std::optional const c = section["c"] | "";
std::optional const d = section["d"] | "";
std::optional const e = section["e"] | false;
return 0;
}
```### Read arrays
```cpp
#include
#include
#includeint main() {
confetti::result const parsed = confetti::parse_text(
"[section]\n"
"data = [1, 2, 3, 4]\n"
);
if(!parsed)
return -1;
confetti::value const& section = parsed.config["section"];
std::optional> const data = section["data"] | std::vector{};
return 0;
}
```### Read tables
```cpp
#include
#includeint main() {
confetti::result const parsed = confetti::parse_text(
"[gods]\n"
"anubis = {name = 'Anubis', sex = male}\n"
);
if(!parsed)
return -1;
confetti::value const& gods = parsed.config["gods"];
confetti::value const& anubis = gods["anubis"];
std::optional const name = anubis["name"] | "";
std::optional const sex = anubis["sex"] | "";
return 0;
}
```### Check section contains property
```cpp
#includeint main() {
confetti::result const parsed = confetti::parse_text("");
if(!parsed)
return -1;
bool const key_exists = parsed.config["default"].contains("key");
return 0;
}
```## Tests
To build tests:
```shell
cd confetti
mkdir build
cd build
meson ../tests
ninja
```## Installation
Drop `confetti/*` somewhere at include path.
## Supported platforms and compilers
confetti requires C++ 17 compiler.
## License
confetti licensed under [MIT license](https://opensource.org/licenses/MIT).