aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorclyne <clyne@bitgloo.com>2021-01-05 18:53:16 -0500
committerGitHub <noreply@github.com>2021-01-05 18:53:16 -0500
commit2aa4d516c3f1a624c801da1aab4feb1add8cf522 (patch)
treee48369f08bc2f335c6b893a9cbce85e06d65e0da /README.md
parent7b3c3796217f92c257c92d535d2864af57c48ce2 (diff)
Improve documentation, add godbolt example
Diffstat (limited to 'README.md')
-rw-r--r--README.md23
1 files changed, 13 insertions, 10 deletions
diff --git a/README.md b/README.md
index c1e82e6..3566603 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,8 @@ A single-header library that converts INI-formatted string literals to a key-val
Requires C++20. Tested to work on gcc 10.1 and clang trunk. Passes `-Wall -Wextra -pedantic`.
+[Try it on Godbolt.](https://godbolt.org/z/K8GGov)
+
## Features
* Comments and whitespace removed during compilation
* Handles single-line `key=value` pairs with very basic syntax error reporting
@@ -13,27 +15,28 @@ Requires C++20. Tested to work on gcc 10.1 and clang trunk. Passes `-Wall -Wextr
## How to use
```cpp
-// 1. Include
#include "ini_config.hpp"
-// 2. Use _ini suffix
-auto config = R"ini(
+auto config = R"(
someflag = true
[Cat]
-color = grey
+color = gray
lives = 9
-
-)ini"_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()
+config.size();
+// Iterate through all KVPs
for (auto kvp : config) {}
// Iterate through all KVPs under [Cat] section
for (auto kvp : config.section("Cat")) {}
+// Access specific values
+config.get("someflag"); // Returns "true"
+config.get("lives"); // Searches all KVPs, returns "9"
+config["lives"]; // Same as above
+config.get("Cat", "color"); // Only searches [Cat] section, Returns "gray"
+config.get("Dog", "color"); // No match, returns ""
```
See the header file for further documentation.