add UtilFile
This commit is contained in:
60
include/util.h
Normal file
60
include/util.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#ifndef UTIL_H
|
||||||
|
#define UTIL_H
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user