]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/breaks/breaks-docs.factor
Merge branch 'master' into experimental
[factor.git] / basis / unicode / breaks / breaks-docs.factor
1 USING: help.syntax help.markup strings ;
2 IN: unicode.breaks
3
4 ABOUT: "unicode.breaks"
5
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 } ;
16
17 HELP: first-grapheme
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." } ;
20
21 HELP: last-grapheme
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." } ;
24
25 HELP: >graphemes
26 { $values { "str" string } { "graphemes" "an array of strings" } }
27 { $description "Divides a string into a sequence of individual graphemes." } ;
28
29 HELP: string-reverse
30 { $values { "str" string } { "rts" string } }
31 { $description "Reverses a string, leaving graphemes in-tact." } ;
32
33 HELP: first-word
34 { $values { "str" string } { "i" "index" } }
35 { $description "Finds the length of the first word in the string." } ;
36
37 HELP: >words
38 { $values { "str" string } { "words" "an array of strings" } }
39 { $description "Divides the string up into words." } ;