]> gitweb.factorcode.org Git - factor.git/commitdiff
ascii: change >words not to use split*.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 1 Apr 2013 16:13:33 +0000 (09:13 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 1 Apr 2013 16:13:33 +0000 (09:13 -0700)
basis/ascii/ascii-tests.factor
basis/ascii/ascii.factor

index a833c03f48e662f9009da99a1dcf137b8c5239bd..0c4ac1ef8465b4dfca0b68d8f9e4fab24032ac6b 100644 (file)
@@ -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
index dd34976600e436514f3425d07e8b20cffdaea71b..cf3f62c7c11b916470e524b590681b456ea75b11 100644 (file)
@@ -1,7 +1,7 @@
 ! 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
@@ -18,7 +18,12 @@ IN: ascii
 : >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