|
a |
|
b/src/Common/Utils.cc |
|
|
1 |
/*
|
|
|
2 |
* Utils.cpp
|
|
|
3 |
*
|
|
|
4 |
* Created on: Mar 5, 2015
|
|
|
5 |
* Author: gaixas1
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
#include <Utils.h>
|
|
|
9 |
#include <algorithm>
|
|
|
10 |
|
|
|
11 |
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
|
|
|
12 |
std::stringstream ss(s);
|
|
|
13 |
std::string item;
|
|
|
14 |
while (std::getline(ss, item, delim)) {
|
|
|
15 |
elems.push_back(item);
|
|
|
16 |
}
|
|
|
17 |
return elems;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
std::vector<std::string> split(const std::string &s, char delim) {
|
|
|
21 |
std::vector<std::string> elems;
|
|
|
22 |
split(s, delim, elems);
|
|
|
23 |
return elems;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
std::string join(const std::vector<std::string> &elems, const unsigned int n, const char delim) {
|
|
|
27 |
std::string s = "";
|
|
|
28 |
char d[2] = {delim, 0};
|
|
|
29 |
|
|
|
30 |
for(unsigned int i = 0; i < elems.size() && i<n; i++){
|
|
|
31 |
if(i>0){
|
|
|
32 |
s.append(d);
|
|
|
33 |
}
|
|
|
34 |
s.append(elems.at(i));
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
return s;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
bool isPrefix(std::string prefix, std::string s) {
|
|
|
41 |
if(prefix.size() > s.size()) {
|
|
|
42 |
return false;
|
|
|
43 |
}
|
|
|
44 |
return std::mismatch(prefix.begin(), prefix.end(), s.begin()).first == prefix.end();
|
|
|
45 |
}
|