summaryrefslogtreecommitdiff
path: root/src/utils.cpp
blob: d960ad29d0f7bc48d086d7af44e3d05af5a06dc4 (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
#include <utils.h>

namespace newsbeuter {

std::vector<std::string> utils::tokenize_config(const std::string& str, std::string delimiters) {
	std::vector<std::string> tokens = tokenize(str,delimiters);
	for (std::vector<std::string>::iterator it=tokens.begin();it!=tokens.end();++it) {
		if ((*it)[0] == '#') {
			tokens.erase(it,tokens.end());
			break;
		}
	}
	return tokens;
}
	
std::vector<std::string> utils::tokenize(const std::string& str, std::string delimiters) {
    std::vector<std::string> tokens;
    std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
    std::string::size_type pos = str.find_first_of(delimiters, last_pos);

    while (std::string::npos != pos || std::string::npos != last_pos) {
            tokens.push_back(str.substr(last_pos, pos - last_pos));
            last_pos = str.find_first_not_of(delimiters, pos);
            pos = str.find_first_of(delimiters, last_pos);
    }
    return tokens;
}


}