summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rw-r--r--lib/bio/bio.myr20
-rw-r--r--lib/bio/test/bio-skipto.myr12
-rw-r--r--lib/bio/test/data/bio-skipto-16kbound1
-rw-r--r--lib/bio/test/data/bio-skipto-16kspan1
5 files changed, 26 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index 76ac5a8..91c01f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,10 +27,3 @@ mbld/mbld
support/mdumpleak
myrbuild/myrbuild
lib/regex/redump
-
-# test outputs
-*.log
-**/test/*
-!**/test/data/*
-!**/test/*.myr
-!**/test/runtest.sh
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr
index eb55069..2284959 100644
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -409,9 +409,11 @@ const unwrapc = {cc, v
}
const readdelim = {f, delim, drop
- var ret
+ var ret, i, j
+ var pr
ret = [][:]
+ pr = false
while true
match ensureread(f, delim.len)
| `std.Err `Eof:
@@ -434,25 +436,27 @@ const readdelim = {f, delim, drop
| `std.Err e: -> `std.Err e
| `std.Ok _: /* nothing: scan the buffer */
;;
- for var i = f.rstart; i < f.rend - delim.len; i++
- for var j = 0; j < delim.len; j++
+ for i = f.rstart; i <= f.rend - delim.len; i++
+ for j = 0; j < delim.len; j++
if f.rbuf[i + j] != delim[j]
- goto nextiterread
+ goto notfound
;;
;;
+ /* If we found it, return that information */
if !drop
readinto(f, &ret, i - f.rstart)
else
- f.rstart += i - f.rstart
+ f.rstart = i
;;
f.rstart += delim.len
-> `std.Ok ret
-:nextiterread
+:notfound
+ f.rstart = i
;;
if !drop
readinto(f, &ret, f.rend - f.rstart)
else
- f.rstart += f.rend - f.rstart
+ f.rstart = i
;;
;;
std.die("unreachable")
@@ -520,7 +524,7 @@ const ensureread = {f, n
match fill(f, n)
| `std.Err e: -> `std.Err e
| `std.Ok len:
- if len >= n
+ if held + len >= n
-> `std.Ok len
else
-> `std.Err `Eof
diff --git a/lib/bio/test/bio-skipto.myr b/lib/bio/test/bio-skipto.myr
index 6a66d9c..862a896 100644
--- a/lib/bio/test/bio-skipto.myr
+++ b/lib/bio/test/bio-skipto.myr
@@ -21,6 +21,18 @@ const main = {
| `std.Err e: std.fatal("expected EOF, got {}\n", e)
;;
+ /* Ensure we find a delimiter if it spans a 16k boundary */
+ f = std.try(bio.open("data/bio-skipto-16kspan", bio.Rd))
+ if !bio.skipto(f, "ABCDE")
+ std.fatal("failed to find ABCDE spanning boundary")
+ ;;
+
+ /* Ensure we find a delimiter if it ends on a 16k boundary */
+ f = std.try(bio.open("data/bio-skipto-16kbound", bio.Rd))
+ if !bio.skipto(f, "ABCDE")
+ std.fatal("failed to find ABCDE at end of buffer")
+ ;;
+
std.put("success: all reads matched\n")
}
diff --git a/lib/bio/test/data/bio-skipto-16kbound b/lib/bio/test/data/bio-skipto-16kbound
new file mode 100644
index 0000000..7a5dc65
--- /dev/null
+++ b/lib/bio/test/data/bio-skipto-16kbound
@@ -0,0 +1 @@
+..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ABCDE
diff --git a/lib/bio/test/data/bio-skipto-16kspan b/lib/bio/test/data/bio-skipto-16kspan
new file mode 100644
index 0000000..d1e348a
--- /dev/null
+++ b/lib/bio/test/data/bio-skipto-16kspan
@@ -0,0 +1 @@
+.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ABCDE