1: \ string comparisons
2:
3: \ This file is in the public domain. NO WARRANTY.
4:
5: \ Uses of COMPARE can be replaced with STR=, STRING-PREFIX?, and STR<
6: \ (and these can be implemented more efficiently and used more easily
7: \ than COMPARE). See <news:2002Aug12.110229@a0.complang.tuwien.ac.at>
8: \ and following.
9:
10: s" gforth" environment? [if]
11: 2drop defined str=
12: [else]
13: \ : \G postpone \ ; immediate
14: 0
15: [then]
16: 0= [if]
17:
18: : str= ( c-addr1 u1 c-addr2 u2 -- f ) \ gforth
19: compare 0= ;
20:
21: : string-prefix? ( c-addr1 u1 c-addr2 u2 -- f ) \ gforth
22: \G Is @var{c-addr2 u2} a prefix of @var{c-addr1 u1}?
23: tuck 2>r min 2r> str= ;
24:
25: : str< ( c-addr1 u1 c-addr2 u2 -- f ) \ gforth
26: compare 0< ;
27:
28: [then]
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>