Blame


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