join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
filesystem.hpp
Go to the documentation of this file.
1
25#ifndef __JOIN_FILESYSTEM_HPP__
26#define __JOIN_FILESYSTEM_HPP__
27
28// C++.
29#include <string>
30
31namespace join
32{
38 __inline__ std::string base (const std::string& filepath)
39 {
40 size_t pos = filepath.rfind ("/");
41
42 if (pos == std::string::npos)
43 return {};
44 else
45 return filepath.substr (0, pos + 1);
46 }
47
53 __inline__ std::string filename (const std::string& filepath)
54 {
55 size_t pos = filepath.rfind ("/");
56
57 if (pos == std::string::npos)
58 return filepath;
59 else
60 return filepath.substr (pos + 1);
61 }
62
68 __inline__ std::string extension (const std::string& filepath)
69 {
70 size_t pos = filepath.rfind (".");
71
72 if (pos == std::string::npos)
73 return {};
74 else
75 return filepath.substr (pos + 1);
76 }
77
83 __inline__ std::string mime (const std::string& filepath)
84 {
85 std::string mime, suffix (extension (filepath));
86
87 if (suffix == "htm")
88 mime = "text/html";
89 else if (suffix == "html")
90 mime = "text/html";
91 else if (suffix == "css")
92 mime = "text/css";
93 else if (suffix == "less")
94 mime = "text/css";
95 else if (suffix == "js")
96 mime = "application/javascript";
97 else if (suffix == "xml")
98 mime = "text/xml";
99 else if (suffix == "json")
100 mime = "application/json";
101 else if (suffix == "txt")
102 mime = "text/plain";
103 else if (suffix == "properties")
104 mime = "text/x-java-properties";
105 else if (suffix == "jpg")
106 mime = "image/jpeg";
107 else if (suffix == "jpeg")
108 mime = "image/jpeg";
109 else if (suffix == "png")
110 mime = "image/png";
111 else if (suffix == "bmp")
112 mime = "image/bmp";
113 else if (suffix == "gif")
114 mime = "image/gif";
115 else if (suffix == "jpe")
116 mime = "image/jpg";
117 else if (suffix == "xbm")
118 mime = "image/xbm";
119 else if (suffix == "tiff")
120 mime = "image/tiff";
121 else if (suffix == "tif")
122 mime = "image/tiff";
123 else if (suffix == "ico")
124 mime = "image/x-icon";
125 else if (suffix == "svg")
126 mime = "image/svg+xml";
127 else if (suffix == "pdf")
128 mime = "application/pdf";
129 else if (suffix == "mp3")
130 mime = "audio/mpeg";
131 else if (suffix == "mp4")
132 mime = "audio/mp4";
133 else if (suffix == "zip")
134 mime = "application/zip";
135 else if (suffix == "bz2")
136 mime = "application/x-bzip";
137 else if (suffix == "tbz2")
138 mime = "application/x-bzip";
139 else if (suffix == "tb2")
140 mime = "application/x-bzip";
141 else if (suffix == "gz")
142 mime = "application/x-gzip";
143 else if (suffix == "gzip")
144 mime = "application/x-gzip";
145 else if (suffix == "tar")
146 mime = "application/x-tar";
147 else if (suffix == "rar")
148 mime = "application/x-rar-compressed";
149 else if (suffix == "tpl")
150 mime = "application/vnd.groove-tool-template";
151 else if (suffix == "woff")
152 mime = "application/font-woff";
153 else if (suffix == "woff2")
154 mime = "application/font-woff2";
155 else
156 mime = "application/octet-stream";
157
158 return mime;
159 }
160}
161
162#endif
Definition acceptor.hpp:32
__inline__ std::string extension(const std::string &filepath)
get extension of the file specified.
Definition filesystem.hpp:68
__inline__ std::string filename(const std::string &filepath)
get file name of the specified file.
Definition filesystem.hpp:53
__inline__ std::string mime(const std::string &filepath)
get mime type of the specified file.
Definition filesystem.hpp:83
__inline__ std::string base(const std::string &filepath)
get base path of the specified file.
Definition filesystem.hpp:38