]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/breaks/breaks-docs.factor
unicode: make this the API for all unicode things.
[factor.git] / basis / unicode / breaks / breaks-docs.factor
1 USING: help.syntax help.markup strings unicode ;
2 IN: unicode.breaks
3
4 ABOUT: "unicode.breaks"
5
6 ARTICLE: "unicode.breaks" "Word and grapheme breaks"
7 "The " { $vocab-link "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 { $subsections
10     first-grapheme
11     first-grapheme-from
12     last-grapheme
13     last-grapheme-from
14     >graphemes
15     string-reverse
16 }
17 "Operations on words:"
18 { $subsections
19     first-word
20     first-word-from
21     last-word
22     last-word-from
23     >words
24 } ;
25
26 HELP: first-grapheme
27 { $values { "str" string } { "i" "an index" } }
28 { $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." } ;
29
30 HELP: last-grapheme
31 { $values { "str" string } { "i" "an index" } }
32 { $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." } ;
33
34 HELP: first-grapheme-from
35 { $values { "start" "an index" } { "str" string } { "i" "an index" } }
36 { $description "Finds the length of the first grapheme of the string, starting from the given index. This can be used repeatedly to efficiently traverse the graphemes of the string, using slices." } ;
37
38 HELP: last-grapheme-from
39 { $values { "end" "an index" } { "str" string } { "i" "an index" } }
40 { $description "Finds the index of the start of the last grapheme of the string, starting from the given index. This can be used to traverse the graphemes of a string backwards." } ;
41
42 HELP: >graphemes
43 { $values { "str" string } { "graphemes" "an array of strings" } }
44 { $description "Divides a string into a sequence of individual graphemes." } ;
45
46 HELP: string-reverse
47 { $values { "str" string } { "rts" string } }
48 { $description "Reverses a string, leaving graphemes in-tact." } ;
49
50 HELP: first-word
51 { $values { "str" string } { "i" "index" } }
52 { $description "Finds the index of the end of the first word in the string." } ;
53
54 HELP: last-word
55 { $values { "str" string } { "i" "index" } }
56 { $description "Finds the index of the beginning of the last word in the string." } ;
57
58 HELP: first-word-from
59 { $values { "start" "index" } { "str" string } { "i" "index" } }
60 { $description "Finds the index of the end of the first word in the string, starting from the given index." } ;
61
62 HELP: last-word-from
63 { $values { "end" "index" } { "str" string } { "i" "index" } }
64 { $description "Finds the index of the start of the word that the index is contained in." } ;
65
66 HELP: >words
67 { $values { "str" string } { "words" "an array of strings" } }
68 { $description "Divides the string up into words." } ;