-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.cpp
More file actions
53 lines (47 loc) · 1.6 KB
/
Copy pathUtility.cpp
File metadata and controls
53 lines (47 loc) · 1.6 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
#include "Utility.h"
std::vector<int> Utility::splitStringInt(const std::string& str, const char& separator){
size_t pos = 0;
size_t start_pos = 0;
std::vector<int> result;
while((pos = str.find(separator, start_pos)) != std::string::npos){
result.push_back(std::stoi(str.substr(start_pos, pos - start_pos)));
start_pos = pos + 1;
}
result.push_back(std::stoi(str.substr(start_pos, str.length() - start_pos)));
return result;
}
std::vector<std::string> Utility::splitString(const std::string& str, const char& separator){
size_t pos = 0;
size_t start_pos = 0;
std::vector<std::string> result;
while((pos = str.find(separator, start_pos)) != std::string::npos){
result.push_back(str.substr(start_pos, pos - start_pos));
start_pos = pos + 1;
}
result.push_back(str.substr(start_pos, str.length() - start_pos));
return result;
}
char Utility::getOsSeparator(){
#if defined _WIN32 || defined __CYGWIN__
return '\\';
#else
return '/';
#endif
}
std::string Utility::getPath(std::string folder, std::string path){
#if defined _WIN32 || defined __CYGWIN__
std::string finalPath = ".\\";
finalPath += folder;
finalPath += getOsSeparator();
finalPath += path;
return finalPath;
#else
std::string finalPath = folder;
finalPath += getOsSeparator();
finalPath += path;
return finalPath;
#endif
}
bool Utility::intersect(SDL_Rect firstRect, SDL_Rect secondRect){
return SDL_HasIntersection(&firstRect,&secondRect) == SDL_TRUE ? true : false;
}