]> gitweb.factorcode.org Git - factor.git/blob - core/strings/strings-docs.factor
22e8bfcb62a5361af6dc81b36255e389afeaa186
[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 help.vocabs ;
4 IN: strings
5
6 ARTICLE: "strings" "Strings"
7 "The " { $vocab-link "strings" } " vocabulary implements fixed-size mutable sequences of of Unicode 5.1 code points."
8 $nl
9 "Code points, or characters as they're informally known, are not a first-class type; they are simply represented as integers in the range 0 and 16,777,216 (2^24), inclusive. Only characters up to 2,097,152 (2^21) have a defined meaning in Unicode."
10 $nl
11 "String literal syntax is covered in " { $link "syntax-strings" } "."
12 $nl
13 "Since strings implement the " { $link "sequence-protocol" } ", basic string manipulation can be performed with " { $link "sequences" } " in the " { $vocab-link "sequences" } " vocabulary. More text processing functionality can be found in vocabularies carrying the " { $link T{ vocab-tag { name "text" } } } " tag."
14 $nl
15 "Strings form a class:"
16 { $subsection string }
17 { $subsection string? }
18 "Creating new strings:"
19 { $subsection >string }
20 { $subsection <string> }
21 "Creating a string from a single character:"
22 { $subsection 1string } ;
23
24 ABOUT: "strings"
25
26 HELP: string
27 { $description "The class of fixed-length character strings. See " { $link "syntax-strings" } " for syntax and " { $link "strings" } " for general information." } ;
28
29 HELP: string-nth
30 { $values { "n" fixnum } { "string" string } { "ch" "the character at the " { $snippet "n" } "th index" } }
31 { $description "Unsafe string accessor, used to define " { $link nth } " on strings." }
32 { $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." } ;
33
34 HELP: set-string-nth
35 { $values { "ch" "a character" } { "n" fixnum } { "string" string }  }
36 { $description "Unsafe string mutator, used to define " { $link set-nth } " on strings." }
37 { $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." } ;
38
39 HELP: <string>
40 { $values { "n" "a positive integer specifying string length" } { "ch" "an initial character" } { "string" string } }
41 { $description "Creates a new string with the given length and all characters initially set to " { $snippet "ch" } "." } ;
42
43 HELP: 1string
44 { $values { "ch" "a character"} { "str" string } }
45 { $description "Outputs a string of one character." } ;
46
47 HELP: >string
48 { $values { "seq" "a sequence of characters" } { "str" string } }
49 { $description "Outputs a freshly-allocated string with the same elements as a given sequence, by interpreting the sequence elements as Unicode code points." }
50 { $notes "This operation is only appropriate if the underlying sequence holds Unicode code points, which is rare unless it is a " { $link slice } " of another string. To convert a sequence of bytes to a string, use the words documented in " { $link "io.encodings.string" } "." }
51 { $errors "Throws an error if the sequence contains elements other than integers." } ;
52
53 HELP: resize-string ( n str -- newstr )
54 { $values { "n" "a non-negative integer" } { "str" string } { "newstr" string } }
55 { $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" } "." } ;