-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringutil.cpp
More file actions
38 lines (33 loc) · 752 Bytes
/
stringutil.cpp
File metadata and controls
38 lines (33 loc) · 752 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
35
36
37
38
#include "stringutil.h"
namespace JGG
{
std::vector<std::string> splitstring(const std::string& srcstring, char sep)
{
std::vector<std::string> vecsep;
if (srcstring.empty())
return vecsep;
std::string::size_type pos_begin = srcstring.find_first_not_of(sep);
std::string::size_type comma_pos = 0;
std::string tmp;
while (pos_begin != std::string::npos)
{
comma_pos = srcstring.find(sep, pos_begin);
if (comma_pos != std::string::npos)
{
tmp = srcstring.substr(pos_begin, comma_pos - pos_begin);
pos_begin = comma_pos + 1;
}
else
{
tmp = srcstring.substr(pos_begin);
pos_begin = comma_pos;
}
if (!tmp.empty())
{
vecsep.push_back(tmp);
tmp.clear();
}
}
return vecsep;
}
}