-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.h
52 lines (40 loc) · 1.34 KB
/
functions.h
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
/* Create a unique number for each file */
unsigned long long idGenerator() {
std::random_device rd;
std::default_random_engine generator(rd());
/* 1 is reserved for the root */
std::uniform_int_distribution<long long unsigned> distribution(2,0xFFFFFFFFFFFFFFF);
return distribution(generator);
}
/* Find parent path given a path */
std::string parent_path(std::string path_name) {
std::string parent_path = path_name.substr(0, path_name.find_last_of("/"));
/* If empty, parent is the root */
if (parent_path == "") {
parent_path = "/";
}
return parent_path;
}
/* Find file name given full path */
std::string file_name(std::string path_name) {
std::string file_name = path_name.substr(path_name.find_last_of("/") + 1);
return file_name;
}
/* Converts vector to ASCII string */
std::string asciify(std::vector<auto> const &vec) {
std::string fullString;
for (int i = 1; i < vec.size(); i++) {
fullString += static_cast<char>(vec[i]);
}
while(!std::isdigit(fullString[0])) {
fullString = fullString.substr(1);
}
return fullString;
}
/* Checks if path_name is root */
bool is_root(std::string path_name) {
if (path_name == "/") {
return true;
}
return false;
}