7493 ficl: want additional softwords
[unleashed.git] / usr / src / common / ficl / softcore / wordsets.fr
blob0658b69270ffcc086b770666100ce53fa486988d
2 \ This file and its contents are supplied under the terms of the
3 \ Common Development and Distribution License ("CDDL"), version 1.0.
4 \ You may only use this file in accordance with the terms of version
5 \ 1.0 of the CDDL.
7 \ A full copy of the text of the CDDL should have accompanied this
8 \ source.  A copy of the CDDL is also available via the Internet at
9 \ http://www.illumos.org/license/CDDL.
11 \ Copyright 2016 Toomas Soome <tsoome@me.com>
13 \ This file is part of the softcore, implementing [partial] word sets.
15 \ Optional String word set.
16 \ compare is implemented in ficl core.
18 \ search ( c-addr1 u1 c-addr2 u2 -- c-addr3 u3 flag )
19 \ Search the string specified by c-addr1 u1 for the string specified by
20 \ c-addr2 u2. If flag is true, a match was found at c-addr3 with u3 characters
21 \ remaining. If flag is false there was no match and c-addr3 is c-addr1 and u3
22 \ is u1.
23 : search { c-addr1 u1 c-addr2 u2 | saved-addr1 saved-u1 -- c-addr3 u3 flag }
24         c-addr1 to saved-addr1  \ save original c-addr1
25         u1 to saved-u1          \ save original u1
26         begin
27                 c-addr1 u1 u2 < if u1 else u2 then
28                 c-addr2 u2 compare
29         while
30                 c-addr1 1+ to c-addr1
31                 u1 1- to u1
32                 u1 0= if
33                         saved-addr1 saved-u1 0 exit     \ not found
34                 then
35         repeat
36         c-addr1 u1 -1