A small wildcard matching algorithm
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
A small wildcard matching algorithm         


Author: Charles Melice
Date: Oct 15, 2006 02:36

\ A small wildcard matching algorithm.
\ Converted from Jack Handy "wildcmp" C source.
\ see https://secure.codeproject.com/string/wildcmp.asp

\ WILDCARD-MATCH ( text ntext wild nwild -- flag )
(
s" bl?h.*" s" blah.jpg" WILD-COMPARE if
." we have a match!"
else
." no match"
then ;
)

\ NB: ANDIF, ORIF see Neil Bawd http://home.earthlink.net/~neilbawd/

char * constant '*'
char ? constant '?'

: up2 ( a b -- A B ) upper swap upper ;
: ucharC ( a n i -- c ) tuck > if chars + c@ else 2drop 0 then ;

: textC ( -- C ) s" text nt it ucharC" evaluate ; immediate
: wildC ( -- C ) s" wild nw iw ucharC" evaluate ; immediate
Show full article (2.82Kb)
86 Comments
Re: A small wildcard matching algorithm         


Author: Marcel Hendrix
Date: Oct 15, 2006 11:40

"Charles Melice" forthcad.com> writes Re: A small wildcard matching algorithm
> \ A small wildcard matching algorithm.
> \ Converted from Jack Handy "wildcmp" C source.
> \ see https://secure.codeproject.com/string/wildcmp.asp

Neat! Especially the poem.

Three remarks:

1.
| \ WILDCARD-MATCH ( text ntext wild nwild -- flag )
| (
| s" bl?h.*" s" blah.jpg" WILD-COMPARE if
| ." we have a match!"
| else
| ." no match"
| then ;
| )
Show full article (1.05Kb)
83 Comments
Re: A small wildcard matching algorithm         


Author: Charles Melice
Date: Oct 16, 2006 00:07

"Marcel Hendrix" a
82 Comments
Re: A small wildcard matching algorithm         


Author: The Beez'
Date: Oct 16, 2006 06:08

Charles Melice wrote:
This is a version without locals nor toolbelt extensions. Don't ask me
how portable it is. It should be, but it isn't tested.

Hans Bezemer

-- CUT HERE --
\ 4tH library - WILDCARD - Copyright 2006 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

\ int wildcmp (const char *wild, const char *string) {
\ // Written by Jack Handy - jakkhandy@hotmail.com
\ const char *cp = NULL, *mp = NULL;

\ while ((*string) && (*wild != '*')) {
\ if ((*wild != *string) && (*wild != '?')) {
\ return 0;
\ }
\ wild++;
\ string++;
\ }
Show full article (3.10Kb)
81 Comments
Re: A small wildcard matching algorithm         


Author: Charles Melice
Date: Oct 16, 2006 08:09

"The Beez'" bigfoot.com> a
80 Comments
Re: A small wildcard matching algorithm         


Author: Charles Melice
Date: Oct 16, 2006 08:30

"Charles Melice" forthcad.com> a
61 Comments
Re: A small wildcard matching algorithm         


Author: The Beez'
Date: Oct 16, 2006 10:05

Yes, it is case sensitive. I can always apply filters if I want (I got
those in my toolbox too ;-). True, I don't like locals nor variables.
So, I have to refer to stack juggling. The functions I used (s= s? s<>)
already take some of the "unreadability" away, but we've got still a
lot of items on our hand. Note I use the return stack to store the
temporaries and the data stack to store the ANS compatible addr/count
pointers in the order "wild string". The temporary flags are
transferred to the return stack until evaluated.

Hans Bezemer
57 Comments
Re: A small wildcard matching algorithm         


Author: Charles Melice
Date: Oct 16, 2006 13:41

"The Beez'" bigfoot.com> a
56 Comments
Re: A small wildcard matching algorithm         


Author: Jos van de Ven
Date: Oct 16, 2006 15:23

"Charles Melice" wrote:
> "The Beez'" bigfoot.com> a écrit dans le message de news:
> 1161004128.441423.107200@f16g2000cwb.googlegroups.com...
>> Charles Melice wrote:
>> This is a version without locals nor toolbelt extensions. Don't ask me
>> how portable it is. It should be, but it isn't tested.
>
> Nice !
>
> I hesited to do that because it's really unreadable...
>
> Notice that you have an error for the next case:
>
> s" *in*so?t*" test \ ---> In each soft corner
>
> If you don't like LOCALS, the next version is very similar
> but using globals variables...
> : WILDCARD-MATCH ( text nt wild nw -- flag )
Show full article (0.86Kb)
17 Comments
Re: A small wildcard matching algorithm         


Author: Marcel Hendrix
Date: Oct 16, 2006 21:34

"Jos van de Ven" wrote Re: A small wildcard matching algorithm
[..]
> I think that it would be very usefull when WILDCARD-MATCH also
> returns the adres and count of the found string.

( not tested )

: $WILDCARD-MATCH ( text nt wild nw
-- c-addr u TRUE=match )
2OVER 2SWAP WILDCARD-MATCH ;

-marcel
16 Comments
1 2 3 4 5 6 7 8 9