-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibgit2.strarray.pas
More file actions
64 lines (49 loc) · 1.22 KB
/
libgit2.strarray.pas
File metadata and controls
64 lines (49 loc) · 1.22 KB
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
unit LibGit2.StrArray;
{$mode objfpc}{$H+}{$modeswitch advancedrecords}
interface
uses
LibGit2.Platform,
SysUtils,
LibGit2.StdInt;
type
PGitStrArray = ^TGitStrArray;
TGitStrArray = record
Strings: PPChar;
Count: size_t;
end;
TGitStrArrayHelper = record helper for TGitStrArray
procedure Dispose; inline;
function IsEmpty: Boolean; inline;
function ToArray: TStringArray;
function Item(Index: SizeInt): String;
end;
implementation
procedure Libgit2StrArrayDispose(StrArray: PGitStrArray); cdecl; external LibGit2Dll name 'git_strarray_dispose';
procedure TGitStrArrayHelper.Dispose; inline;
begin
Libgit2StrArrayDispose(@Self);
Self := Default(TGitStrArray);
end;
function TGitStrArrayHelper.IsEmpty: Boolean; inline;
begin
Result := (Count = 0) or (Strings = nil);
end;
function TGitStrArrayHelper.ToArray: TStringArray;
var
i: SizeInt;
begin
SetLength(Result, Count);
for i := 0 to Count - 1 do
begin
Result[i] := Ansistring(UTF8ToString(Strings[i]));
end;
end;
function TGitStrArrayHelper.Item(Index: SizeInt): String;
begin
if (Index < 0) or (Index >= Count) then
begin
raise ERangeError.CreateFmt('Index %d out of bounds (0..%d)', [Index, Count - 1]);
end;
Result := Strings[Index];
end;
end.