-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.goof
More file actions
101 lines (94 loc) · 1.89 KB
/
string.goof
File metadata and controls
101 lines (94 loc) · 1.89 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const sizeof(str) 16 end
macro str.count 0 + end
macro str.data 8 + end
// count "string" ptr -->
proc store_str ptr ptr int -- --
over over
str.data swap .64
swap drop
str.count swap .64
end
// ptr --> count "string"
proc read_str ptr -- int ptr --
dup str.count ,64
swap str.data ,64
end
macro chop_left // input
dup str.count dup ,64 1 - .64
dup str.data dup ,64 1 + .64
drop
end
proc str_trim_left ptr -- --
while
if dup str.count ,64 0 > do
dup str.data ,64 (ptr) , 32 =
else
0 (bool)
end
do
dup chop_left
end
drop
end
proc str_chop_line ptr ptr -- --
2dup str.data ,64 swap str.data swap .64
over str.count 0 .64
while
if dup str.count ,64 0 > do
dup str.data ,64 (ptr) , 10 !=
else
0 (bool)
end
do
dup chop_left
swap
dup str.count dup ,64 1 + .64
swap
end
if dup str.count ,64 0 > do
dup chop_left
end
drop drop
end
proc str_chop_word ptr ptr -- --
2dup str.data ,64 swap str.data swap .64
over str.count 0 .64
while
if dup str.count ,64 0 > do
dup str.data ,64 (ptr) , 32 !=
else
0 (bool)
end
do
dup chop_left
swap
dup str.count dup ,64 1 + .64
swap
end
if dup str.count ,64 0 > do
dup chop_left
end
drop drop
end
proc is_number ptr -- bool --
// &string i
0 while
if over str.count ,64 over > do
2dup
// &string i &string i
swap str.data ,64 + , '0' - // &string i string->data[i]
dup -1 > swap 10 < &
else
0 (bool)
end
do
1 +
end
// &string i
if over str.count ,64 over = do
1 (bool)
else
0 (bool)
end
rot drop drop
end