🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10245

Re: MatchesMask function and wildcards question

#10245
From: Mark Jacobs
Date: Fri, 07 May 2004 13:16
183 lines
4319 bytes
Use the Regular exzpression engine, and use these (the routine wildfiles matches semicolon delimited masks) :-



AnsiString getdelimel(AnsiString alphstr,AnsiString dlms,int el)

{

  int gto=1; char *pt=alphstr.c_str(); AnsiString cret="";

  while (*pt)

  {

    if (strchr(dlms.c_str(),*pt)) { if (gto==el) break; else ++gto;}

    else if (gto==el) cret+=AnsiString(*pt);

    ++pt;

  }

  if (*pt=='\0' && cret.Length()==0) cret="\n";

  return cret;

}



AnsiString mjstrtorx(AnsiString str)

{

  static AnsiString olret="",olstr=""; AnsiString retv="";

  if (olstr==str) return olret;

  int ii,jj=str.Length();

  for (ii=1;ii<=jj;++ii)

  {

    if (strchr("[\\^$.|+()",str[ii])) retv+="\\"+AnsiString(str[ii]);

    else if (str[ii]=='*') retv+=".*";

    else if (str[ii]=='?') retv+=".{1}";

    else retv+=AnsiString(str[ii]);

  }

  olstr=str; olret=retv;

  return retv;

}



pcre *mjre_compile(AnsiString rexp)

{

  const char *errstr[250]; int wherr; pcre *compre;

  compre=pcre_compile(rexp.c_str(),0,errstr,&wherr,NULL);

  if (!compre)

  {

    reprob=true;

    ShowMessage("Regular Expression Error :-\n"+AnsiString(*errstr)+"\n"+

    rexp.SubString(1,wherr)+" HERE-->"+rexp.SubString(wherr+1,rexp.Length()));

  }

  return compre;

}



bool mjre_test(AnsiString rexp,AnsiString str)

{

  pcre *compre; bool retv=false;

  reprob=false; compre=mjre_compile("(?U)"+rexp);

  if (compre) { retv=mjre_exec(compre,str); pcre_free(compre);}

  return retv;

}



bool mjre_exec(pcre *compre,AnsiString str)

{

  int wherr,offo[999];

  lnparsed=0; locfnd=0; genuse="";

  wherr=pcre_exec(compre,NULL,str.c_str(),str.Length(),0,offo,999);

  if (wherr>=0)

  {

    lnparsed=offo[1]; locfnd=offo[0]+1; genuse=str.SubString(offo[0]+1,offo[1]-offo[0]);

    return true;

  }

  if (wherr<-1) { reprob=true; ShowMessage("Internal PCRE Matching Error");}

  return false;

}



bool wildfiles(AnsiString msk,AnsiString cmp)

{

  AnsiString nxtfl; int el=0;

  while (true)

  {

    ++el; nxtfl=getdelimel(msk,";",el); if (nxtfl.IsEmpty()) continue;

    if (nxtfl=="\n") break;

    else if (nxtfl.SubString(1,5).UpperCase()!="MJRE:") nxtfl="MJRE:(?i)^"+mjstrtorx(nxtfl)+"$";

    if (wildmatches(nxtfl,cmp)) return true;

  }

  return false;

}



bool wildmatches(AnsiString msk,AnsiString cmp)

{

  lnparsed=0; locfnd=0; genuse=""; // Library globals

  if (msk.SubString(1,5).UpperCase()=="MJRE:") return mjre_test(msk.SubString(6,msk.Length()),cmp);

  return mjre_test(mjstrtorx(msk),cmp);

}


-- 
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
markj@criticalremovethisspuriousantispamstuff.co.uk

"Martin C" <martincplus@hotmail.com> wrote in message news:409845a0@newsgroups.borland.com...
> I am using MatchesMask function inside a search for files function inside my
> project, and so far it is working good. Although I need to be able to
> compare the filename inside the MatchesMask with multiple wildcards (ex.
> *.cpp, *.obj, *.asm....etc), so my question is it possible to do so through
> the MatchesMask function? and if not is there any alternative solution?
Technical Details
Message-ID: <409b8c16@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <409845a0@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,b3e4cfc74ec4a42b
X-Google-Attributes: gid10cc67,public
Reply-To: "Mark Jacobs" <markjremovethisspuriousantispamstuff@critical.co.uk>
From: "Mark Jacobs" <markjremovethisspuriousantispamstuff@critical.co.uk>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <409845a0@newsgroups.borland.com>
Subject: Re: MatchesMask function and wildcards question
Date: Fri, 7 May 2004 14:16:11 +0100
Lines: 185
Organization: DK Computing
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 81.144.157.8
Message-ID: <409b8c16@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1083935766 81.144.157.8 (7 May 2004 06:16:06 -0700)
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail