AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
AnCH INI library documentation

Introduction

AnCH INI library is INI parsing library for INI format.

Prerequisites

AnCH INI is a standalone library.

Installation

CMake target anch::ini:

find_package(Anch REQUIRED)
target_link_libraries(my-app PRIVATE anch::ini)

See installation.

Conception

AnCH INI file library aims to parse INI file according to common specifications.
Comments are managed with '#' or ';' character.
Subsections are delimited by '.'.
Key which contains '.' character will create as many subsections as the number of '.' in key.
Values will be requested with their paths separated with '.'.

Examples

INI file:

# Comments
# vnjldmsv
# cdsnjkovdfmsnjom gefdbnjmvdfbnjiom
toto=tata
tata=tutu # test with comments
[TOTO]
toto=titi

Parse INI file:

void
addIndent(uint32_t indent) {
for(uint32_t i = 0 ; i < indent ; ++i) {
std::cout << ' ';
}
}
void
printSection(const anch::ini::Section& section, const std::string& name = "root", uint32_t indent = 0) {
addIndent(indent);
std::cout << '[' << name << ']' << std::endl;
for(auto iter = section.getValues().begin() ; iter != section.getValues().end() ; ++iter) {
addIndent(indent + 1);
std::cout << iter->first << '=' << iter->second << std::endl;
}
for(auto iter = section.getSections().begin() ; iter != section.getSections().end() ; ++iter) {
printSection(iter->second, iter->first, indent + 2);
}
}
int
main() {
std::cout << "Parse file" << std::endl;
anch::ini::Section section = anch::ini::parse(std::string("test.ini"));
printSection(section);
std::cout << "File has been parsed" << std::endl;
std::cout << "TOTO.toto = " << section.getValue<std::string>("TOTO.toto").value_or("<none>") << std::endl;
return 0;
}