KvConfig
KvConfig
Description
Key-value configuration map.
Duplicate keys are resolved with last-write-wins semantics during parsing.
Usage example (from documentation)
KvConfig cfg = KvConfigInit();
Str text = StrInitFromZstr("host = localhost\nport = 8080\n");
StrIter si = KvConfigParse(StrIterFromStr(text), &cfg);
Str *host_ptr = KvConfigGetPtr(&cfg, "host");
Str host = KvConfigGet(&cfg, "host");
i64 port = 0;
KvConfigGetI64(&cfg, "port", &port);
StrDeinit(&host);Usage example (Cross-references)
Usage examples (Cross-references)
- In
KvConfig.c:1:
#include <Misra/Parsers/KvConfig.h>
#include <Misra/Std/Container/Map/Private.h>
#include <Misra/Std/Memory.h>- In
KvConfig.c:342:
}
StrIter KvConfigParse(StrIter si, KvConfig *cfg) {
StrIter saved_si = si;- In
KvConfig.c:346:
if (!cfg) {
LOG_ERROR("Expected valid KvConfig object");
return si;
}- In
KvConfig.c:401:
}
Str *KvConfigGetPtr(KvConfig *cfg, const char *key) {
Str lookup = {0};
Str *value = NULL;- In
KvConfig.c:423:
}
Str KvConfigGet(KvConfig *cfg, const char *key) {
Str *value = KvConfigGetPtr(cfg, key);- In
KvConfig.c:433:
}
bool KvConfigContains(KvConfig *cfg, const char *key) {
return KvConfigGetPtr(cfg, key) != NULL;
}- In
KvConfig.c:437:
}
bool KvConfigGetBool(KvConfig *cfg, const char *key, bool *value) {
Str *str = KvConfigGetPtr(cfg, key);- In
KvConfig.c:447:
}
bool KvConfigGetI64(KvConfig *cfg, const char *key, i64 *value) {
Str *str = KvConfigGetPtr(cfg, key);- In
KvConfig.c:457:
}
bool KvConfigGetF64(KvConfig *cfg, const char *key, f64 *value) {
Str *str = KvConfigGetPtr(cfg, key);- In
Parse.c:1:
#include <Misra/Parsers/KvConfig.h>
#include <Misra/Std/Io.h>- In
Parse.c:7:
static bool test_kvconfig_basic_parse(void) {
KvConfig cfg = KvConfigInit();
Str src = StrInitFromZstr(
"host = localhost\n"- In
Parse.c:33:
static bool test_kvconfig_comments_quotes_and_duplicates(void) {
KvConfig cfg = KvConfigInit();
Str src = StrInitFromZstr(
"# comment line\n"- In
Parse.c:64:
static bool test_kvconfig_get_returns_copy(void) {
KvConfig cfg = KvConfigInit();
Str src = StrInitFromZstr("host = localhost\n");
StrIter input = StrIterFromStr(src);- In
Parse.c:95:
static bool test_kvconfig_numeric_and_bool_accessors(void) {
KvConfig cfg = KvConfigInit();
Str src = StrInitFromZstr(
"workers = 16\n"- In
Parse.c:126:
static bool test_kvconfig_invalid_line_fails(void) {
KvConfig cfg = KvConfigInit();
Str src = StrInitFromZstr(
"valid = yes\n"- In
Parse.c:155:
};
WriteFmt("[INFO] Starting KvConfig.Parse tests\n\n");
return run_test_suite(tests, (int)(sizeof(tests) / sizeof(tests[0])), NULL, 0, "KvConfig.Parse");
}- In
Parse.c:156:
WriteFmt("[INFO] Starting KvConfig.Parse tests\n\n");
return run_test_suite(tests, (int)(sizeof(tests) / sizeof(tests[0])), NULL, 0, "KvConfig.Parse");
}- In
Misra.h:9:
#include <Misra/Parsers/JSON.h>
#include <Misra/Parsers/KvConfig.h>
#include <Misra/Std.h>
#include <Misra/Sys.h>- In
KvConfig.h:175:
/// FAILURE : Returns original iterator on first invalid line.
///
StrIter KvConfigParse(StrIter si, KvConfig *cfg);
///
- In
KvConfig.h:186:
/// FAILURE : Empty `Str` if key does not exist.
///
Str KvConfigGet(KvConfig *cfg, const char *key);
///
- In
KvConfig.h:197:
/// FAILURE : `NULL` if key does not exist.
///
Str *KvConfigGetPtr(KvConfig *cfg, const char *key);
///
- In
KvConfig.h:208:
/// FAILURE : `false`
///
bool KvConfigContains(KvConfig *cfg, const char *key);
///
- In
KvConfig.h:222:
/// FAILURE : `false`
///
bool KvConfigGetBool(KvConfig *cfg, const char *key, bool *value);
///
- In
KvConfig.h:234:
/// FAILURE : `false`
///
bool KvConfigGetI64(KvConfig *cfg, const char *key, i64 *value);
///
- In
KvConfig.h:246:
/// FAILURE : `false`
///
bool KvConfigGetF64(KvConfig *cfg, const char *key, f64 *value);
#endif // MISRA_PARSERS_KVCONFIG_H
Last updated on