]> gitweb.factorcode.org Git - factor.git/blob - core/strings/strings-docs.factor
88e47d5309433da87916eeaca3ba25585fdb8de7
[factor.git] / core / strings / strings-docs.factor
1 USING: arrays byte-arrays help.markup help.syntax
2 kernel kernel.private strings.private sequences vectors
3 sbufs math ;
4 IN: strings
5
6 ARTICLE: "strings" "Strings"
7 "A string is a fixed-size mutable sequence of Unicode 5.0 code points."
8 $nl
9 "Characters are not a first-class type; they are simply represented as integers between 0 and 16777216 (2^24). Only characters up to 2097152 (2^21) have a defined meaning in Unicode."
10 $nl
11 "String literal syntax is covered in " { $link "syntax-strings" } "."
12 $nl
13 "String words are found in the " { $vocab-link "strings" } " vocabulary."
14 $nl
15 "Strings form a class:"
16 { $subsection string }
17 { $subsection string? }
18 "Creating strings:"
19 { $subsection >string }
20 { $subsection <string> }
21 "Creating a string from a single character:"
22 { $subsection 1string }
23 "Since strings are sequences, basic string manipulation can be performed using sequence operations (" { $link "sequences" } "). More advanced functionality can be found in other vocabularies, including but not limited to:"
24 { $list
25     { { $vocab-link "ascii" } " - traditional ASCII character classes" }
26     { { $vocab-link "unicode.categories" } " - Unicode character classes" }
27     { { $vocab-link "unicode.case" } " - Unicode case conversion" }
28     { { $vocab-link "regexp" } " - regular expressions" }
29     { { $vocab-link "peg" } " - parser expression grammars" }
30 } ;
31
32 ABOUT: "strings"
33
34 HELP: string
35 { $description "The class of fixed-length character strings. See " { $link "syntax-strings" } " for syntax and " { $link "strings" } " for general information." } ;
36
37 HELP: string-nth ( n string -- ch )
38 { $values { "n" fixnum } { "string" string } { "ch" "the character at the " { $snippet "n" } "th index" } }
39 { $description "Unsafe string accessor, used to define " { $link nth } " on strings." }
40 { $warning "This word is in the " { $vocab-link "strings.private" } " vocabulary because it does not perform type or bounds checking. User code should call " { $link nth } " instead." } ;
41
42 HELP: set-string-nth ( ch n string -- )
43 { $values { "ch" "a character" } { "n" fixnum } { "string" string }  }
44 { $description "Unsafe string mutator, used to define " { $link set-nth } " on strings." }
45 { $warning "This word is in the " { $vocab-link "strings.private" } " vocabulary because it does not perform type or bounds checking. User code should call " { $link set-nth } " instead." } ;
46
47 HELP: <string> ( n ch -- string )
48 { $values { "n" "a positive integer specifying string length" } { "ch" "an initial character" } { "string" string } }
49 { $description "Creates a new string with the given length and all characters initially set to " { $snippet "ch" } "." } ;
50
51 HELP: 1string
52 { $values { "ch" "a character"} { "str" string } }
53 { $description "Outputs a string of one character." } ;
54
55 HELP: >string
56 { $values { "seq" "a sequence of characters" } { "str" string } }
57 { $description "Outputs a freshly-allocated string with the same elements as a given sequence." }
58 { $errors "Throws an error if the sequence contains elements other than real numbers." } ;
59
60 HELP: resize-string ( n str -- newstr )
61 { $values { "n" "a non-negative integer" } { "str" string } { "newstr" string } }
62 { $description "Creates a new string " { $snippet "n" } " characters long The contents of the existing string are copied into the new string; if the new string is shorter, only an initial segment is copied, and if the new string is longer the remaining space is filled with " { $snippet "\\u000000" } "." } ;