-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.cpp
More file actions
29 lines (26 loc) · 786 Bytes
/
util.cpp
File metadata and controls
29 lines (26 loc) · 786 Bytes
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
#include "util.hpp"
#include <iostream>
#include <string>
#include <vector>
namespace util {
void split(std::vector<std::string>& v, const std::string& str, char sep) {
size_t start = 0;
size_t str_len = str.size();
for (size_t i = 0; i < str_len; i++) {
if (str[i] == sep) {
v.push_back(str.substr(start, i - start));
start = i + 1;
}
}
v.push_back(str.substr(start, str_len - start));
}
std::string trim_copy(const std::string& str, const std::string& white_space) {
if (str.size() == 0) {
return "";
} else {
size_t start = str.find_first_not_of(white_space);
size_t end = str.find_last_not_of(white_space);
return str.substr(start, end - start + 1);
}
}
} // namespace util