ref: 6940a02fd47d73ba5dd0ad3a82b1945b639a23dc
parent: 770c90d4a5b16a5d598072b6983e50969151b166
author: Ori Bernstein <[email protected]>
date: Thu Mar 21 16:18:52 EDT 2019
Commit bio.readterm
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -28,7 +28,7 @@
/* 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 @@
}
/* same as readto, but includes the delimiter if it was found */
-const readtoinc = {f, delim
+const readterm = {f, delim
-> readdelim(f, delim, `Keep)
}
--- /dev/null
+++ b/lib/bio/test/bio-readterm.myr
@@ -1,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")
+ ;;
+}
--- a/lib/bio/test/bio-readtoinc.myr
+++ /dev/null
@@ -1,30 +1,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")
- ;;
-}
--- a/lib/bio/test/bld.sub
+++ b/lib/bio/test/bld.sub
@@ -14,6 +14,14 @@
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
--- /dev/null
+++ b/lib/bio/test/data/bio-readterm
@@ -1,0 +1,2 @@
+data with semicolon;multiple delims]]]a new line
+data separated,with commas until,no more
--- a/lib/bio/test/data/bio-readtoinc
+++ /dev/null
@@ -1,2 +1,0 @@
-data with semicolon;multiple delims]]]a new line
-data separated,with commas until,no more