#include <iostream>
#incldue <cstring>
#include <stdlib.h>
using namespace std;
//通用函数 获取扩展名
inline string getExtension(const string &fileName)
{
string extension;
if(fileName.rfind('.') != string::npos){
extension = fileName.substr(fileName.rfind('.') + 1);
}
return extension;
}
//通用函数 匹配扩展名
bool matchExtension(const string &fileName,const string &extension)
{
char *str = (char *)malloc(extension.length() + 1);
char *ext = (char *)malloc(getExtension(fileName).length() + 1);
strcpy(str,extension.c_str());
strcpy(ext,getExtension(fileName).c_str());
bool isMatch = false;
char *p = strtok(str,"|");
while(p && !isMatch){
if(strcmp(ext,p) == 0){
isMatch = true;
}
p = strtok(NULL,"|");
}
free(str);
free(ext);
return isMatch;
}
#incldue <cstring>
#include <stdlib.h>
using namespace std;
//通用函数 获取扩展名
inline string getExtension(const string &fileName)
{
string extension;
if(fileName.rfind('.') != string::npos){
extension = fileName.substr(fileName.rfind('.') + 1);
}
return extension;
}
//通用函数 匹配扩展名
bool matchExtension(const string &fileName,const string &extension)
{
char *str = (char *)malloc(extension.length() + 1);
char *ext = (char *)malloc(getExtension(fileName).length() + 1);
strcpy(str,extension.c_str());
strcpy(ext,getExtension(fileName).c_str());
bool isMatch = false;
char *p = strtok(str,"|");
while(p && !isMatch){
if(strcmp(ext,p) == 0){
isMatch = true;
}
p = strtok(NULL,"|");
}
free(str);
free(ext);
return isMatch;
}