[ "i'm good thx bai" ] [ "I'm Good THX bai" >lower ] unit-test
[ "Hello How Are You?" ] [ "hEllo how ARE yOU?" >title ] unit-test
-[ { " " "Hello" " " "World" } ] [ " Hello World" >words [ >string ] map ] unit-test
+[ { " " "Hello" " " " " " " "World" } ] [ " Hello World" >words [ >string ] map ] unit-test
! Copyright (C) 2005, 2009 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
USING: combinators.short-circuit hints kernel math math.order\r
-sequences splitting strings ;\r
+sequences strings ;\r
IN: ascii\r
\r
: ascii? ( ch -- ? ) 0 127 between? ; inline\r
: >lower ( str -- lower ) [ ch>lower ] map ;\r
: ch>upper ( ch -- upper ) dup letter? [ 0x20 - ] when ; inline\r
: >upper ( str -- upper ) [ ch>upper ] map ;\r
-: >words ( str -- words ) [ blank? ] split*-when-slice ;\r
+: >words ( str -- words )\r
+ [ dup empty? not ] [\r
+ dup [ blank? ] find drop\r
+ [ [ 1 ] when-zero cut-slice swap ]\r
+ [ f 0 rot [ length ] keep <slice> ] if*\r
+ ] produce nip ;\r
: capitalize ( str -- str' ) unclip [ >lower ] [ ch>upper ] bi* prefix ;\r
: >title ( str -- title ) >words [ capitalize ] map concat ;\r
\r