aboutsummaryrefslogblamecommitdiffstats
path: root/library/cpp/deprecated/split/delim_string_iter.cpp
blob: af418c5bfb9ddd78a5c6f78d02eec2f5292298cc (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                              
  
                           
  
                                                  

                                        
                               






                                                  
                                                                                                




                           
                                              

                             
                                                                  





                          
                                                         

                    
                                                           
                      
#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;
}