" " wrap-indented-string
] unit-test
+{
+ " This is
+a long
+piece of
+text that
+we wish to
+word wrap."
+} [
+ " This is a long piece of text that we wish to word wrap." 10
+ wrap-string
+] unit-test
+
+{
+ " This is
+ a long
+ piece of
+ text that
+ we wish to
+ word wrap."
+} [
+ " This is a long piece of text that we wish to word wrap." 12
+ " " wrap-indented-string
+] unit-test
+
{ t } [
"This is a long piece of text that we wish to word wrap." 12
[ " " wrap-indented-string ] [ 2 wrap-indented-string ] 2bi =
<PRIVATE
+: split-line ( string -- elements )
+ dup [ " \t" member? not ] find drop 0 or
+ [ f swap ] [ cut ] if-zero
+ " \t" split harvest [ dup length 1 <element> ] map!
+ swap [ 0 over length <element> prefix ] when* ;
+
: split-lines ( string -- elements-lines )
- string-lines [
- " \t" split harvest
- [ dup length 1 <element> ] map!
- ] map! ;
+ string-lines [ split-line ] map! ;
: join-elements ( wrapped-lines -- lines )
[ " " join ] map! ;