Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 3 odgovora
  • 2.261 pregleda

Najnovija ↓

WildCard (tj. *) string compare? 05.10.2004. u 20:20 · pre 268 meseci #1
Našao sam ovo, ali nešto ne štima:

Code:

type
  PathStr = string[128]; { in Delphi 2/3: = string }
  NameStr = string[12];  { in Delphi 2/3: = string }
  ExtStr  = string[3];   { in Delphi 2/3: = string }

{$V-} { in Delphi 2/ 3 to switch off "strict var-strings" }

function WildComp(FileWild,FileIs: PathStr): boolean;
var
  NameW,NameI: NameStr;
  ExtW,ExtI: ExtStr;
  c: byte;

  function WComp(var WildS,IstS: NameStr): boolean;
  var
    i, j, l, p : Byte;
  begin
    i := 1;
    j := 1;
    while (i<=length(wilds)) do
    begin
      if WildS[i]='*' then
      begin
        if i = length(WildS) then
        begin
          WComp := true;
          exit
        end
        else
        begin
          { we need to synchronize }
          l := i+1;
          while (l and (WildS[l+1] <> '*') do
            inc (l);
          p := pos (copy (WildS, i+1, l-i), IstS);
          if p > 0 then
          begin
            j := p-1;
          end
          else
          begin
            WComp := false;
            exit;
          end;
        end;
      end
      else
      if (WildS[i]<>'?') and ((length(IstS) or (WildS[i]<>IstS[j])) then
      begin
        WComp := false;
     exit
      end;

      inc (i);
      inc (j);
    end;
    WComp := (j > length(IstS));
  end;

begin
  c:=pos('.',FileWild);
  if c=0 then
  begin { automatically append .* }
    NameW := FileWild;
    ExtW  := '*';
  end
  else
  begin
    NameW := copy(FileWild,1,c-1);
    ExtW  := copy(FileWild,c+1,255);
  end;

  c:=pos('.',FileIs);
  if c=0 then
    c:=length(FileIs)+1;
  NameI := copy(FileIs,1,c-1);
  ExtI  := copy(FileIs,c+1,255);
  WildComp := WComp(NameW,NameI) and WComp(ExtW,ExtI);
end;

begin
  if     WildComp('a*.bmp',  'auto.bmp') then ShowMessage('OK 1');
  if not WildComp('a*x.bmp', 'auto.bmp') then ShowMessage('OK 2');
  if     WildComp('a*o.bmp', 'auto.bmp') then ShowMessage('OK 3');
  if not WildComp('a*tu.bmp','auto.bmp') then ShowMessage('OK 4');
end.
Potpis
Laravel Srbija.

[NE PRUŽAM PODRŠKU ZA PHP PREKO PRIVATNIH PORUKA!]
Re: WildCard (tj. *) string compare? 05.10.2004. u 23:27 · pre 268 meseci #2
imas u unitu Masks funkciju
matchesMask(s, mask: string): boolean
na primer matchesMask('bane.bmp', '?a*.bmp') ce vratiti true.
mislim da je tako sintaksa
Potpis
Ride the rainbow, crack the sky

DIY gitare, pojacala i efekti www.diy-fever.com
Re: WildCard (tj. *) string compare? 08.10.2004. u 11:09 · pre 268 meseci #3
Mislim da ti je gornji kod osakacen:
Code:

if (WildS[i]<>'?') and ((length(IstS) or (WildS[i]<>IstS[j])) then


Sta ne valja? Pa, ocigledno je da je autor hteo da sve ovo bude matematicka logika, medjutim drugi deo izraza gore je ispao bitwise OR umesto logicki OR, tako da...ko bi ga znao. Mislim da je u pitanju trapavo prevodjenje sa C-a.

Rajko

P.S. Po nekom mom iskustvu, sve sto je lako dostupno, besplatno itd. uvek ima neku falinku, pa tako i ovaj kod gore.
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme