1 ! Copyright (C) 2011-2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: kernel make math sequences ui.text unicode wrap ;
10 : word-index ( string -- n/f )
11 dup [ blank? ] find drop [
12 1 + swap [ blank? not ] find-from drop
17 : word-split1 ( string -- before after/f )
18 dup word-index [ cut ] [ f ] if* ;
22 : word-split, ( string -- )
23 [ word-split1 [ , ] [ dup empty? not ] bi* ] loop drop ;
27 : word-split ( string -- seq )
28 [ word-split, ] { } make ;
32 : string>elements ( string font -- elements )
34 dup dup [ blank? ] find drop [ cut ] [ "" ] if*
35 [ _ swap text-width ] bi@
41 : visual-wrap ( line font line-width -- lines )
42 [ string>elements ] dip wrap [ concat ] map ;