]> gitweb.factorcode.org Git - factor.git/blob - core/splitting/splitting-docs.factor
sequences: Add join-as, which takes an exemplar. Move split-subseq and replace from...
[factor.git] / core / splitting / splitting-docs.factor
1 USING: help.markup help.syntax sequences strings ;
2 IN: splitting
3
4 ARTICLE: "sequences-split" "Splitting sequences"
5 "Splitting sequences at occurrences of subsequences:"
6 { $subsections
7     ?head
8     ?head-slice
9     ?tail
10     ?tail-slice
11     split1
12     split1-slice
13     split1-when
14     split1-last
15     split1-last-slice
16     split
17     split-when
18     split*
19     split*-when
20 }
21 "Splitting a string into lines:"
22 { $subsections string-lines }
23 "Replacing subsequences with another subsequence:"
24 { $subsections replace } ;
25
26 ABOUT: "sequences-split"
27
28 HELP: split1
29 { $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before" "a new sequence" } { "after" "a new sequence" } }
30 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
31
32 HELP: split1-slice
33 { $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before-slice" slice } { "after-slice" slice } }
34 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
35
36 HELP: split1-when
37 { $values { "seq" "a sequence" } { "quot" { $quotation "( ... elt -- ... ? )" } } { "before" "a new sequence" } { "after" "a new sequence" } }
38 { $description "Splits " { $snippet "seq" } " at the first occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs the pieces before and after the split." } ;
39
40 HELP: split1-last
41 { $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before" "a new sequence" } { "after" "a new sequence" } }
42 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
43
44 HELP: split1-last-slice
45 { $values { "seq" "a sequence" } { "subseq" "a sequence" } { "before-slice" slice } { "after-slice" slice } }
46 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
47
48 { split1 split1-slice split1-last split1-last-slice } related-words
49
50 HELP: split-when
51 { $values { "seq" "a sequence" } { "quot" { $quotation "( ... elt -- ... ? )" } } { "pieces" "a new array" } }
52 { $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
53 { $examples { $example "USING: ascii kernel prettyprint splitting ;" "\"hello,world-how.are:you\" [ letter? not ] split-when ." "{ \"hello\" \"world\" \"how\" \"are\" \"you\" }" } } ;
54
55 HELP: split
56 { $values { "seq" "a sequence" } { "separators" "a sequence" } { "pieces" "a new array" } }
57 { $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
58 { $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
59
60 HELP: split*-when
61 { $values { "seq" "a sequence" } { "quot" { $quotation "( ... elt -- ... ? )" } } { "pieces" "a new array" } }
62 { $description "A variant of " { $link split-when } " that includes the elements along which the sequence was split." }
63 { $examples { $example "USING: ascii kernel prettyprint splitting ;" "\"hello,world-how.are:you\" [ letter? not ] split*-when ." "{ \"hello,\" \"world-\" \"how.\" \"are:\" \"you\" }" } } ;
64
65 HELP: split*
66 { $values { "seq" "a sequence" } { "separators" "a sequence" } { "pieces" "a new array" } }
67 { $description "A variant of " { $link split } " that includes the elements along which the sequence was split." }
68 { $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split* ." "{ \"hello \" \"world-\" \"how \" \"are \" \"you?\" }" } } ;
69
70 HELP: ?head
71 { $values { "seq" "a sequence" } { "begin" "a sequence" } { "newseq" "a new sequence" } { "?" "a boolean" } }
72 { $description "Tests if " { $snippet "seq" } " starts with " { $snippet "begin" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "begin" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
73
74 HELP: ?head-slice
75 { $values { "seq" "a sequence" } { "begin" "a sequence" } { "newseq" slice } { "?" "a boolean" } }
76 { $description "Like " { $link ?head } ", except the resulting sequence is a " { $link slice } "." } ;
77
78 HELP: ?tail
79 { $values { "seq" "a sequence" } { "end" "a sequence" } { "newseq" "a new sequence" } { "?" "a boolean" } }
80 { $description "Tests if " { $snippet "seq" } " ends with " { $snippet "end" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "end" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
81
82 HELP: ?tail-slice
83 { $values { "seq" "a sequence" } { "end" "a sequence" } { "newseq" slice } { "?" "a boolean" } }
84 { $description "Like " { $link ?tail } ", except the resulting sequence is a " { $link slice } "." } ;
85
86 HELP: string-lines
87 { $values { "str" string } { "seq" "a sequence of strings" } }
88 { $description "Splits a string along line breaks." }
89 { $examples
90     { $example "USING: prettyprint splitting ;" "\"Hello\\r\\nworld\\n\" string-lines ." "{ \"Hello\" \"world\" \"\" }" }
91 } ;
92
93 HELP: replace
94 { $values { "seq" sequence } { "old" sequence } { "new" sequence } { "new-seq" sequence } }
95 { $description "Replaces every occurrence of " { $snippet "old" } " with " { $snippet "new" } " in the " { $snippet "seq" } "." }
96 { $examples
97     { $example "USING: io splitting ;"
98                "\"cool example is cool\" \"cool\" \"silly\" replace print"
99                "silly example is silly"
100     }
101 } ;