1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: fry kernel math sequences splitting strings wrap ;
8 : split-lines ( string -- elements-lines )
11 [ dup length 1 <element> ] map!
14 : join-elements ( wrapped-lines -- lines )
17 : join-lines ( strings -- string )
22 : wrap-lines ( string width -- newlines )
23 [ split-lines ] dip '[ _ wrap join-elements ] map! concat ;
25 : wrap-string ( string width -- newstring )
26 wrap-lines join-lines ;
30 : make-indent ( indent -- indent' )
31 dup string? [ CHAR: \s <string> ] unless ; inline
35 : wrap-indented-string ( string width indent -- newstring )
36 make-indent [ length - wrap-lines ] keep
37 over empty? [ nip ] [ '[ _ prepend ] map! join-lines ] if ;