-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathStringUtils.h
36 lines (29 loc) · 970 Bytes
/
StringUtils.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
#pragma once
#include <string>
#include <algorithm>
// Trim from start (in place)
static inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !isspace(ch); }));
}
// Trim from end (in place)
static inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !isspace(ch); }).base(), s.end());
}
// Trim from both ends (in place)
static inline void trim(std::string &s) {
ltrim(s);
rtrim(s);
}
// Trim from start (in place)
static inline void ltrim(std::wstring &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](wchar_t ch) { return !iswspace(ch); }));
}
// Trim from end (in place)
static inline void rtrim(std::wstring &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](wchar_t ch) { return !iswspace(ch); }).base(), s.end());
}
// Trim from both ends (in place)
static inline void trim(std::wstring &s) {
ltrim(s);
rtrim(s);
}