-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathufunctions.pas
86 lines (68 loc) · 1.65 KB
/
ufunctions.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
unit ufunctions;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms;
function GetExedir: string;
function File2String(AFilename: string): string;
function StrDec(s: string): string;
function StrEndsWith(AStr, ATail: string; ACaseSensistive: boolean = False): boolean;
function StrStartsWith(AStr, AHead: string; ACaseSensistive: boolean = False): boolean;
implementation
function StrDec(s: string): string;
begin
Result := System.Copy(s, 1, Length(s) - 1);
end;
function GetExedir: string;
begin
Result := ExtractFilePath(Application.ExeName);
end;
function File2String(AFilename: string): string;
var
fs: TFileStream;
ss: TStringStream;
begin
ss := nil;
fs := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyWrite);
try
ss := TStringStream.Create('');
ss.CopyFrom(fs, fs.Size);
Result := ss.DataString;
finally
fs.Free;
ss.Free;
end;
end;
function StrEndsWith(AStr, ATail: string; ACaseSensistive: boolean = False): boolean;
var
Ls, Lt: integer;
begin
Ls := Length(AStr);
Lt := Length(ATail);
if Lt = 0 then
Result := True
else
begin
if ACaseSensistive then
Result := Copy(AStr, Ls - Lt + 1, Lt) = ATail
else
Result := AnsiUpperCase(Copy(AStr, Ls - Lt + 1, Lt)) = AnsiUpperCase(ATail);
end;
end;
function StrStartsWith(AStr, AHead: string; ACaseSensistive: boolean = False): boolean;
var
Ls, Lh: integer;
begin
Ls := Length(AStr);
Lh := Length(AHead);
if Lh > Ls then
Result := False
else
begin
if ACaseSensistive then
Result := Copy(AStr, 1, Lh) = AHead
else
Result := AnsiUpperCase(Copy(AStr, 1, Lh)) = AnsiUpperCase(AHead);
end;
end;
end.