-
Notifications
You must be signed in to change notification settings - Fork 4
/
uArrayAsPHP.pas
103 lines (89 loc) · 2.33 KB
/
uArrayAsPHP.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
unit uArrayAsPHP;
interface
//Ein paar Array-Funktionen wie sie in PHP ublich sind.
//Some Array-functions like in PHP.
// âçÿë èç íåäð èíòåðíåòà.
// ïåðâî-èñòî÷íèê íå èçâåñòåí.
type
TString = widestring;
ArrOfStr = array of TString;
function explode(sPart, sInput: TString; EmptyIfNone: boolean = false): ArrOfStr;
function implode(sPart: TString; arrInp: ArrOfStr): TString; overload;
function implode(sPart: TString; arrInp: array of Variant): TString; overload;
implementation
uses StrUtils;
function explode(sPart, sInput: TString; EmptyIfNone: boolean = false): ArrOfStr;
var
P, Offs: integer;
begin
Offs := 1;
P := PosEx(sPart, sInput, Offs);
if (P = 0) then
if (EmptyIfNone = true) then
begin
SetLength(Result, 0);
exit;
end else
begin
SetLength(Result, 1);
Result[0] := sInput;
exit;
end;
SetLength(Result, 0);
while P <> 0 do
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := Copy(sInput, Offs, P - Offs);
Offs := P + Length(sPart);
P := PosEx(sPart, sInput, Offs);
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := Copy(sInput, Offs, Length(sInput) - Offs + 1);
end;
function implode(sPart: TString; arrInp: ArrOfStr): TString;
var
i: Integer;
begin
if Length(arrInp) <= 1 then Result := arrInp[0]
else
begin
for i := 0 to Length(arrInp) - 2 do Result := Result + arrInp[i] + sPart;
Result := Result + arrInp[Length(arrInp) - 1];
end;
end;
function implode(sPart: TString; arrInp: array of Variant): TString;
var
i: Integer;
begin
if Length(arrInp) <= 1 then Result := arrInp[0]
else
begin
for i := 0 to Length(arrInp) - 2 do Result := Result + arrInp[i] + sPart;
Result := Result + arrInp[Length(arrInp) - 1];
end;
end;
{
procedure sort(arrInp: ArrOfStr);
var
slTmp: TStringList;
i: Integer;
begin
slTmp := TStringList.Create;
for i := 0 to Length(arrInp) - 1 do slTmp.Add(arrInp[i]);
slTmp.Sort;
for i := 0 to slTmp.Count - 1 do arrInp[i] := slTmp[i];
slTmp.Free;
end;
procedure rsort(arrInp: ArrOfStr);
var
slTmp: TStringList;
i: Integer;
begin
slTmp := TStringList.Create;
for i := 0 to Length(arrInp) - 1 do slTmp.Add(arrInp[i]);
slTmp.Sort;
for i := 0 to slTmp.Count - 1 do arrInp[slTmp.Count - 1 - i] := slTmp[i];
slTmp.Free;
end;
}
end.