-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfileinfo.h
132 lines (106 loc) · 2.83 KB
/
fileinfo.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef HTTP_FILEINFO_H
#define HTTP_FILEINFO_H
#include "common.h"
namespace openrc {
/**
* @brief File class.
*/
class FileInfo
{
public:
FileInfo(const std::string& path)
: _path(path)
{}
FileInfo(const FileInfo& file)
: _path(file._path)
{}
std::string Extenstion()
{
int32 sep = _path.rfind('.');
if(sep == -1)
return "";
return std::string(_path.begin() + sep + 1, _path.end());
}
int32 Contain(const std::string& text)
{
return _path.find(text);
}
std::string GetDirectory()
{
int32 sep = _path.rfind('/');
#ifdef _WIN32
int32 s0 = _path.rfind('\\');
if(s0 > sep)
sep = s0;
#endif
if(sep == -1)
return _path;
return std::string(_path.begin(), _path.begin() + sep);
}
std::string GetName()
{
int32 sep = _path.rfind('/');
#ifdef _WIN32
int32 s0 = _path.rfind('\\');
if(s0 > sep)
sep = s0;
#endif
if(sep == -1)
return _path;
return std::string(_path.begin() + sep + 1, _path.end());
}
std::string GetShortName()
{
int32 sep = _path.rfind('/');
#ifdef _WIN32
int32 s0 = _path.rfind('\\');
if(s0 > sep)
sep = s0;
#endif
int32 eInd = _path.rfind('.');
if(sep == -1 || eInd < sep)
return std::string(_path.begin() + sep + 1, _path.end());
return std::string(_path.begin() + sep + 1, _path.begin() + eInd);
}
bool IsFiltered(const std::string& filter)
{
int32 sep = filter.rfind('/');
#ifdef _WIN32
int32 s0 = filter.rfind('\\');
if(s0 > sep)
sep = s0;
#endif
int32 eInd = filter.rfind('.');
if(eInd != -1 || eInd > sep)
{
std::string filterExtension = std::string(_path.begin() + sep + 1, _path.end());
if(filterExtension != "*" && filterExtension != Extenstion())
return false;
}
std::string filterName = std::string(_path.begin() + sep + 1, _path.begin() + eInd);
if(filterName != "*" && filterName != GetShortName())
return false;
if(sep != -1 )
{
std::string filterPath = std::string(_path.begin() + sep + 1, _path.begin() + eInd);
if(filterPath != GetDirectory())
return false;
}
return true;
}
// Operators.
FileInfo& operator = (const FileInfo& file)
{
_path = file._path;
return (*this);
}
// Inline methods.
const std::string& GetFullPath() const {return _path;}
// Static methods.
static time_t LastModifiedTime(const std::string& path);
static bool IsExist(const std::string& path);
protected:
std::string _path;
};
} // End http.
#endif // FILEINFO_H