-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.h
108 lines (102 loc) · 4.38 KB
/
extensions.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
#ifndef FILESORTER_EXTENSIONS_H
#define FILESORTER_EXTENSIONS_H
#include <list>
#include <string>
// Struct to keep extensions
// You can add, delete or change extensions in lists
struct Extensions {
private:
// Audio file extensions
const std::list<std::string> audio_ext
{".aif", ".cda", ".mid", ".midi", ".mp3", ".mpa", ".ogg", ".wav", ".wma", ".wpl"};
// Compressed file extensions
const std::list<std::string> compressed_ext
{".7z", ".arj", ".deb", ".pkg", ".rar", ".rpm", ".tar.gz", ".z", ".zip"};
// Disc and media file extensions
const std::list<std::string> disc_ext
{".dmg", ".iso", ".toast", ".vcd"};
// Data and database file extensions
const std::list<std::string> data_ext
{".csv", ".dat", ".db", ".dbf", ".log", ".mdb", ".sav", ".sql", ".tar", ".xml"};
// E-mail file extensions
const std::list<std::string> email_ext
{".email", ".eml", ".emlx", ".msg", ".oft", ".ost", ".pst", ".vcf"};
// Executable file extensions
const std::list<std::string> executable_ext
{".apk", ".bat", ".bin", ".com", ".exe", ".gadget", ".jar", ".msi", ".wsf"};
// Font file extensions
const std::list<std::string> font_ext
{".fnt", ".fon", ".otf", ".ttf"};
// Image file extensions
const std::list<std::string> image_ext
{".ai", ".bmp", ".gif", ".ico", ".jpeg", ".jpg", ".png", ".ps", ".psd", ".svg", ".tif", ".tiff"};
// Internet related extensions
const std::list<std::string> internet_ext
{".asp", ".aspx", ".cer", ".cfm", ".cgi", ".css", ".htm", ".html", ".js", ".jsp", ".part", ".php",
".py", ".rss", ".xhtml"};
// Presentation file extensions
const std::list<std::string> presentation_ext
{".key", ".odp", ".pps", ".ppt", ".pptx"};
// Programming file extensions
const std::list<std::string> programming_ext
{".c", ".class", ".cpp", ".cs", ".h", ".java", ".pl", ".sh", ".swift", ".vb"};
// Spreadsheet file extensions
const std::list<std::string> spreadsheet_ext
{".ods", ".xls", ".xlsm", ".xlsx"};
// System related file extensions
const std::list<std::string> system_ext
{".bak", ".cab", ".cfg", ".cpl", ".cur", ".dll", ".dmp", ".drv", ".icns", ".ini", ".lnk", ".sys", ".tmp"};
// Video file extensions
const std::list<std::string> video_ext
{".3g2", ".3gp", ".avi", ".flv", ".h264", ".m4v", ".mkv", ".mov", ".mp4", ".mpg", ".mpeg", ".rm", ".swf",
".vob", ".wmv"};
// Word processor and text file extensions
const std::list<std::string> text_ext
{".doc", ".docx", ".odt", ".pdf", ".rtf", ".tex", ".txt", ".wpd"};
public:
// Hash function for strings to use them in switch
static constexpr unsigned str_hash(const char *str, int hash = 0) {
return !str[hash] ? 5381 : (str_hash(str, hash + 1) * 33) ^ str[hash];
}
// Return extensions list depending on given type
// Return empty list if type cannot be found
std::list<std::string> get_extensions(const std::string &type) {
std::list<std::string> empty;
switch (str_hash(type.c_str())) {
case str_hash("audio"):
return audio_ext;
case str_hash("compressed"):
return compressed_ext;
case str_hash("disc"):
return disc_ext;
case str_hash("data"):
return data_ext;
case str_hash("email"):
return email_ext;
case str_hash("executable"):
return executable_ext;
case str_hash("font"):
return font_ext;
case str_hash("image"):
return image_ext;
case str_hash("internet"):
return internet_ext;
case str_hash("presentation"):
return presentation_ext;
case str_hash("programming"):
return programming_ext;
case str_hash("spreadsheet"):
return spreadsheet_ext;
case str_hash("system"):
return system_ext;
case str_hash("video"):
return video_ext;
case str_hash("text"):
return text_ext;
default:
std::cerr << "Invalid type" << std::endl;
return empty;
}
}
};
#endif //FILESORTER_EXTENSIONS_H