| 27 | using std::string; |
| 28 | |
| 29 | Format *GetType(void *file_pointer, size_t file_size, const string& filename) |
| 30 | { |
| 31 | if (depth > max_depth) |
| 32 | { |
| 33 | return new Format(file_pointer, file_size); |
| 34 | } |
| 35 | |
| 36 | if (!filename.empty()) |
| 37 | { |
| 38 | size_t dot = filename.find_last_of('.'); |
| 39 | if (dot != string::npos) |
| 40 | { |
| 41 | string ext = filename.substr(dot + 1); |
| 42 | // toupper |
| 43 | for (auto &c : ext) |
| 44 | c &= ~0x20; |
| 45 | |
| 46 | if (ext == "HTML" || |
| 47 | ext == "HTM" || |
| 48 | ext == "JS" || |
| 49 | ext == "CSS") |
| 50 | { |
| 51 | if (is_verbose) |
| 52 | { |
| 53 | cout << ext << " detected." << endl; |
| 54 | } |
| 55 | return new DataURI(file_pointer, file_size); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | if (memcmp(file_pointer, Png::header_magic, sizeof(Png::header_magic)) == 0) |
| 61 | { |
| 62 | if (is_verbose) |
| 63 | { |
| 64 | cout << "PNG detected." << endl; |
| 65 | } |
| 66 | return new Png(file_pointer, file_size); |
| 67 | } |
| 68 | else if (memcmp(file_pointer, Jpeg::header_magic, sizeof(Jpeg::header_magic)) == 0) |
| 69 | { |
| 70 | if (is_verbose) |
| 71 | { |
| 72 | cout << "JPEG detected." << endl; |
| 73 | } |
| 74 | return new Jpeg(file_pointer, file_size); |
| 75 | } |
| 76 | else if (memcmp(file_pointer, Lua::header_magic, sizeof(Lua::header_magic)) == 0) |
| 77 | { |
| 78 | if (is_verbose) |
| 79 | { |
| 80 | cout << "Lua detected." << endl; |
| 81 | } |
| 82 | return new Lua(file_pointer, file_size); |
| 83 | } |
| 84 | else if (memcmp(file_pointer, Zip::header_magic, sizeof(Zip::header_magic)) == 0) |
| 85 | { |
| 86 | if (is_verbose) |