Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcmtroffaes/inipp
Simple C++ ini parser.
https://github.com/mcmtroffaes/inipp
configparser cpp header-only ini parser parsing python-configparser simple
Last synced: 12 days ago
JSON representation
Simple C++ ini parser.
- Host: GitHub
- URL: https://github.com/mcmtroffaes/inipp
- Owner: mcmtroffaes
- License: mit
- Created: 2017-05-09T18:54:58.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-24T09:45:13.000Z (about 2 months ago)
- Last Synced: 2024-10-12T20:43:07.860Z (about 1 month ago)
- Topics: configparser, cpp, header-only, ini, parser, parsing, python-configparser, simple
- Language: C++
- Homepage:
- Size: 101 KB
- Stars: 273
- Watchers: 12
- Forks: 53
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# IniPP
Simple header-only C++ ini parser and generator.
[![Build Status](https://github.com/mcmtroffaes/inipp/actions/workflows/build.yml/badge.svg)](https://github.com/mcmtroffaes/inipp/actions/workflows/build.yml)
## Features
* Header-only.
* Both parsing and generating.
* Wide character support for native unicode on Windows.
* Default section support (similar to Python's ConfigParser).
* Interpolation support (i.e. variable substitution, similar to Python's ConfigParser).
* Trailing comments support.
* Simple design and implementation.
* Permissive MIT license.## Example
```cpp
#include
#include "inipp.h"int main() {
inipp::Ini ini;
std::ifstream is("example.ini");
ini.parse(is);
std::cout << "raw ini file:" << std::endl;
ini.generate(std::cout);
ini.strip_trailing_comments();
ini.default_section(ini.sections["DEFAULT"]);
ini.interpolate();
std::cout << "ini file after default section and interpolation:" << std::endl;
ini.generate(std::cout);
int compression_level = -1;
inipp::get_value(ini.sections["bitbucket.org"], "CompressionLevel", compression_level);
std::cout << "bitbucket.org compression level: " << compression_level << std::endl;
return 0;
}
```To include in a cmake project:
```
FetchContent_Declare(inipp GIT_REPOSITORY https://github.com/mcmtroffaes/inipp.git)
FetchContent_MakeAvailable(inipp)
target_link_libraries(MyTarget PRIVATE inipp::inipp)
```## Parsing algorithm
* The *section* is set to the empty string.
* Every *line* is read from the file and trimmed from whitespace.
* If *line* is empty or starts with ``;`` then nothing happens.
* Otherwise, if *line* starts with ``[`` then *section* is changed
to the string between ``[`` and ``]``. If *line* does not end
with ``]`` then an error is reported.* Otherwise, if *line* contains an ``=`` sign, then all characters
before ``=`` are treated as *variable* and all characters
following ``=`` are treated as *value*. Both are trimmed. If the
variable was already assigned earlier, an error is
reported. Otherwise, the corresponding assigment is added to the
*section*.* Otherwise, the *line* is reported as an error.
## Default section algorithm
Insert every variable from the default section into every other section, without overwriting existing variables.
## Interpolation algorithm
1. Locally within each section, every occurrence "${variable}" is replaced by "${section:variable}".
2. Every occurrence of "${section:variable}" is replaced by its value.
3. The previous step is repeated until no more replacements are possible, or until the recursion depth (by default, 10) is reached.