-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathARRL.pas
126 lines (111 loc) · 2.59 KB
/
ARRL.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
unit ARRL;
interface
uses
SysUtils, Classes, Contnrs, PerlRegEx, pcre;
type
TARRLRec= class
public
prefixReg: string;
Entity: string;
Continent: string;
ITU: string;
CQ: string;
function GetString: string;
end;
TARRL= class
private
ARRLList: TList;
procedure LoadARRL;
procedure Delimit(var AStringList: TStringList; const AText: string);
public
constructor Create;
function Search(ACallsign: string): string;
end;
var
ARRLDX: TARRL;
implementation
uses
log;
procedure TARRL.LoadARRL;
var
slst, tl: TStringList;
i: integer;
AR: TARRLRec;
begin
slst:= TStringList.Create;
tl:= TStringList.Create;
try
ARRLList:= TList.Create;
slst.LoadFromFile(ParamStr(1) + 'ARRL.LIST');
slst.Sort;
for i:= 0 to slst.Count-1 do begin
self.Delimit(tl, slst.Strings[i]);
if (tl.Count = 7) then begin
AR:= TARRLRec.Create;
AR.prefixReg:= tl.Strings[1];
AR.Entity:= tl.Strings[2];
AR.Continent:= tl.Strings[3];
AR.ITU:= tl.Strings[4];
AR.CQ:= tl.Strings[5];
ARRLList.Add(AR);
end;
end;
finally
slst.Free;
tl.Free;
end;
end;
constructor TARRL.Create;
begin
inherited Create;
LoadARRL;
end;
function TARRL.Search(ACallsign: string): string;
var
reg: TPerlRegEx;
i: integer;
s, sC, sP: string;
begin
reg := TPerlRegEx.Create();
try
Result:= '';
sC:= ExtractCallsign(ACallsign);
sP:= ExtractPrefix(sC);
reg.Subject := UTF8Encode(sP);
for i:= ARRLList.Count - 1 downto 0 do begin
s:= '^(' + TARRLRec(ARRLList.Items[i]).prefixReg + ')';
reg.RegEx:= UTF8Encode(s);
if Reg.Match then begin
Result:= sC + ' ' + TARRLRec(ARRLList[i]).GetString;
Break;
end;
end;
finally
reg.Free;
end;
end;
procedure TARRL.Delimit(var AStringList: TStringList; const AText: string);
const
DelimitChar: char= ';';
var
i, l: integer;
s: string;
begin
AStringList.Clear;
l:= Length(AText);
s:= '';
for i := 1 to l do begin
if(AText[i] = DelimitChar) or (i=l) then begin
AStringList.Add(s);
s:= '';
end
else
s:= s + AText[i];
end;
end;
{ TARRLRec }
function TARRLRec.GetString: string;
begin
Result:= Format('%s/%s; ITU Zone:%s; CQ Zone:%s', [Entity, Continent, ITU, CQ]);
end;
end.