summaryrefslogtreecommitdiff
path: root/stream.sml
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-05-18 12:07:58 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-05-18 12:07:58 +0200
commit183a4420d2f2a985dd26d76e63c2cdcaafedc5ad (patch)
tree8fbb929bedf4196aab73a0b630bda38cd58d4cdf /stream.sml
parent5edd85474d6d8f3a0cc06cc0250ed3db8b26fcfa (diff)
Conditional inclusion
Diffstat (limited to 'stream.sml')
-rw-r--r--stream.sml17
1 files changed, 17 insertions, 0 deletions
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 =