forked from lemire/FastPFor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringutil.h
33 lines (25 loc) · 820 Bytes
/
stringutil.h
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
/**
* This code is released under the
* Apache License Version 2.0 http://www.apache.org/licenses/.
*
* (c) Daniel Lemire, http://lemire.me/en/
*/
#ifndef STRINGUTIL_H_
#define STRINGUTIL_H_
#include "common.h"
#include "util.h"
namespace FastPForLib {
using namespace std;
std::vector<std::string> split(const std::string& str, const std::string& del) {
std::vector<std::string> tokens;
size_t lastPos = str.find_first_not_of(del, 0);
size_t pos = str.find_first_of(del, lastPos);
while (std::string::npos != pos || std::string::npos != lastPos) {
tokens.push_back(str.substr(lastPos, pos - lastPos));
lastPos = str.find_first_not_of(del, pos);
pos = str.find_first_of(del, lastPos);
}
return tokens;
}
} // namespace FastPFor
#endif /* STRINGUTIL_H_ */