splitting: simplify a bit.

db4
John Benediktsson 2013-10-12 16:41:12 -07:00
parent f6bd67ab46
commit 04d83f9f48
1 changed files with 5 additions and 7 deletions

View File

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