Vivianne Langdon
31012d5b8f
- We change the stream iterator to *always* return a grapheme (except for EOF). The grapheme then gets built up over time. - This way, trans flag for example is first white flag, then white flag + zwj, etc until it finally transforms into the trans flag. - Users of the stream library can then use the `modification?' flag to determine if the stream value is a modification of the prior grapheme instead of a new grapheme. - Abstracted iteration to an iterator object to support use cases where we don't have an input stream (reflow needs this!)
24 lines
736 B
Scheme
24 lines
736 B
Scheme
(define-module (uniseg graphemes stream)
|
|
#:use-module (uniseg graphemes iterator)
|
|
#:use-module (ice-9 textual-ports)
|
|
#:use-module (srfi srfi-41)
|
|
#:export (string->grapheme-stream
|
|
input->grapheme-stream))
|
|
|
|
(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))
|