aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils/scan/scan.h
blob: fcadeee89ca47ca385383bde3f03fda419f51493 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include <util/generic/strbuf.h>

template <bool addAll, char sep, char sepKeyVal, class F> 
static inline void ScanKeyValue(TStringBuf s, F&& f) {
    TStringBuf key, val;

    while (!s.empty()) {
        val = s.NextTok(sep); 

        if (val.empty()) {
            continue; // && case
        }

        key = val.NextTok(sepKeyVal); 

        if (addAll || val.IsInited()) {
            f(key, val); // includes empty keys
        }
    }
}