-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsplit_11.cpp
More file actions
63 lines (53 loc) · 1.5 KB
/
split_11.cpp
File metadata and controls
63 lines (53 loc) · 1.5 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
#include <vector>
using namespace std;
namespace detail {
////////////////////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////////////////////
template <typename Seperator>
auto split_aux(string const& val, Seperator&& sep) -> vector<string>
{
vector<string> result;
string::size_type p = 0, q;
while ((q = sep(val, p)) != string::npos)
{
result.emplace_back(val, p, q - p);
p = q + 1;
}
result.emplace_back(val, p);
return result;
}
////////////////////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////////////////////
}
auto split(string const& val, char sep) -> vector<string>
{
return detail::split_aux(val,
[=](string const& v, string::size_type p) { return v.find(sep, p); });
}
auto split(string const& val, string const& seps) -> vector<string>
{
return detail::split_aux(val,
[&](string const& v, string::size_type p) {
return v.find_first_of(seps, p);
});
}
int main(int argc, const char *argv[])
{
auto s0 = "/var/mobile/Applications/Kakao/Kakao.sqlite";
auto v0 = split(s0, '/');
cout << "size: " << v0.size() << endl;
for (auto elem: v0) cout << elem << endl;
auto s1 = "|var/mobile|Applications/Kakao|Kakao.sqlite";
auto v1 = split(s1, "|/");
cout << "size: " << v1.size() << endl;
for (auto elem: v1) cout << elem << endl;
return 0;
}