-
Notifications
You must be signed in to change notification settings - Fork 4
/
strtools.cpp
63 lines (59 loc) · 1 KB
/
strtools.cpp
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 "strtools.h"
using std::vector;
char *r_strip(char* &str)
{
if (NULL == str)
{
return NULL;
}
char *p = str + strlen(str) - 1;
char filter_chs[] = " \t\n";
while (p >= str && strchr(filter_chs, *p))
{
*p-- = 0;
}
return str;
}
char *l_strip(char* &str)
{
if (NULL == str)
{
return NULL;
}
char *p = str;
char filter_chs[] = " \t\n";
while (*p && strchr(filter_chs, *p))
{
*p++ = 0;
}
str = p;
return str;
}
char *strip(char* &str)
{
r_strip(str);
l_strip(str);
return str;
}
void split(std::vector<char *> &list, char *str, char sep)
{
list.clear();
if (NULL == str)
{
return ;
}
char *begin = str;
char *end = strchr(begin, sep);
while (end)
{
list.push_back(begin);
*end++ = 0;
begin = end;
end = strchr(begin, sep);
}
list.push_back(begin);
if (end = strchr(begin, '\n'))
{
*end = 0;
}
}