2024-03-04 01:25:47 +00:00
|
|
|
(define-module (uniseg graphemes stream)
|
2024-03-05 16:46:32 +00:00
|
|
|
#: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)
|
2024-03-05 16:46:32 +00:00
|
|
|
#: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."
|
2024-03-05 16:46:32 +00:00
|
|
|
(call-with-input-string str input->grapheme-stream))
|
2024-03-04 19:04:27 +00:00
|
|
|
|
|
|
|
|
2024-03-05 16:46:32 +00:00
|
|
|
(define (input->grapheme-stream port)
|
|
|
|
"Given an input port, create a (lazy) stream of graphemes."
|
|
|
|
(define grapheme-iterator (make-grapheme-iterator))
|
2024-03-04 19:04:27 +00:00
|
|
|
|
2024-03-05 16:46:32 +00:00
|
|
|
(define-stream (grapheme-stream)
|
|
|
|
(define grapheme (grapheme-iterator (get-char port)))
|
2024-03-04 19:04:27 +00:00
|
|
|
|
2024-03-05 16:46:32 +00:00
|
|
|
(if grapheme
|
|
|
|
(stream-cons grapheme (grapheme-stream))
|
|
|
|
stream-null))
|
2024-03-04 19:04:27 +00:00
|
|
|
|
2024-03-05 16:46:32 +00:00
|
|
|
(grapheme-stream))
|