Handbook
Glossary
first-grapheme ( entire-str start -- i )
Word and grapheme breaks
Next:
first-grapheme-from ( start str -- i )
Vocabulary
unicode
Inputs
entire-str
a
string
start
a
string
Outputs
i
an 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
USING:
kernel
math
math.order
ranges
sequences
unicode.breaks.private
;
IN:
unicode
::
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*
;