guile-uniseg/uniseg/graphemes/stream.scm

25 lines
736 B
Scheme
Raw Permalink Normal View History

2024-03-04 01:25:47 +00:00
(define-module (uniseg graphemes stream)
#:use-module (uniseg graphemes iterator)
2024-03-04 01:25:47 +00:00
#:use-module (ice-9 textual-ports)
2024-03-03 18:13:22 +00:00
#:use-module (srfi srfi-41)
#:export (string->grapheme-stream
2024-03-03 18:13:22 +00:00
input->grapheme-stream))
2024-03-04 01:25:47 +00:00
(define (string->grapheme-stream str)
"Given a string, create a (lazy) stream of graphemes."
(call-with-input-string str input->grapheme-stream))
(define (input->grapheme-stream port)
"Given an input port, create a (lazy) stream of graphemes."
(define grapheme-iterator (make-grapheme-iterator))
(define-stream (grapheme-stream)
(define grapheme (grapheme-iterator (get-char port)))
(if grapheme
(stream-cons grapheme (grapheme-stream))
stream-null))
(grapheme-stream))