1 USING: help.syntax help.markup strings ;
4 ABOUT: "unicode.breaks"
6 ARTICLE: "unicode.breaks" "Word and grapheme breaks"
7 "The " { $vocab-link "unicode.breaks" "unicode.breaks" } " vocabulary partially implements Unicode Standard Annex #29. This provides for segmentation of a string along grapheme and word boundaries. In Unicode, a grapheme, or a basic unit of display in text, may be more than one code point. For example, in the string \"e\\u000301\" (where U+0301 is a combining acute accent), there is only one grapheme, as the acute accent goes above the e, forming a single grapheme. Word breaks, in general, are more complicated than simply splitting by whitespace, and the Unicode algorithm provides for that."
8 $nl "Operations for graphemes:"
9 { $subsection first-grapheme }
10 { $subsection last-grapheme }
11 { $subsection >graphemes }
12 { $subsection string-reverse }
13 "Operations on words:"
14 { $subsection first-word }
15 { $subsection >words } ;
18 { $values { "str" string } { "i" "an index" } }
19 { $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." } ;
22 { $values { "str" string } { "i" "an index" } }
23 { $description "Finds the index of the start of the last grapheme of the string. This can be used to traverse the graphemes of a string backwards." } ;
26 { $values { "str" string } { "graphemes" "an array of strings" } }
27 { $description "Divides a string into a sequence of individual graphemes." } ;
30 { $values { "str" string } { "rts" string } }
31 { $description "Reverses a string, leaving graphemes in-tact." } ;
34 { $values { "str" string } { "i" "index" } }
35 { $description "Finds the length of the first word in the string." } ;
38 { $values { "str" string } { "words" "an array of strings" } }
39 { $description "Divides the string up into words." } ;