Blob


1 /* Detect MIME file type */
3 #include "utils.h"
5 #include <string>
6 #include <map>
8 #pragma once
11 namespace vostok
12 {
15 class Mime
16 {
17 public:
18 /* Read and parse "mime.types" file content */
19 bool parse_db(NotNull<czstring> sz_path);
21 /* Lookup MIME type by FS path */
22 const std::string *lookup(const std::string &path) const;
24 /* Get file extension from path. Return path.end() if no extension. */
25 static std::string::const_iterator get_ext(const std::string &path);
27 protected:
28 class Key
29 {
30 public:
31 explicit Key(/* in/out */ std::string &string) {m_string.swap(string);}
32 explicit Key(const char *p) : m_p(p) {}
33 const char *c_str() const { return m_p ? m_p : m_string.c_str(); }
35 private:
36 std::string m_string;
37 const char *m_p{nullptr};
38 };
40 private:
41 class Less
42 {
43 public:
44 bool operator ()(const Key &key1, const Key &key2) const;
45 };
46 std::map<Key, std::string, Less> m_map;
47 };
50 } // namespace vostok