Skip to content

Commit c597831

Browse files
committed
Rename TURI as TImmutableURI
Rename type in Utils.URI unit Updated affected units Renamed test class from TTestTURI to TTestTImmutableURI
1 parent f9f373d commit c597831

File tree

3 files changed

+86
-82
lines changed

3 files changed

+86
-82
lines changed

cupola/src/CSLE.Snippets.TestInfo.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ constructor TSnippetTestInfo.Create(const AGeneral: TTestInfoGeneral;
130130
fAdvanced := [];
131131
fURL := string.Empty;
132132
end;
133-
if not TURI.IsValidURIString(fURL, True) then
133+
if not TImmutableURI.IsValidURIString(fURL, True) then
134134
raise ESnippetTestInfo.CreateFmt('Invalid URL: %s', [fURL]);
135135
end;
136136

@@ -176,8 +176,8 @@ class function TSnippetTestInfo.Same(const Left,
176176
Exit(True);
177177
// Only if Left & Right's .General field is Advanced AND if Left and Right's
178178
// .Advanced property is not empty set do we compare URLs
179-
var LeftURI := TURI.Create(Left.fURL, True);
180-
var RightURI := TURI.Create(Right.fURL, True);
179+
var LeftURI := TImmutableURI.Create(Left.fURL, True);
180+
var RightURI := TImmutableURI.Create(Right.fURL, True);
181181
Result := LeftURI = RightURI;
182182
end;
183183

cupola/src/CSLE.Utils.URI.pas

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface
1818
CSLE.Exceptions;
1919

2020
type
21-
TURI = record
21+
TImmutableURI = record
2222
strict private
2323
var
2424
// Record containing URI information. Must not be accessed if fEmpty is
@@ -91,20 +91,21 @@ TURI = record
9191
/// <summary>Fragment part of the URI.</summary>
9292
property Fragment: string read GetFragment;
9393

94-
/// <summary>Compares two <c>TURI</c> records and returns a 0, -ve or +ve
95-
/// value depending on whether the <c>Left</c> is equal to, less than or
96-
/// greater than <c>Right</c>, respectively.</summary>
97-
class function Compare(const Left, Right: TURI): Integer; static;
94+
/// <summary>Compares two <c>TImmutableURI</c> records and returns a 0,
95+
/// -ve or +ve value depending on whether the <c>Left</c> is equal to, less
96+
/// than or greater than <c>Right</c>, respectively.</summary>
97+
class function Compare(const Left, Right: TImmutableURI): Integer; static;
9898

9999
/// <summary>Checks the validity of a given URI. An empty URI is only
100100
/// considered to be valid if <c>APermitEmpty</c> is <c>True</c>.</summary>
101101
class function IsValidURIString(const AURIStr: string;
102102
const APermitEmpty: Boolean): Boolean; static;
103103

104104
// Operator overloads
105-
class operator Equal(const Left, Right: TURI): Boolean;
106-
class operator NotEqual(const Left, Right: TURI): Boolean;
107-
class operator Implicit(const AURI: System.Net.URLCLient.TURI): TURI;
105+
class operator Equal(const Left, Right: TImmutableURI): Boolean;
106+
class operator NotEqual(const Left, Right: TImmutableURI): Boolean;
107+
class operator Implicit(const AURI: System.Net.URLCLient.TURI):
108+
TImmutableURI;
108109
end;
109110

110111
EURI = class(EExpected);
@@ -115,9 +116,9 @@ implementation
115116
System.SysUtils,
116117
System.Types;
117118

118-
{ TURI }
119+
{ TImmutableURI }
119120

120-
class function TURI.Compare(const Left, Right: TURI): Integer;
121+
class function TImmutableURI.Compare(const Left, Right: TImmutableURI): Integer;
121122
begin
122123
// Deal with one or more empty URIs: empty is less than
123124
if Left.IsEmpty and Right.IsEmpty then
@@ -169,7 +170,8 @@ class function TURI.Compare(const Left, Right: TURI): Integer;
169170
);
170171
end;
171172

172-
constructor TURI.Create(const AURIStr: string; const APermitEmpty: Boolean);
173+
constructor TImmutableURI.Create(const AURIStr: string;
174+
const APermitEmpty: Boolean);
173175
begin
174176
fIsEmpty := AURIStr.IsEmpty;
175177
if fIsEmpty and not APermitEmpty then
@@ -181,95 +183,96 @@ constructor TURI.Create(const AURIStr: string; const APermitEmpty: Boolean);
181183
end;
182184
end;
183185

184-
class operator TURI.Equal(const Left, Right: TURI): Boolean;
186+
class operator TImmutableURI.Equal(const Left, Right: TImmutableURI): Boolean;
185187
begin
186188
Result := Compare(Left, Right) = 0;
187189
end;
188190

189-
function TURI.GetFragment: string;
191+
function TImmutableURI.GetFragment: string;
190192
begin
191193
if fIsEmpty then
192194
Result := string.Empty
193195
else
194196
Result := fURI.Fragment;
195197
end;
196198

197-
function TURI.GetHost: string;
199+
function TImmutableURI.GetHost: string;
198200
begin
199201
if fIsEmpty then
200202
Result := string.Empty
201203
else
202204
Result := fURI.Host;
203205
end;
204206

205-
function TURI.GetParams: TURIParameters;
207+
function TImmutableURI.GetParams: TURIParameters;
206208
begin
207209
if fIsEmpty then
208210
SetLength(Result, 0)
209211
else
210212
Result := fURI.Params;
211213
end;
212214

213-
function TURI.GetPassword: string;
215+
function TImmutableURI.GetPassword: string;
214216
begin
215217
if fIsEmpty then
216218
Result := string.Empty
217219
else
218220
Result := fURI.Password;
219221
end;
220222

221-
function TURI.GetPath: string;
223+
function TImmutableURI.GetPath: string;
222224
begin
223225
if fIsEmpty then
224226
Result := string.Empty
225227
else
226228
Result := fURI.Path;
227229
end;
228230

229-
function TURI.GetPort: Integer;
231+
function TImmutableURI.GetPort: Integer;
230232
begin
231233
if fIsEmpty then
232234
Result := 0
233235
else
234236
Result := fURI.Port;
235237
end;
236238

237-
function TURI.GetQuery: string;
239+
function TImmutableURI.GetQuery: string;
238240
begin
239241
if fIsEmpty then
240242
Result := string.Empty
241243
else
242244
Result := fURI.Query;
243245
end;
244246

245-
function TURI.GetScheme: string;
247+
function TImmutableURI.GetScheme: string;
246248
begin
247249
if fIsEmpty then
248250
Result := string.Empty
249251
else
250252
Result := fURI.Scheme;
251253
end;
252254

253-
function TURI.GetUsername: string;
255+
function TImmutableURI.GetUsername: string;
254256
begin
255257
if fIsEmpty then
256258
Result := string.Empty
257259
else
258260
Result := fURI.Username;
259261
end;
260262

261-
class operator TURI.Implicit(const AURI: System.Net.URLCLient.TURI): TURI;
263+
class operator TImmutableURI.Implicit(const AURI: System.Net.URLCLient.TURI):
264+
TImmutableURI;
262265
begin
263266
Result.fURI := AURI;
264267
Result.fIsEmpty := False;
265268
end;
266269

267-
function TURI.IsEmpty: Boolean;
270+
function TImmutableURI.IsEmpty: Boolean;
268271
begin
269272
Result := fIsEmpty;
270273
end;
271274

272-
class function TURI.IsValidURIString(const AURIStr: string;
275+
class function TImmutableURI.IsValidURIString(const AURIStr: string;
273276
const APermitEmpty: Boolean): Boolean;
274277
begin
275278
if AURIStr.IsEmpty then
@@ -278,20 +281,21 @@ class function TURI.IsValidURIString(const AURIStr: string;
278281
Result := TryDeconstructURI(AURIStr, Dummy);
279282
end;
280283

281-
class operator TURI.NotEqual(const Left, Right: TURI): Boolean;
284+
class operator TImmutableURI.NotEqual(const Left, Right: TImmutableURI):
285+
Boolean;
282286
begin
283287
Result := Compare(Left, Right) <> 0;
284288
end;
285289

286-
function TURI.ToString: string;
290+
function TImmutableURI.ToString: string;
287291
begin
288292
if fIsEmpty then
289293
Result := string.Empty
290294
else
291295
Result := fURI.ToString;
292296
end;
293297

294-
class function TURI.TryDeconstructURI(const AURIStr: string;
298+
class function TImmutableURI.TryDeconstructURI(const AURIStr: string;
295299
out AURI: System.Net.URLClient.TURI): Boolean;
296300
begin
297301
Result := True;

0 commit comments

Comments
 (0)