aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/split/delim_string_iter.cpp
blob: af4147c18b50f48d6d487adc0a2629f7a1bd08e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "delim_string_iter.h"

//
// TKeyValueDelimStringIter
//

void TKeyValueDelimStringIter::ReadKeyAndValue() {
    TStringBuf currentToken(*DelimIter);

    size_t pos = currentToken.find('=');
    if (pos == TString::npos) { 
        ChunkValue.Clear();
        ChunkKey = currentToken;
    } else {
        ChunkKey = currentToken.SubStr(0, pos);
        ChunkValue = currentToken.SubStr(pos + 1);
    }
}

TKeyValueDelimStringIter::TKeyValueDelimStringIter(const TStringBuf str, const TStringBuf delim)
    : DelimIter(str, delim)
{
    if (DelimIter.Valid())
        ReadKeyAndValue();
}

bool TKeyValueDelimStringIter::Valid() const {
    return DelimIter.Valid();
}

TKeyValueDelimStringIter& TKeyValueDelimStringIter::operator++() {
    ++DelimIter;
    if (DelimIter.Valid())
        ReadKeyAndValue();

    return *this;
}

const TStringBuf& TKeyValueDelimStringIter::Key() const {
    return ChunkKey;
}

const TStringBuf& TKeyValueDelimStringIter::Value() const {
    return ChunkValue;
}