Introduction
AnCH INI library is INI parsing library for INI format.
Prerequisites
AnCH INI is a standalone library.
Installation
make install
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;
}
printSection(iter->second, iter->first, indent + 2);
}
}
void
parse() {
std::cout << "Parse file" << std::endl;
std::string file = "test.ini";
section = anch::ini::parse(file);
printSection(section);
std::cout << "File has been parsed" << std::endl;
std::cout <<
"TOTO.toto = " << section.
getValue(
"TOTO.toto") << std::endl;
}
INI file section.
Definition section.hpp:39
static std::optional< std::string > getValue(const std::string &path, const Section §ion)
const std::map< std::string, std::string > & getValues() const
const std::map< std::string, Section > & getSections() const