Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PRG49 - Сопоставление с шаблоном. Звёздочки, вопpосики. Паскаль.

0 views
Skip to first unread message

FAQServer

unread,
Aug 30, 2023, 12:45:01 AM8/30/23
to
[Q]: Сопоставление с шаблоном. Звёздочки, вопpосики. Паскаль.

[A]: Vadim Rumyantsev (2:5030/301)


UNIT UslPatrn;



INTERFACE



function MatchLineOk (pattern, line : string) : boolean;
function MatchFileOk (pattern, name : string) : boolean;



IMPLEMENTATION



uses Dos;



function MatchLineOk;



function SubOk (ppos, lpos : byte) : boolean;

begin

if ppos > length (pattern) then
SubOk := lpos > length (line)
else if lpos > length (line) then
SubOk := (pattern [ppos] = '*') and SubOk (ppos+1, lpos)
else if pattern [ppos] = '*' then begin
SubOk := false;
for lpos := length (line) + 1 downto lpos do
if SubOk (ppos+1, lpos) then begin
SubOk := true;
break
end
end
else
SubOk := ((pattern [ppos] = '?') or
(pattern [ppos] = line [lpos])) and
SubOk (ppos+1, lpos+1)

end;



begin

MatchLineOk := SubOk (1, 1)

end;



function MatchFileOk;

var
pd, nd : DirStr;
pn, nn : NameStr;
px, nx : ExtStr;

begin

FSplit (pattern, pd, pn, px);
FSplit (name, nd, nn, nx);

MatchFileOk := ((pd = '') or (pd = nd)) and
MatchLineOk (pn, nn) and
MatchLineOk (px, nx)

end;



END.

0 new messages