File: strcomp.fs

package info (click to toggle)
gforth 0.7.0%2Bds2-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,808 kB
  • sloc: ansic: 8,506; sh: 3,660; lisp: 1,783; makefile: 993; yacc: 186; sed: 141; lex: 102; awk: 21
file content (28 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
\ string comparisons

\ This file is in the public domain. NO WARRANTY.

\ Uses of COMPARE can be replaced with STR=, STRING-PREFIX?, and STR<
\ (and these can be implemented more efficiently and used more easily
\ than COMPARE).  See <news:2002Aug12.110229@a0.complang.tuwien.ac.at>
\ and following.

s" gforth" environment? [if]
    2drop defined str=
[else]
    \ : \G postpone \ ; immediate
    0
[then]
0= [if]

: str= ( c-addr1 u1 c-addr2 u2 -- f ) \ gforth
    compare 0= ;

: string-prefix? ( c-addr1 u1 c-addr2 u2 -- f ) \ gforth
    \G Is @var{c-addr2 u2} a prefix of @var{c-addr1 u1}?
    tuck 2>r min 2r> str= ;

: str< ( c-addr1 u1 c-addr2 u2 -- f ) \ gforth
    compare 0< ;

[then]