ref: b17873ed4e6a14786758fd68290ef572b0b88f10
parent: 7d4e8b50cac2af2cce372bfbebc3addc752eab25
author: Ori Bernstein <[email protected]>
date: Sun Oct 14 08:06:42 EDT 2018
Fix boundary-spanning delimiters.
--- a/.gitignore
+++ b/.gitignore
@@ -27,10 +27,3 @@
support/mdumpleak
myrbuild/myrbuild
lib/regex/redump
-
-# test outputs
-*.log
-**/test/*
-!**/test/data/*
-!**/test/*.myr
-!**/test/runtest.sh
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -409,9 +409,11 @@
}
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 @@
| `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 @@
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
--- a/lib/bio/test/bio-skipto.myr
+++ b/lib/bio/test/bio-skipto.myr
@@ -21,6 +21,18 @@
| `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")
}
--- /dev/null
+++ b/lib/bio/test/data/bio-skipto-16kbound
@@ -1,0 +1,1 @@
+...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
\ No newline at end of file
--- /dev/null
+++ b/lib/bio/test/data/bio-skipto-16kspan
@@ -1,0 +1,1 @@
+...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
\ No newline at end of file