commit | 003b6b7c9e5ec978e8877959f8a8106bb60d6ac5 | [log] [tgz] |
---|---|---|
author | Evgeniy Alekseev <i@arcanis.me> | Mon Jan 23 20:33:48 2017 +0300 |
committer | Evgeniy Alekseev <i@arcanis.me> | Mon Jan 23 20:39:33 2017 +0300 |
tree | 39f747b4f9b7f645ca09f91355e2d78011f9e136 | |
parent | d4d341c6b3799476b50bec1e4a654148277cf280 [diff] |
Add Sections() method It may be useful in case if you dont know which sections present in configuration and want to iterate over all available sections. We are going to store section names in memory because there are no obvious ways to parse all stored keys and get sections from them.
This is a header only C++ version of inih.
inih (INI Not Invented Here) is a simple .INI file parser written in C. It‘s only a couple of pages of code, and it was designed to be small and simple, so it’s good for embedded systems. It‘s also more or less compatible with Python’s ConfigParser style of .INI files, including RFC 822-style multi-line syntax and name: value
entries.
All you need to do is to include INIReader.h
. Consider the following example (INIReaderTest.cpp
):
#include <iostream> #include "INIReader.h" int main() { INIReader reader("test.ini"); if (reader.ParseError() < 0) { std::cout << "Can't load 'test.ini'\n"; return 1; } std::cout << "Config loaded from 'test.ini': version=" << reader.GetInteger("protocol", "version", -1) << ", name=" << reader.Get("user", "name", "UNKNOWN") << ", email=" << reader.Get("user", "email", "UNKNOWN") << ", pi=" << reader.GetReal("user", "pi", -1) << ", active=" << reader.GetBoolean("user", "active", true) << "\n"; return 0; }
To compile and run:
g++ INIReaderTest.cpp -o INIReaderTest.out ./INIReaderTest.out # Config loaded from 'test.ini': version=6, name=Bob Smith, email=bob@smith.com, pi=3.14159, active=1