aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/split.cpp
blob: 7d26857cc7acda0c75c3ba02af845a04d9d58922 (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
#include "split.h"

template <class TValue>
inline size_t Split(const char* ptr, const char* delim, TVector<TValue>& values) {
    values.erase(values.begin(), values.end());
    while (ptr && *ptr) {
        ptr += strspn(ptr, delim);
        if (ptr && *ptr) {
            size_t epos = strcspn(ptr, delim);
            assert(epos);
            values.push_back(TValue(ptr, epos));
            ptr += epos;
        }
    }
    return values.size();
}

size_t Split(const char* ptr, const char* delim, TVector<TString>& values) {
    return Split<TString>(ptr, delim, values);
}

size_t Split(const TString& in, const TString& delim, TVector<TString>& res) {
    return Split(in.data(), delim.data(), res);
}