-
Notifications
You must be signed in to change notification settings - Fork 1
/
getstrparam.pas
163 lines (144 loc) · 4.13 KB
/
getstrparam.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{ **** UBPFD *********** by kladovka.net.ru ****
>> Ïîëó÷åíèå ïàðàìåòðà èç ñòðîêè ïî åãî èíäåêñó, à òàêæå ïîëó÷åíèå îáùåãî ÷èñëà ïàðàìåòðîâ â ñòðîêå
 þíèòå ïðåäñòàâëåíû äâå ôóíêöèè, îäíà èç êîòîðûõ, GetParamFromString, ïîçâîëÿåò ïîëó÷èòü ïàðàìåòð èç ñòðîêè, ïî èíäåêñó ýòîãî ïàðàìåòðà (èíäåêñàöèÿ íà÷èíàåòñÿ ñ 1). Ïàðàìåòðîâ â ñòðîêå, ÿ íàçûâàþ ÷àñòè ñòðîê, ðàçäåë¸ííûå êàêèì-íèáóäü îãîâîð¸ííûì ðàçäåëèòåëåì, íàïðèìåð ñèìâîëîì ";".
Ê ïðèìåð ñòðîêà "fex;9x-1;code" èìååò òðè ïàðàìåòðà:
fex
9x-1
code.
Îïèñàíèå àðãóìåíòîâ ôóíêöèè GetParamFromString:
SourceStr - ñòðîêà, ñîäåðæàùàÿ â ñåáå ïàðàìåòðû;
Delimiter - ðàçäåëèòåëü ïàðàìåòðîâ â ñòðîêå;
Ind - èíäåêñ çàïðàøèâàåìîãî ïàðàìåòðà.
Ôóíêöèÿ GetParamsCount ïðîñòî âîçâðàùàåò êîëè÷åñòâî ïàðàìåòðîâ â ñòðîêå.
Îïèñàíèå àðãóìåíòîâ ôóíêöèè GetParamsCount:
SourceStr - ñòðîêà, ñîäåðæàùàÿ â ñåáå ïàðàìåòðû;
Delimiter - ðàçäåëèòåëü ïàðàìåòðîâ â ñòðîêå;
Çàâèñèìîñòè: Windows
Àâòîð: VID, ICQ:132234868, Ìàõà÷êàëà
Copyright: (c) íå ìî¸
Äàòà: 26 àïðåëÿ 2004 ã.
********************************************** }
unit getstrparam;
interface
uses Windows;
type
TDelim = set of Char;
TArrayOfString = Array of String;
function GetParamsCount(const SourceStr, Delimiter: String): integer;
function GetParamFromString(const SourceStr, Delimiter: String;
Ind: integer): string;
function fcToParts(sString: String; tdDelim: TDelim): TArrayOfString;
implementation
function GetDTextItem(DText, delimeter: pchar; var idx: integer): pchar;
var
nextpos: pchar;
i, len, p: integer;
begin
result := DText;
len := length(delimeter);
if (len = 0) or (DText = '') then
exit;
i := 1;
while TRUE do
begin
p := pos(delimeter, result);
if (p <> 0) then
nextpos := pointer(integer(result) + p - 1)
else
nextpos := pointer(integer(result) + length(result));
if (i = idx) or (p = 0) then
break;
result := pointer(integer(nextpos) + len);
inc(i);
end;
if i = idx then
// byte(nextpos^) := 0 { TODO : èñïðàâèòü. èíà÷å íå êîìïèëèòñÿ }
else
// byte(result^) := 0;
end;
function GetDTextCount(DText, delimeter: pchar): integer;
var
subpos: pchar;
i, len: integer;
begin
result := 0;
len := length(delimeter);
if (len = 0) or (DText = '') then
exit;
subpos := DText;
i := pos(delimeter, subpos);
while i <> 0 do
begin
inc(result);
subpos := pointer(integer(subpos) + i + len - 1);
i := pos(delimeter, subpos);
end;
if (byte(subpos^)) <> 0 then
inc(result);
end;
function GetParamsCount(const SourceStr, Delimiter: String): integer;
begin
result := GetDTextCount(pchar(SourceStr), pchar(Delimiter));
end;
function GetParamFromString(const SourceStr, Delimiter: String;
Ind: integer): string;
var
TmpS, TmpRes: pchar;
LRes: integer;
begin
GetMem(TmpS, length(SourceStr) + 1);
try
CopyMemory(TmpS, pchar(SourceStr), length(SourceStr));
byte(pointer(integer(TmpS) + length(SourceStr))^) := 0;
TmpRes := GetDTextItem(TmpS, pchar(Delimiter), Ind);
LRes := length(TmpRes);
SetLength(result, LRes);
CopyMemory(@result[1], TmpRes, LRes);
finally
FreeMem(TmpS);
end;
end;
// *******************
//
// Ðàçáèâàåò ñòðîêó ñ ðàçäåëèòåëÿìè íà ÷àñòè
// è âîçâðàùàåò ìàññèâ ÷àñòåé
//
// fcToParts
//
function fcToParts(sString: String; tdDelim: TDelim): TArrayOfString;
var
iCounter, iBegin: integer;
begin // fc
if length(sString) > 0 then
begin
include(tdDelim, #0);
iBegin := 1;
SetLength(result, 0);
For iCounter := 1 to length(sString) do
begin // for
if (sString[iCounter] in tdDelim) or (iCounter = length(sString)) then
begin
SetLength(result, length(result) + 1);
// if (iCounter - iBegin)>1 then
result[length(result) - 1] := Copy(sString, iBegin, iCounter - iBegin);
iBegin := iCounter + 1;
end;
end; // for
end; // if
end; // fc
{
#0:http:
#1:
#2:parts.japancar.ru
#3:?code=parts
#4:mode=old
#5:cl=search_partsoldng
#6:cl_partCode=3cvFLjAwNg_1316
#7:cl_marka=TOYOTA
#8:cl_model=4RUNNER
#9:cl_kuzovN=kuzov
#10:cl_engineN=dvigatel
#11:cl_modelN=optika
#12:cl_note=primechanie
}
end.