forked from xsgordon/duplo-fork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileType.cpp
74 lines (67 loc) · 2.06 KB
/
FileType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "StringUtil.h"
#include "FileType.h"
static const std::string FileTypeExtn_C = "c";
static const std::string FileTypeExtn_CC = "cc";
static const std::string FileTypeExtn_CPP = "cpp";
static const std::string FileTypeExtn_CXX = "cxx";
static const std::string FileTypeExtn_H = "h";
static const std::string FileTypeExtn_HH = "hh";
static const std::string FileTypeExtn_HPP = "hpp";
static const std::string FileTypeExtn_Java = "java";
static const std::string FileTypeExtn_CS = "cs";
static const std::string FileTypeExtn_VB = "vb";
#include <algorithm>
FileType::FILETYPE FileType::GetFileType(const std::string& FileName)
{
std::string TrimFileName = StringUtil::trim(FileName);
std::string::size_type DotPos = TrimFileName.find_last_of (".");
if (std::string::npos == DotPos)
{
// no file extension
return FILETYPE_UNKNOWN;
}
// get lower case file extension
std::string FileExtn = TrimFileName.substr(DotPos + 1, TrimFileName.length() - DotPos - 1);
std::transform(FileExtn.begin(), FileExtn.end(), FileExtn.begin(), (int(*)(int)) tolower);
if (!FileExtn.compare(FileTypeExtn_C))
{
return FILETYPE_C;
}
else if (!FileExtn.compare(FileTypeExtn_CC))
{
return FILETYPE_CXX;
}
else if (!FileExtn.compare(FileTypeExtn_HH))
{
return FILETYPE_CXX;
}
else if (!FileExtn.compare(FileTypeExtn_CPP))
{
return FILETYPE_CXX;
}
else if (!FileExtn.compare(FileTypeExtn_CXX))
{
return FILETYPE_CXX;
}
else if (!FileExtn.compare(FileTypeExtn_H))
{
return FILETYPE_C;
}
else if (!FileExtn.compare(FileTypeExtn_HPP))
{
return FILETYPE_CXX;
}
else if (!FileExtn.compare(FileTypeExtn_Java))
{
return FILETYPE_JAVA;
}
else if (!FileExtn.compare(FileTypeExtn_CS))
{
return FILETYPE_CS;
}
else if (!FileExtn.compare(FileTypeExtn_VB))
{
return FILETYPE_VB;
}
return FILETYPE_UNKNOWN;
}