]> gitweb.factorcode.org Git - factor.git/blob - basis/wrap/strings/strings.factor
Splitting up basis/wrap into three vocabs
[factor.git] / basis / wrap / strings / strings.factor
1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: wrap kernel sequences fry splitting math ;
4 IN: wrap.strings
5
6 <PRIVATE
7
8 : split-lines ( string -- elements-lines )
9     string-lines [
10         " \t" split harvest
11         [ dup length 1 <element> ] map
12     ] map ;
13
14 : join-elements ( wrapped-lines -- lines )
15     [ " " join ] map ;
16
17 : join-lines ( strings -- string )
18     "\n" join ;
19
20 PRIVATE>
21
22 : wrap-lines ( lines width -- newlines )
23     [ split-lines ] dip '[ _ dup wrap join-elements ] map concat ;
24
25 : wrap-string ( string width -- newstring )
26     wrap-lines join-lines ;
27
28 : wrap-indented-string ( string width indent -- newstring )
29     [ length - wrap-lines ] keep '[ _ prepend ] map join-lines ;