From be65c3c929091d703310cf8eed86c0cf15f480e5 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 29 Apr 2012 08:39:39 -0400 Subject: [PATCH] Add behaviour switch after a byte limit is used up. --- stringstream.ml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stringstream.ml b/stringstream.ml index 1555deb..6b101d7 100644 --- a/stringstream.ml +++ b/stringstream.ml @@ -69,3 +69,13 @@ let rec to_list s = let rec to_string s = String.concat "" (to_list s) + +let rec switch_after' on_boundary limit s1 s2 = + if limit > 0 || not on_boundary + then Stream (fun () -> + match run s1 with + | None -> None + | Some (v, f, k) -> Some (v, f, switch_after' f (limit - String.length v) k s2)) + else s2 + +let switch_after limit s1 s2 = switch_after' true limit s1 s2