mp/include/util.h

60 lines
1.4 KiB
C
Raw Normal View History

2024-02-20 14:55:57 +08:00
#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