-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocumenttypes.pas
55 lines (42 loc) · 1.1 KB
/
documenttypes.pas
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
unit DocumentTypes;
{$mode Delphi}
interface
type
{ The document type to read. This determines which lexer will be used. }
TDocumentType = (
{ Unknown document type}
dtNone,
{ CPP source }
dtCpp,
{ Pascal source}
dtPascal,
{ EditorConfig configuration file }
dtEditorConfig
);
function GetDocumentType(const FileName: String): TDocumentType;
implementation
uses SysUtils;
function IsCppFileExtension(const extension: String): Boolean;
begin
IsCppFileExtension := (extension = '.cpp') or (extension = '.c') or (extension = '.h');
end;
function IsPascalFileExtension(const extension: String): Boolean;
begin
IsPascalFileExtension := (extension = '.pas') or (extension = '.dpr') or
(extension = '.lpr');
end;
function GetDocumentType(const FileName: String): TDocumentType;
var
s: String;
begin
s := ExtractFileExt(FileName);
if IsCppFileExtension(s) then
Result := dtCpp
else if IsPascalFileExtension(s) then
Result := dtPascal
else if ExtractFileName(FileName) = '.editorconfig' then
Result := dtEditorConfig
else
Result := dtNone;
end;
end.