diff options
author | Ori Bernstein <ori@eigenstate.org> | 2019-03-21 20:18:52 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2019-03-21 20:20:39 -0700 |
commit | 6940a02fd47d73ba5dd0ad3a82b1945b639a23dc (patch) | |
tree | 67f0cd7d6a9e58bef70de07225b4c7157d4c7d4e /lib/bio | |
parent | 770c90d4a5b16a5d598072b6983e50969151b166 (diff) | |
download | mc-6940a02fd47d73ba5dd0ad3a82b1945b639a23dc.tar.gz |
Commit bio.readterm
Diffstat (limited to 'lib/bio')
-rw-r--r-- | lib/bio/bio.myr | 4 | ||||
-rw-r--r-- | lib/bio/test/bio-readterm.myr | 30 | ||||
-rw-r--r-- | lib/bio/test/bio-readtoinc.myr | 30 | ||||
-rw-r--r-- | lib/bio/test/bld.sub | 8 | ||||
-rw-r--r-- | lib/bio/test/data/bio-readterm (renamed from lib/bio/test/data/bio-readtoinc) | 0 |
5 files changed, 40 insertions, 32 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr index 58f6a92..d678c71 100644 --- a/lib/bio/bio.myr +++ b/lib/bio/bio.myr @@ -28,7 +28,7 @@ pkg bio = /* delimited read; returns freshly allocated buffer. */ const readln : (f : file# -> std.result(byte[:], err)) const readto : (f : file#, delim : byte[:] -> std.result(byte[:], err)) - const readtoinc : (f: file#, delim : byte[:] -> std.result(byte[:], err)) + const readterm : (f : file#, delim : byte[:] -> std.result(byte[:], err)) const skipto : (f : file#, delim : byte[:] -> bool) const skipspace : (f : file# -> bool) @@ -329,7 +329,7 @@ const readto = {f, delim } /* same as readto, but includes the delimiter if it was found */ -const readtoinc = {f, delim +const readterm = {f, delim -> readdelim(f, delim, `Keep) } diff --git a/lib/bio/test/bio-readterm.myr b/lib/bio/test/bio-readterm.myr new file mode 100644 index 0000000..ade257e --- /dev/null +++ b/lib/bio/test/bio-readterm.myr @@ -0,0 +1,30 @@ +use std +use bio + +const main = { + var f + + f = std.try(bio.open("data/bio-readterm", bio.Rd)) + + readterm(f, ";") + readterm(f, "]]]") + readterm(f, "\n") + readterm(f, ",") + readterm(f, ",") + readterm(f, ",") + readterm(f, "the end") + + bio.close(f) +} + +const readterm = {f, d + match bio.readterm(f, d) + | `std.Ok s: + std.put("{}\n", s) + std.slfree(s) + | `std.Err `bio.Eof: + std.put("eof\n") + | `std.Err _: + std.put("err\n") + ;; +} diff --git a/lib/bio/test/bio-readtoinc.myr b/lib/bio/test/bio-readtoinc.myr deleted file mode 100644 index a856a92..0000000 --- a/lib/bio/test/bio-readtoinc.myr +++ /dev/null @@ -1,30 +0,0 @@ -use std -use bio - -const main = { - var f - - f = std.try(bio.open("data/bio-readtoinc", bio.Rd)) - - readtoinc(f, ";") - readtoinc(f, "]]]") - readtoinc(f, "\n") - readtoinc(f, ",") - readtoinc(f, ",") - readtoinc(f, ",") - readtoinc(f, "the end") - - bio.close(f) -} - -const readtoinc = {f, d - match bio.readtoinc(f, d) - | `std.Ok s: - std.put("{}\n", s) - std.slfree(s) - | `std.Err `bio.Eof: - std.put("eof\n") - | `std.Err _: - std.put("err\n") - ;; -} diff --git a/lib/bio/test/bld.sub b/lib/bio/test/bld.sub index 66e44e6..3c77c8b 100644 --- a/lib/bio/test/bld.sub +++ b/lib/bio/test/bld.sub @@ -14,6 +14,14 @@ bin delim {test} = lib @/lib/bio:bio ;; +bin term {test} = + bio-readterm.myr + + lib @/lib/std:std + lib @/lib/sys:sys + lib @/lib/bio:bio +;; + bin endianrd {test} = bio-endianrd.myr lib @/lib/std:std diff --git a/lib/bio/test/data/bio-readtoinc b/lib/bio/test/data/bio-readterm index b0a2d25..b0a2d25 100644 --- a/lib/bio/test/data/bio-readtoinc +++ b/lib/bio/test/data/bio-readterm |