-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
42 lines (35 loc) · 990 Bytes
/
util.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
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
std::vector<std::string> split(std::string s, char delimeter = ' ') {
std::istringstream iss(s);
std::vector<std::string> tokens;
std::string token;
// Use a while loop to extract space-separated tokens
//while (iss >> token) {
while (std::getline(iss, token, delimeter)) {
tokens.push_back(token);
}
return tokens;
}
// Function to split a string using a custom delimiter
std::vector<std::string> splitString(const std::string& input, char delimiter = ' ') {
std::vector<std::string> tokens;
std::string token;
for (char c : input) {
if (c == delimiter) {
if (!token.empty()) {
tokens.push_back(token);
token.clear();
}
} else {
token += c;
}
}
if (!token.empty()) {
tokens.push_back(token);
}
return tokens;
}