-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtils.h
More file actions
34 lines (29 loc) · 818 Bytes
/
Copy pathStringUtils.h
File metadata and controls
34 lines (29 loc) · 818 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
30
31
32
33
34
#pragma once
#include <algorithm>
#include <cctype>
#include <locale>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
// trim from start (in place)
inline void ltrim(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
}
// trim from end (in place)
inline void rtrim(std::string& s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
inline std::vector<std::string> split(const std::string& str, char delimiter) {
std::istringstream iss(str);
std::vector<std::string> tokens;
std::string token;
while (std::getline(iss, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}