From e0142c827daaec9d827c0c236afde855ae2bec8a Mon Sep 17 00:00:00 2001 From: clyne Date: Tue, 5 Jan 2021 17:30:39 -0500 Subject: [PATCH] Create README.md --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1e82e6 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# ini-config + +A single-header library that converts INI-formatted string literals to a key-value pair list at compile-time. + +Requires C++20. Tested to work on gcc 10.1 and clang trunk. Passes `-Wall -Wextra -pedantic`. + +## Features + * Comments and whitespace removed during compilation + * Handles single-line `key=value` pairs with very basic syntax error reporting + * Supports sections + * Supports comments (start line with ';' or '#', preceding whitespace is okay) + * Supports wide strings + +## How to use +```cpp +// 1. Include +#include "ini_config.hpp" + +// 2. Use _ini suffix +auto config = R"ini( +someflag = true + +[Cat] +color = grey +lives = 9 + +)ini"_ini; + +// ... + +// Returns count of key-value pairs (KVPs), 3 in this case +config.size() +// Iterate through all KVPs using config.begin() and config.end() +for (auto kvp : config) {} +// Iterate through all KVPs under [Cat] section +for (auto kvp : config.section("Cat")) {} +``` +See the header file for further documentation. + +## How it works (brief) +1. `_ini` prefix constructs an `ini_config` object with the given string. +2. Syntax is validated, and a character array is sized to fit all section names, keys, and values. +3. The array is populated with values. +4. Compiled result is the minimized array, with efficient functions for iteration and access.