1 | unit Generics;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TListString }
|
---|
11 |
|
---|
12 | TListString = class(TList<string>)
|
---|
13 | procedure Assign(Source: TListString);
|
---|
14 | procedure Explode(Separator: Char; Text: string; MaxCount: Integer = -1);
|
---|
15 | function Implode(Separator: Char): string;
|
---|
16 | end;
|
---|
17 |
|
---|
18 | { TDictionaryStringString }
|
---|
19 |
|
---|
20 | TDictionaryStringString = class(TDictionary<string, string>)
|
---|
21 | procedure Assign(Source: TDictionaryStringString);
|
---|
22 | end;
|
---|
23 |
|
---|
24 |
|
---|
25 | implementation
|
---|
26 |
|
---|
27 | { TListString }
|
---|
28 |
|
---|
29 | procedure TListString.Assign(Source: TListString);
|
---|
30 | var
|
---|
31 | I: Integer;
|
---|
32 | begin
|
---|
33 | Count := Source.Count;
|
---|
34 | for I := 0 to Source.Count - 1 do
|
---|
35 | Items[I] := Source[I];
|
---|
36 | end;
|
---|
37 |
|
---|
38 | function TListString.Implode(Separator: Char): string;
|
---|
39 | var
|
---|
40 | I: Integer;
|
---|
41 | begin
|
---|
42 | Result := '';
|
---|
43 | for I := 0 to Count - 1 do begin
|
---|
44 | Result := Result + Items[I];
|
---|
45 | if I < Count - 1 then Result := Result + Separator;
|
---|
46 | end;
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TListString.Explode(Separator: Char; Text: string; MaxCount: Integer = -1);
|
---|
50 | var
|
---|
51 | Index: Integer;
|
---|
52 | begin
|
---|
53 | Clear;
|
---|
54 | repeat
|
---|
55 | Index := Pos(Separator, Text);
|
---|
56 | if Index > 0 then begin
|
---|
57 | Add(Copy(Text, 1, Index - 1));
|
---|
58 | System.Delete(Text, 1, Index);
|
---|
59 | if (MaxCount <> -1) and (Count >= MaxCount) then Break;
|
---|
60 | end else Break;
|
---|
61 | until False;
|
---|
62 | if Text <> '' then begin
|
---|
63 | Add(Text);
|
---|
64 | end;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | { TDictionaryStringString }
|
---|
68 |
|
---|
69 | procedure TDictionaryStringString.Assign(Source: TDictionaryStringString);
|
---|
70 | var
|
---|
71 | Item: TPair<string, string>;
|
---|
72 | begin
|
---|
73 | Clear;
|
---|
74 | for Item in Source do
|
---|
75 | Add(Item.Key, Item.Value);
|
---|
76 | end;
|
---|
77 |
|
---|
78 | end.
|
---|