first-grapheme ( entire-str start -- i )
Word and grapheme breaks

Next:first-grapheme-from ( start str -- i )


Vocabulary
unicode

Inputs
entire-stra string
starta string


Outputs
ian index


Word description
Finds the length of the first grapheme of the string. This can be used repeatedly to efficiently traverse the graphemes of the string, using slices.

Definition


:: first-grapheme ( entire-str start -- i )
start :> pos! entire-str length :> str-len 0 pos 1 +
entire-str <slice> grapheme-class pos 1 + str-len 1 - min
pos! pos str-len 1 - [a..b] [
1 + 0 swap entire-str <slice>
grapheme-class dup rot swap grapheme-break?
] find drop nip [ 1 + ] [ str-len start - ] if* ;