From 183a4420d2f2a985dd26d76e63c2cdcaafedc5ad Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Sun, 18 May 2025 12:07:58 +0200 Subject: Conditional inclusion --- stream.sml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'stream.sml') diff --git a/stream.sml b/stream.sml index fd5932a..4ea7f08 100644 --- a/stream.sml +++ b/stream.sml @@ -52,6 +52,23 @@ structure Stream :> STREAM = struct fun getSubstr startOff endOff ({ contents, ... }: t) = String.substring (contents, startOff, endOff - startOff) + fun getLine (S as { contents, off, ... }: t) = + let + fun find off = + if off = size contents then + NONE + else + if String.sub (contents, off) = #"\n" then + SOME off + else + find (off + 1) + in + case find off of + SOME off' => + (SOME $ getSubstr off off' S, updateStream S s#off off' %) + | NONE => (NONE, S) + end + fun getFname ({ fname, ... }: t) = fname fun createFromInstream fname instream = -- cgit v1.2.3