guile-uniseg/uniseg/graphemes.scm

43 lines
1.3 KiB
Scheme

(define-module (uniseg graphemes)
#:use-module (ice-9 hash-table)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9 gnu)
#:export (make-grapheme
grapheme?
grapheme-width
grapheme-delta-width
grapheme-modification?
grapheme-glyphs
grapheme-glyphs-reverse
grapheme-state
grapheme-string))
(define-immutable-record-type <grapheme>
(_make-grapheme width delta-width modification? state glyphs-reverse glyphs-promise string-promise)
grapheme?
(width grapheme-width)
(delta-width grapheme-delta-width)
(modification? grapheme-modification?)
(state grapheme-state)
(glyphs-reverse grapheme-glyphs-reverse)
(glyphs-promise _grapheme-glyphs-promise)
(string-promise _grapheme-string-promise))
(define (make-grapheme width delta modification? state glyphs-reverse)
(_make-grapheme
width
delta
modification?
state
glyphs-reverse
(delay (reverse (glyphs-reverse)))
(delay (reverse-list->string glyphs-reverse))))
(define (grapheme-glyphs grapheme)
"Return a lazily-constructed list of glyphs in the grapheme"
(force (_grapheme-glyphs-promise grapheme)))
(define (grapheme-string grapheme)
"Return a lazily-constructed string of the glyphs in the grapheme."
(force (_grapheme-string-promise grapheme)))