-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.cpp
67 lines (55 loc) · 1.39 KB
/
core.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
64
#include <stdlib.h>
#include"core.h"
string join(const vector<string> &str, const string &separator) {
if (str.empty()) return "";
string tmp = "";
if (str.size() == 1)
return str[0];
for (int i = 0; i < str.size(); i++) {
if (i == (str.size() - 1)) {
tmp += str[i];
} else {
tmp += str[i] + separator;
}
}
return tmp;
}
vector<string> split(const string &str, const string &separator) {
vector<string> arr;
string tmp = str;
long index = 0;
while ((index = tmp.find(separator)) != str.npos) {
arr.push_back(tmp.substr(0, index));
tmp = tmp.substr(index + 1);
}
if (tmp == "") {
return arr;
}
arr.push_back(tmp);
return arr;
}
bool file_exist(const char *file) {
if (strlen(file) == 0 || file == NULL) return false;
if (!access(file, R_OK)) {
return true;
} else {
return false;
}
}
string intToString(int32_t i) {
stringstream ss;
ss << i;
return ss.str();
}
string doubleToString(double i) {
stringstream ss;
ss << i;
return ss.str();
}
double time_diff(struct timeval x, struct timeval y) {
double x_ms, y_ms, diff;
x_ms = (double) x.tv_sec * 1000000 + (double) x.tv_usec;
y_ms = (double) y.tv_sec * 1000000 + (double) y.tv_usec;
diff = (double) y_ms - (double) x_ms;
return diff/1000/1000;
}