-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_string.nolol
107 lines (81 loc) · 1.62 KB
/
lib_string.nolol
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
102
103
104
105
106
include "std/string"
//include "debug"
define NEW_LINE="\n"
// outputs digit d from char c
// from https://github.com/Jerald/yolol-is-cylons/blob/master/thinktank/Str2num.md#Final-Version--Universal
macro char_parse_digit(b, c, d) block
//assert(string_contains("0123456789","d"), "invalid character")
if b<=10 then
d=5*(c>4)
d+=2*(c>(d+1))
d+=c>d
d+=c>d
end
end
macro string_deque(str, out) block
out=str
--str
out-=str
// out=str- --str
end
macro string_empty(str) expr
str==""
end
macro string_not_empty(str) expr
str!=""
end
macro string_read_until(out, str, seperator)<ignore> block
ignore=""
while ignore!=seperator and string_not_empty(str) do
out=ignore+out
string_pop(str,ignore)
//ignore=str
//ignore-=str--
end
end
macro string_parse_integer(base, str, out) block
power = 1
out=0
while string_not_empty(str) do
string_pop(str,c)
char_parse_digit(base, c,digit)
out+=digit*power
power *= base
end
end
// runs anywhere
macro string_parse_number(str, out) block
tmp=""
string_reverse(str,tmp)
str=tmp
out=0
tmp=0
while i!="" do
string_pop(str,char)
if c<0 then
// im a decimal
out/=1000
else
char_parse_digit_base10(char,digit)
end
// parse digit
o+=d*10^j++
goto 2+c<0
o=n*(1-2*(c<0))
n/=b^--j
j=0
end
end
// asserteq(1,:d,"char_parse_digit_base10 1")
//char_parse_digit_base10("2",:d)
//asserteq(2,:d,"char_parse_digit_base10 1")
macro test_string() block
end
// hello="hello world"
// string_read_until(out,hello," ")
// :c1 = c1
// :d1 = d1
//string_parse_integer(str, o)
//:out = o $
// info("finished tests")
//:Exit=1