summaryrefslogtreecommitdiffstats
path: root/vbench/src/vbench/core/string.cpp
blob: 00e02398fd0a1b624adbb928d1ffd21531390c0c (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
46
47
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "string.h"

#if USE_VESPA_STRING
#include <vespa/vespalib/util/vstringfmt.h>
#else
#include <vespa/vespalib/util/stringfmt.h>
#endif

namespace vbench {

string strfmt(const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
#if USE_VESPA_STRING
    string ret = vespalib::make_vespa_string_va(fmt, ap);
#else
    string ret = vespalib::make_string_va(fmt, ap);
#endif
    va_end(ap);
    return ret;
}

size_t splitstr(const string &str, const string &sep,
                std::vector<string> &dst)
{
    dst.clear();
    string tmp;
    for (size_t i = 0; i < str.size(); ++i) {
        if (sep.find(str[i]) != string::npos) {
            if (!tmp.empty()) {
                dst.push_back(tmp);
                tmp.clear();
            }
        } else {
            tmp.push_back(str[i]);
        }
    }
    if (!tmp.empty()) {
        dst.push_back(tmp);
    }
    return dst.size();
}

} // namespace vbench