From 0f1f3db3d58e2db2655820e2e1f923bc3795bd0d Mon Sep 17 00:00:00 2001 From: Jie Date: Tue, 20 Feb 2024 14:55:57 +0800 Subject: [PATCH] add UtilFile --- include/util.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/util.h diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..afe6f47 --- /dev/null +++ b/include/util.h @@ -0,0 +1,60 @@ +#ifndef UTIL_H +#define UTIL_H + +#include +#include +#include +#include +#include +const std::array MusicFileExtensive = { + "mp3" +}; + +const std::array VideoFileExtensive = { + "mp4" +}; + +const std::array ImgFileExtensive = { + "jpeg", + "jpg", + "png", +}; + + +using namespace std::filesystem; +class Util{ +public: + static const char* GetFileExtensive(path filepath){ + std::string ext = filepath.extension().string(); + ext.erase(std::remove_if(ext.begin(), ext.end(), [](char c){return c=='.';}), ext.end()); + return ext.c_str(); + } + static bool IsMusic(path filepath){ + const auto ext = GetFileExtensive(filepath); + for(const auto& it : MusicFileExtensive){ + if(std::strcmp(it, ext) == 0) + return true; + } + return false; + } + + static bool IsVideo(path filepath){ + const auto ext = GetFileExtensive(filepath); + for(const auto& it : VideoFileExtensive){ + if(std::strcmp(it, ext) == 0) + return true; + } + return false; + } + + static bool IsImg(path filepath){ + const auto ext = GetFileExtensive(filepath);[A + for(const auto& it : ImgFileExtensive){ + if(std::strcmp(it, ext) == 0) + return true; + } + return false; + } +}; + +#endif \ No newline at end of file