-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstrutil.h
51 lines (38 loc) · 1.04 KB
/
strutil.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
43
44
45
46
47
48
49
50
51
#pragma once
void rtrimwsv(std::wstring_view& sv)
{
size_t end = sv.find_last_not_of(L' ');
if (end != std::wstring_view::npos)
sv.remove_suffix(sv.size() - end - 1);
}
// https://www.bfilipek.com/2018/07/string-view-perf-followup.html
std::vector<std::wstring_view> splitwsv(std::wstring_view strv, wchar_t delim = L' ')
{
std::vector<std::wstring_view> output;
size_t first = 0;
while (first < strv.size())
{
const auto second = strv.find_first_of(delim, first);
if (first != second)
output.emplace_back(strv.substr(first, second - first));
if (second == std::string_view::npos)
break;
first = second + 1;
}
return output;
}
std::vector<std::wstring> splitws(std::wstring_view strv, wchar_t delim = L' ')
{
std::vector<std::wstring> output;
size_t first = 0;
while (first < strv.size())
{
const auto second = strv.find_first_of(delim, first);
if (first != second)
output.emplace_back(strv.substr(first, second - first));
if (second == std::string_view::npos)
break;
first = second + 1;
}
return output;
}