diff --git a/basis/ascii/ascii-tests.factor b/basis/ascii/ascii-tests.factor index a833c03f48..0c4ac1ef84 100644 --- a/basis/ascii/ascii-tests.factor +++ b/basis/ascii/ascii-tests.factor @@ -19,4 +19,4 @@ IN: ascii.tests [ "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 diff --git a/basis/ascii/ascii.factor b/basis/ascii/ascii.factor index dd34976600..cf3f62c7c1 100644 --- a/basis/ascii/ascii.factor +++ b/basis/ascii/ascii.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: combinators.short-circuit hints kernel math math.order -sequences splitting strings ; +sequences strings ; IN: ascii : ascii? ( ch -- ? ) 0 127 between? ; inline @@ -18,7 +18,12 @@ IN: ascii : >lower ( str -- lower ) [ ch>lower ] map ; : ch>upper ( ch -- upper ) dup letter? [ 0x20 - ] when ; inline : >upper ( str -- upper ) [ ch>upper ] map ; -: >words ( str -- words ) [ blank? ] split*-when-slice ; +: >words ( str -- words ) + [ dup empty? not ] [ + dup [ blank? ] find drop + [ [ 1 ] when-zero cut-slice swap ] + [ f 0 rot [ length ] keep ] if* + ] produce nip ; : capitalize ( str -- str' ) unclip [ >lower ] [ ch>upper ] bi* prefix ; : >title ( str -- title ) >words [ capitalize ] map concat ;