diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/mime | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/mime')
-rw-r--r-- | library/cpp/mime/types/mime.cpp | 146 | ||||
-rw-r--r-- | library/cpp/mime/types/mime.h | 82 |
2 files changed, 114 insertions, 114 deletions
diff --git a/library/cpp/mime/types/mime.cpp b/library/cpp/mime/types/mime.cpp index 706d776b24..b0e9209d31 100644 --- a/library/cpp/mime/types/mime.cpp +++ b/library/cpp/mime/types/mime.cpp @@ -1,40 +1,40 @@ #include "mime.h" - + #include <util/system/defaults.h> #include <util/generic/hash.h> #include <util/generic/strbuf.h> #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <cctype> - +#include <cctype> + /* * MIME types */ class TMimeTypes { - // Constructor + // Constructor public: TMimeTypes(); - // Methods + // Methods public: const char* StrByExt(const char* ext) const; - MimeTypes MimeByStr(const char* str) const; + MimeTypes MimeByStr(const char* str) const; MimeTypes MimeByStr(const TStringBuf& str) const; const char* StrByMime(MimeTypes mime) const; - // Constants + // Constants public: static const size_t MAX_EXT_LEN = 11; // max length of supported extensions - // Helper methods + // Helper methods private: void SetContentTypes(); void SetExt(); - // Types + // Types private: struct TRecord { MimeTypes Mime; @@ -44,7 +44,7 @@ private: typedef THashMap<const char*, int> TRecordHash; - // Fields + // Fields private: static const TRecord Records[]; TRecordHash ContentTypes; @@ -53,38 +53,38 @@ private: const TMimeTypes::TRecord TMimeTypes::Records[] = { {MIME_UNKNOWN, nullptr, nullptr}, - {MIME_TEXT, "text/plain\0", "asc\0txt\0"}, - {MIME_HTML, "text/html\0", "html\0htm\0shtml\0"}, - {MIME_PDF, "application/pdf\0", "pdf\0"}, - {MIME_RTF, "text/rtf\0application/rtf\0", "rtf\0"}, - {MIME_DOC, "application/msword\0", "doc\0"}, - {MIME_MPEG, "audio/mpeg\0", "mp3\0mpa\0m2a\0mp2\0mpg\0mpga\0"}, + {MIME_TEXT, "text/plain\0", "asc\0txt\0"}, + {MIME_HTML, "text/html\0", "html\0htm\0shtml\0"}, + {MIME_PDF, "application/pdf\0", "pdf\0"}, + {MIME_RTF, "text/rtf\0application/rtf\0", "rtf\0"}, + {MIME_DOC, "application/msword\0", "doc\0"}, + {MIME_MPEG, "audio/mpeg\0", "mp3\0mpa\0m2a\0mp2\0mpg\0mpga\0"}, {MIME_XML, "text/xml\0application/xml\0", "xml\0"}, - {MIME_WML, "text/vnd.wap.wml\0", "wml\0"}, - {MIME_SWF, "application/x-shockwave-flash\0", "swf\0"}, - {MIME_XLS, "application/vnd.ms-excel\0", "xls\0"}, - {MIME_PPT, "application/vnd.ms-powerpoint\0", "ppt\0"}, - {MIME_IMAGE_JPG, "image/jpeg\0image/jpg\0", "jpeg\0jpg\0"}, - {MIME_IMAGE_PJPG, "image/pjpeg\0", "pjpeg\0"}, - {MIME_IMAGE_PNG, "image/png\0", "png\0"}, - {MIME_IMAGE_GIF, "image/gif\0", "gif\0"}, - {MIME_DOCX, "application/vnd.openxmlformats-officedocument.wordprocessingml.document\0", "docx\0"}, - {MIME_ODT, "application/vnd.oasis.opendocument.text\0", "odt\0"}, - {MIME_ODP, "application/vnd.oasis.opendocument.presentation\0", "odp\0"}, - {MIME_ODS, "application/vnd.oasis.opendocument.spreadsheet\0", "ods\0"}, + {MIME_WML, "text/vnd.wap.wml\0", "wml\0"}, + {MIME_SWF, "application/x-shockwave-flash\0", "swf\0"}, + {MIME_XLS, "application/vnd.ms-excel\0", "xls\0"}, + {MIME_PPT, "application/vnd.ms-powerpoint\0", "ppt\0"}, + {MIME_IMAGE_JPG, "image/jpeg\0image/jpg\0", "jpeg\0jpg\0"}, + {MIME_IMAGE_PJPG, "image/pjpeg\0", "pjpeg\0"}, + {MIME_IMAGE_PNG, "image/png\0", "png\0"}, + {MIME_IMAGE_GIF, "image/gif\0", "gif\0"}, + {MIME_DOCX, "application/vnd.openxmlformats-officedocument.wordprocessingml.document\0", "docx\0"}, + {MIME_ODT, "application/vnd.oasis.opendocument.text\0", "odt\0"}, + {MIME_ODP, "application/vnd.oasis.opendocument.presentation\0", "odp\0"}, + {MIME_ODS, "application/vnd.oasis.opendocument.spreadsheet\0", "ods\0"}, {MIME_UNKNOWN, nullptr, nullptr}, {MIME_IMAGE_BMP, "image/bmp\0image/x-ms-bmp\0image/x-windows-bmp\0", "bmp\0"}, - {MIME_WAV, "audio/x-wav\0", "wav\0"}, + {MIME_WAV, "audio/x-wav\0", "wav\0"}, {MIME_ARCHIVE, "application/x-archive\0", nullptr}, - {MIME_EXE, "application/exe\0application/octet-stream\0application/x-dosexec\0application/x-msdownload\0", "exe\0"}, - {MIME_ODG, "application/vnd.oasis.opendocument.graphics\0", "odg\0"}, - {MIME_GZIP, "application/x-gzip\0", "gz\0gzip\0"}, - {MIME_XLSX, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\0", "xlsx\0"}, - {MIME_PPTX, "application/vnd.openxmlformats-officedocument.presentationml.presentation\0", "pptx\0"}, - {MIME_JAVASCRIPT, "application/javascript\0text/javascript\0", "js\0"}, - {MIME_EPUB, "application/epub+zip\0", "epub\0"}, + {MIME_EXE, "application/exe\0application/octet-stream\0application/x-dosexec\0application/x-msdownload\0", "exe\0"}, + {MIME_ODG, "application/vnd.oasis.opendocument.graphics\0", "odg\0"}, + {MIME_GZIP, "application/x-gzip\0", "gz\0gzip\0"}, + {MIME_XLSX, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\0", "xlsx\0"}, + {MIME_PPTX, "application/vnd.openxmlformats-officedocument.presentationml.presentation\0", "pptx\0"}, + {MIME_JAVASCRIPT, "application/javascript\0text/javascript\0", "js\0"}, + {MIME_EPUB, "application/epub+zip\0", "epub\0"}, {MIME_TEX, "application/x-tex\0application/x-latex\0text/x-tex\0", "tex\0"}, - {MIME_JSON, "application/json\0", "json\0"}, + {MIME_JSON, "application/json\0", "json\0"}, {MIME_APK, "application/vnd.android.package-archive\0", "apk\0"}, {MIME_CSS, "text/css\0", "css\0"}, {MIME_IMAGE_WEBP, "image/webp\0", "webp\0"}, @@ -102,12 +102,12 @@ const TMimeTypes::TRecord TMimeTypes::Records[] = { {MIME_MAX, nullptr, nullptr}, // Additional records - {MIME_HTML, "application/xhtml+xml\0", "xhtml\0"}, + {MIME_HTML, "application/xhtml+xml\0", "xhtml\0"}, }; TMimeTypes::TMimeTypes() - : ContentTypes() - , Ext() + : ContentTypes() + , Ext() { SetContentTypes(); SetExt(); @@ -164,7 +164,7 @@ const char* TMimeTypes::StrByMime(MimeTypes mime) const { return Records[mime].ContentType; } -const char* mimetypeByExt(const char* fname, const char* check_ext) { +const char* mimetypeByExt(const char* fname, const char* check_ext) { const char* ext_p; if (fname == nullptr || *fname == 0 || (ext_p = strrchr(fname, '.')) == nullptr || strlen(ext_p) - 1 > TMimeTypes::MAX_EXT_LEN) { @@ -174,7 +174,7 @@ const char* mimetypeByExt(const char* fname, const char* check_ext) { char ext[TMimeTypes::MAX_EXT_LEN + 1]; size_t i; ext_p++; - for (i = 0; i < TMimeTypes::MAX_EXT_LEN && ext_p[i]; i++) + for (i = 0; i < TMimeTypes::MAX_EXT_LEN && ext_p[i]; i++) ext[i] = (char)tolower(ext_p[i]); ext[i] = 0; @@ -202,39 +202,39 @@ const char* strByMime(MimeTypes mime) { return Singleton<TMimeTypes>()->StrByMime(mime); } -const char* MimeNames[MIME_MAX] = { - "unknown", // MIME_UNKNOWN // 0 - "text", // MIME_TEXT // 1 - "html", // MIME_HTML // 2 - "pdf", // MIME_PDF // 3 - "rtf", // MIME_RTF // 4 - "doc", // MIME_DOC // 5 - "mpeg", // MIME_MPEG // 6 - "xml", // MIME_XML // 7 - "wap", // MIME_WML // 8 - "swf", // MIME_SWF // 9 - "xls", // MIME_XLS // 10 - "ppt", // MIME_PPT // 11 +const char* MimeNames[MIME_MAX] = { + "unknown", // MIME_UNKNOWN // 0 + "text", // MIME_TEXT // 1 + "html", // MIME_HTML // 2 + "pdf", // MIME_PDF // 3 + "rtf", // MIME_RTF // 4 + "doc", // MIME_DOC // 5 + "mpeg", // MIME_MPEG // 6 + "xml", // MIME_XML // 7 + "wap", // MIME_WML // 8 + "swf", // MIME_SWF // 9 + "xls", // MIME_XLS // 10 + "ppt", // MIME_PPT // 11 "jpg", // MIME_IMAGE_JPG // 12 "pjpg", // MIME_IMAGE_PJPG // 13 - "png", // MIME_IMAGE_PNG // 14 - "gif", // MIME_IMAGE_GIF // 15 - "docx", // MIME_DOCX // 16 - "odt", // MIME_ODT // 17 - "odp", // MIME_ODP // 18 - "ods", // MIME_ODS // 19 - "xmlhtml", // MIME_XHTMLXML // 20 - "bmp", // MIME_IMAGE_BMP // 21 - "wav", // MIME_WAV // 22 - "archive", // MIME_ARCHIVE // 23 - "exe", // MIME_EXE // 24 - "odg", // MIME_ODG // 25 - "gzip", // MIME_GZIP // 26 - "xlsx", // MIME_XLSX // 27 - "pptx", // MIME_PPTX // 28 - "js", // MIME_JAVASCRIPT // 29 - "epub", // MIME_EPUB // 30 - "tex", // MIME_TEX // 31 + "png", // MIME_IMAGE_PNG // 14 + "gif", // MIME_IMAGE_GIF // 15 + "docx", // MIME_DOCX // 16 + "odt", // MIME_ODT // 17 + "odp", // MIME_ODP // 18 + "ods", // MIME_ODS // 19 + "xmlhtml", // MIME_XHTMLXML // 20 + "bmp", // MIME_IMAGE_BMP // 21 + "wav", // MIME_WAV // 22 + "archive", // MIME_ARCHIVE // 23 + "exe", // MIME_EXE // 24 + "odg", // MIME_ODG // 25 + "gzip", // MIME_GZIP // 26 + "xlsx", // MIME_XLSX // 27 + "pptx", // MIME_PPTX // 28 + "js", // MIME_JAVASCRIPT // 29 + "epub", // MIME_EPUB // 30 + "tex", // MIME_TEX // 31 "json", // MIME_JSON // 32 "apk", // MIME_APK // 33 "css", // MIME_CSS // 34 diff --git a/library/cpp/mime/types/mime.h b/library/cpp/mime/types/mime.h index 05da389ea9..d28f3af588 100644 --- a/library/cpp/mime/types/mime.h +++ b/library/cpp/mime/types/mime.h @@ -1,49 +1,49 @@ #pragma once -#include <util/system/defaults.h> -#include <util/generic/strbuf.h> - +#include <util/system/defaults.h> +#include <util/generic/strbuf.h> + #include <cstring> - + enum MimeTypes { - MIME_UNKNOWN = 0, - MIME_TEXT = 1, - MIME_HTML = 2, - MIME_XHTMLXML = MIME_HTML, - MIME_PDF = 3, - MIME_RTF = 4, - MIME_DOC = 5, - MIME_MSWORD = MIME_DOC, - MIME_MPEG = 6, - MIME_XML = 7, - MIME_RSS = MIME_XML, - MIME_WML = 8, - MIME_SWF = 9, - MIME_FLASH = MIME_SWF, - MIME_XLS = 10, - MIME_EXCEL = MIME_XLS, - MIME_PPT = 11, - MIME_IMAGE_JPG = 12, + MIME_UNKNOWN = 0, + MIME_TEXT = 1, + MIME_HTML = 2, + MIME_XHTMLXML = MIME_HTML, + MIME_PDF = 3, + MIME_RTF = 4, + MIME_DOC = 5, + MIME_MSWORD = MIME_DOC, + MIME_MPEG = 6, + MIME_XML = 7, + MIME_RSS = MIME_XML, + MIME_WML = 8, + MIME_SWF = 9, + MIME_FLASH = MIME_SWF, + MIME_XLS = 10, + MIME_EXCEL = MIME_XLS, + MIME_PPT = 11, + MIME_IMAGE_JPG = 12, MIME_IMAGE_PJPG = 13, - MIME_IMAGE_PNG = 14, - MIME_IMAGE_GIF = 15, - MIME_DOCX = 16, - MIME_ODT = 17, - MIME_ODP = 18, - MIME_ODS = 19, + MIME_IMAGE_PNG = 14, + MIME_IMAGE_GIF = 15, + MIME_DOCX = 16, + MIME_ODT = 17, + MIME_ODP = 18, + MIME_ODS = 19, //MIME_XHTMLXML = 20, - MIME_IMAGE_BMP = 21, - MIME_WAV = 22, - MIME_ARCHIVE = 23, - MIME_EXE = 24, - MIME_ODG = 25, - MIME_GZIP = 26, - MIME_XLSX = 27, - MIME_PPTX = 28, + MIME_IMAGE_BMP = 21, + MIME_WAV = 22, + MIME_ARCHIVE = 23, + MIME_EXE = 24, + MIME_ODG = 25, + MIME_GZIP = 26, + MIME_XLSX = 27, + MIME_PPTX = 28, MIME_JAVASCRIPT = 29, - MIME_EPUB = 30, - MIME_TEX = 31, - MIME_JSON = 32, + MIME_EPUB = 30, + MIME_TEX = 31, + MIME_JSON = 32, MIME_APK = 33, MIME_CSS = 34, MIME_IMAGE_WEBP = 35, @@ -61,10 +61,10 @@ enum MimeTypes { MIME_MAX }; -extern const char* MimeNames[MIME_MAX]; +extern const char* MimeNames[MIME_MAX]; const char* mimetypeByExt(const char* fname, const char* check_ext = nullptr); -MimeTypes mimeByStr(const char* mimeStr); +MimeTypes mimeByStr(const char* mimeStr); MimeTypes mimeByStr(const TStringBuf& mimeStr); const char* strByMime(MimeTypes mime); |