-
Notifications
You must be signed in to change notification settings - Fork 3
/
string.fs
52 lines (38 loc) · 996 Bytes
/
string.fs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
\ these words are likely better off being written in asm?...
local.start
0 VALUE caddr1 LOCAL
0 VALUE caddr2 LOCAL
0 VALUE u1 LOCAL
0 VALUE u2 LOCAL
: COMPARE ( caddr1 u1 caddr2 u2 -- -1/0/1 )
TO u2 TO caddr2 TO u1 TO caddr1
BEGIN
caddr2 count caddr1 count ( caddr2+1 c2 caddr1+1 c1 )
ROT ( caddr2+1 caddr1+1 c1 c2 )
2DUP < IF 2DROP 2DROP -1 EXIT THEN
> IF 2DROP 1 EXIT THEN
TO caddr1 TO caddr2
-1 +TO u1 -1 +TO u2
u1 0= IF u2 IF -1 EXIT THEN 0 EXIT THEN
u2 0= IF 1 EXIT THEN
AGAIN
;
local.end
local.start
0 VALUE caddr1 LOCAL
0 VALUE caddr2 LOCAL
0 VALUE u1 LOCAL
0 VALUE u2 LOCAL
: SEARCH ( caddr1 u1 caddr2 u2 -- caddr3 u3 f )
2OVER TO u1 TO caddr1 TO u2 TO caddr2 ( caddr1 u1 )
BEGIN
caddr1 u2 caddr2 u2 COMPARE 0= IF 2DROP caddr1 u2 TRUE EXIT THEN
1 +TO caddr1 -1 +TO u1
u1 u2 <
UNTIL
FALSE
;
local.end
: upcase! ( c-addr u -- )
OVER + SWAP DO I C@ 'a 'z 1+ WITHIN IF -32 I c+! THEN LOOP
;