-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.h
More file actions
90 lines (84 loc) · 2.63 KB
/
Copy pathHelpers.h
File metadata and controls
90 lines (84 loc) · 2.63 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef _HELPERSH_
#define _HELPERSH_
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class Helpers
{
public:
static vector<string> split(string s, char delim)
{
stringstream temp;
vector<string> elems(0);
if (s.size() == 0 || delim == 0)
return elems;
for (unsigned int i=0; i<s.length(); ++i)
{
char c=s[i];
if(c == delim)
{
elems.push_back(temp.str());
temp.clear();
}
else
temp << c;
}
if (temp.str().size() > 0)
elems.push_back(temp.str());
return elems;
}
//Splits string s with a list of delimiters in delims (it's just a list, like if we wanted to
//split at the following letters, a, b, c we would make delims="abc".
static vector<string> split(string s, string delims)
{
stringstream temp;
vector<string> elems(0);
bool found;
if(s.size() == 0 || delims.size() == 0)
return elems;
for (unsigned int i=0; i < s.length(); ++i)
{
char c=s[i];
char next=' ';
if(i+1<s.length())
next=s[i+1];
found = false;
for (unsigned int j=0; j<delims.length(); ++j)
{
char d=delims[j];
if(next!=' '){
if(c==d){
bool nextFound=false;
for (int k=0; k<delims.length(); ++k)
{
char d2=delims[k];
if(d2==next)
nextFound=true;
}
if(nextFound)
{
elems.push_back(temp.str());
temp.clear();
found = true;
break;
}
}
}
else if (c == d)
{
elems.push_back(temp.str());
temp.clear();
found = true;
break;
}
}
if(!found)
temp << c;
}
if(temp.str().size() > 0)
elems.push_back(temp.str());
return elems;
}
};
#endif