aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils/scan/scan.h
blob: d97a4bc7c007dcaf18f974cedb43b65a87a7371d (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
        }
    }
}