]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting: simplify a bit.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Oct 2013 23:41:12 +0000 (16:41 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Oct 2013 23:41:12 +0000 (16:41 -0700)
core/splitting/splitting.factor

index 34ad2dbc5fc74339c36e6ef3e41690aa9b072151..73afa24c2477057350415da37337411d7d24daf6 100644 (file)
@@ -45,11 +45,11 @@ PRIVATE>
     [ snip-slice ] (split1) ;
 
 : split-subseq ( seq subseq -- seqs )
-    dup empty? [
-        drop 1array
+    [
+        1array
     ] [
         [ dup ] swap [ split1-slice swap ] curry produce nip
-    ] if ;
+    ] if-empty ;
 
 : replace ( seq old new -- new-seq )
     pick [ [ split-subseq ] dip ] dip join-as ;
@@ -107,12 +107,10 @@ M: string string-lines
         "\n" split
         [
             but-last-slice [
-                dup ?last CHAR: \r = [ but-last ] when
-                [ CHAR: \r = ] split-when
+                "\r" ?tail drop "\r" split
             ] map! drop
         ] [
-            [ length 1 - ] keep
-            [ [ CHAR: \r = ] split-when ] change-nth
+            [ length 1 - ] keep [ "\r" split ] change-nth
         ]
         [ concat ]
         tri