blob: dbdd025d27fa928e329445ccfad17849495e6807 (
plain)
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
|
use std
use "bio"
pkg bio =
type lineiter = file#
type chariter = file#
impl iterable lineiter -> byte[:]
impl iterable chariter -> char
const byline : (f : file# -> lineiter)
const bychar : (f : file# -> chariter)
;;
const byline = {f
-> (f : lineiter)
}
impl iterable lineiter -> byte[:] =
__iternext__ = {itp, outp
match bio.readln((itp# : file#))
| `Ok ln: outp# = ln
| `Err _: -> false
| `Eof: -> false
;;
-> true
}
__iterfin__ = {itp, outp
std.slfree(outp#)
}
;;
const bychar = {f
-> (f : chariter)
}
impl iterable chariter -> char =
__iternext__ = {itp, outp : char#
match bio.getc((itp# : file#))
| `Ok c: outp# = c
| `Err _: -> false
| `Eof: -> false
;;
-> true
}
__iterfin__ = {itp, outp
}
;;
|