-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
28 lines (25 loc) · 760 Bytes
/
util.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
#include "util.h"
#include <sstream>
#include <cmath>
std::vector<std::string> splitPath(const std::string& path) {
char delimiter = '/';
std::vector<std::string> result;
std::istringstream iss(path);
std::string token;
while (std::getline(iss, token, delimiter)) {
result.push_back(token);
}
return result;
}
std::tuple<std::string, std::string> splitPathParent(const std::string& path) {
char delimiter = '/';
std::string::size_type pos = path.find_last_of(delimiter);
if (pos == std::string::npos) {
return std::make_tuple("", path);
}
return std::make_tuple(path.substr(0, pos), path.substr(pos + 1));
}
bool isPowerOf(int num, int base) {
double result = log(num) / log(base);
return (result - (int)result) == 0;
}