-
Notifications
You must be signed in to change notification settings - Fork 89
/
Grijjy.Uri.pas
72 lines (62 loc) · 1.42 KB
/
Grijjy.Uri.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
unit Grijjy.Uri;
{ URI helper }
{$I Grijjy.inc}
interface
uses
System.SysUtils,
System.Classes,
System.Net.URLClient;
type
TgoURI = record
private
FURI: TURI;
public
Scheme: String;
Username: String;
Password: String;
Host: String;
Port: Integer;
Path: String;
Query: String;
Params: String;
Fragment: String;
public
constructor Create(const AUri: String);
function ToString: String;
end;
implementation
{ TgoURI }
constructor TgoURI.Create(const AUri: String);
var
I: Integer;
begin
FURI := TURI.Create(AUri);
Scheme := FURI.Scheme;
Username := FURI.Username;
Password := FURI.Password;
Host := FURI.Host;
Port := FURI.Port;
Path := FURI.Path;
Query := FURI.Query;
for I := 0 to Length(FURI.Params) - 1 do
Params := Params + FURI.Params[I].Name + '=' + FURI.Params[I].Value + '&';
Params := Params.Substring(0, Params.Length - 1);
Fragment := FURI.Fragment;
end;
function TgoURI.ToString: String;
var
Auth: String;
begin
if Username <> '' then
Auth := Username + ':' + Password + '@'
else
Auth := '';
Result := Scheme + '://' + Auth + Host;
if ((Port <> -1) and (Port <> 0)) and
((SameText(Scheme, 'http') and (Port <> 80)) or (SameText(Scheme, 'https') and (Port <> 443))) then
Result := Result + ':' + IntToStr(Port);
Result := Result + Path;
if Length(Params) > 0 then
Result := Result + '?' + Params;
end;
end.