Skip to content

KvConfigParse

KvConfigParse

Description

Parse complete key-value config text into cfg.

Supported syntax:

  • key = value
  • key: value
  • blank lines
  • comments starting with # or ;
  • quoted values using ' or "

If the same key appears multiple times, the last parsed value replaces earlier ones.

Parameters

Name Direction Description
si in Input iterator.
cfg in,out Destination config map.

Success

Returns iterator advanced to end of parsed config.

Failure

Returns original iterator on first invalid line.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    StrIter KvConfigParse(StrIter si, KvConfig *cfg) {
        StrIter saved_si = si;
        );
        StrIter input  = StrIterFromStr(src);
        StrIter si     = KvConfigParse(input, &cfg);
        Str    *host   = KvConfigGetPtr(&cfg, "host");
        i64     port   = 0;
        );
        StrIter input  = StrIterFromStr(src);
        StrIter si     = KvConfigParse(input, &cfg);
        Str    *path   = KvConfigGetPtr(&cfg, "path");
        Str    *user   = KvConfigGetPtr(&cfg, "user");
        bool     result      = true;
    
        (void)KvConfigParse(input, &cfg);
    
        stored_host = KvConfigGetPtr(&cfg, "host");
        StrIter input    = StrIterFromStr(src);
    
        (void)KvConfigParse(input, &cfg);
    
        result = result && KvConfigGetI64(&cfg, "workers", &workers) && (workers == 16);
        );
        StrIter input   = StrIterFromStr(src);
        StrIter si      = KvConfigParse(input, &cfg);
        bool    enabled = false;
        bool    result  = true;
Last updated on