-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfire_utils.h
54 lines (41 loc) · 1.25 KB
/
fire_utils.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
51
52
53
54
#define LINUX
#include <fstream>
#include <iostream>
//win
// #include <direct.h>
// #define OS_SEP "\\"
//linux
#ifdef LINUX
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#define OS_SEP "/"
#endif
static inline bool endsWith(const std::string& str, const std::string& end){
int src_len = str.size();
int end_len = end.size();
if(src_len >= end_len){
std::string temp = str.substr(src_len - end_len, end_len);
if(temp == end)
return true;
}
return false;
}
static inline void strReplace( std::string &str_origin, const std::string &str_src, const std::string &str_dst){
std::string::size_type pos = 0;
std::string::size_type src_len = str_src.size();
std::string::size_type dst_len = str_dst.size();
while( (pos=str_origin.find(str_src, pos)) != std::string::npos ){
str_origin.replace( pos, src_len, str_dst );
pos += dst_len;
}
}
static inline std::string getBasename(std::string path){
if (path.empty()){
return "";
}
// strReplace(path, "/", "\\");
// std::string::size_type iPos = path.find_last_of('\\') + 1;
std::string::size_type iPos = path.find_last_of(OS_SEP) + 1;
return path.substr(iPos, path.length() - iPos);
}