splitting: removing split* to extras.
parent
215c74674f
commit
2ca5b739e0
|
@ -17,8 +17,6 @@ ARTICLE: "sequences-split" "Splitting sequences"
|
||||||
split
|
split
|
||||||
split-when
|
split-when
|
||||||
split-when-slice
|
split-when-slice
|
||||||
split*
|
|
||||||
split*-when
|
|
||||||
}
|
}
|
||||||
"Splitting a string into lines:"
|
"Splitting a string into lines:"
|
||||||
{ $subsections string-lines }
|
{ $subsections string-lines }
|
||||||
|
@ -67,16 +65,6 @@ HELP: split
|
||||||
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
|
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
|
||||||
{ $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
|
{ $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
|
||||||
|
|
||||||
HELP: split*-when
|
|
||||||
{ $values { "seq" "a sequence" } { "quot" { $quotation "( ... elt -- ... ? )" } } { "pieces" "a new array" } }
|
|
||||||
{ $description "A variant of " { $link split-when } " that includes the elements along which the sequence was split." }
|
|
||||||
{ $examples { $example "USING: ascii kernel prettyprint splitting ;" "\"hello,world-how.are:you\" [ letter? not ] split*-when ." "{ \"hello\" \",\" \"world\" \"-\" \"how\" \".\" \"are\" \":\" \"you\" }" } } ;
|
|
||||||
|
|
||||||
HELP: split*
|
|
||||||
{ $values { "seq" "a sequence" } { "separators" "a sequence" } { "pieces" "a new array" } }
|
|
||||||
{ $description "A variant of " { $link split } " that includes the elements along which the sequence was split." }
|
|
||||||
{ $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split* ." "{ \"hello\" \" \" \"world\" \"-\" \"how\" \" \" \"are\" \" \" \"you?\" }" } } ;
|
|
||||||
|
|
||||||
HELP: ?head
|
HELP: ?head
|
||||||
{ $values { "seq" "a sequence" } { "begin" "a sequence" } { "newseq" "a new sequence" } { "?" "a boolean" } }
|
{ $values { "seq" "a sequence" } { "begin" "a sequence" } { "newseq" "a new sequence" } { "?" "a boolean" } }
|
||||||
{ $description "Tests if " { $snippet "seq" } " starts with " { $snippet "begin" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "begin" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
|
{ $description "Tests if " { $snippet "seq" } " starts with " { $snippet "begin" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "begin" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
|
||||||
|
|
|
@ -91,24 +91,6 @@ unit-test
|
||||||
[ "" "ABC" ] [ " ABC" [ blank? ] split1-when-slice [ >string ] bi@ ] unit-test
|
[ "" "ABC" ] [ " ABC" [ blank? ] split1-when-slice [ >string ] bi@ ] unit-test
|
||||||
[ "a" " bc" ] [ "a bc" [ blank? ] split1-when-slice [ >string ] bi@ ] unit-test
|
[ "a" " bc" ] [ "a bc" [ blank? ] split1-when-slice [ >string ] bi@ ] unit-test
|
||||||
|
|
||||||
{ { } } [ { } { 0 } split* ] unit-test
|
|
||||||
{ { { 1 2 3 } } } [ { 1 2 3 } { 0 } split* ] unit-test
|
|
||||||
{ { { 0 } } } [ { 0 } { 0 } split* ] unit-test
|
|
||||||
{ { { 0 0 } } } [ { 0 0 } { 0 } split* ] unit-test
|
|
||||||
{ { { 1 2 } { 0 } { 3 } { 0 0 } } } [ { 1 2 0 3 0 0 } { 0 } split* ] unit-test
|
|
||||||
{ { "hello" } } [ "hello" " " split* ] unit-test
|
|
||||||
{ { " " "hello" } } [ " hello" " " split* ] unit-test
|
|
||||||
{ { "hello" " " "world" } } [ "hello world" " " split* ] unit-test
|
|
||||||
{ { "hello" " " "world" " " } } [ "hello world " " " split* ] unit-test
|
|
||||||
|
|
||||||
{ { } } [ { } [ 0 > ] split*-when ] unit-test
|
|
||||||
{ { { 0 } } } [ { 0 } [ 0 > ] split*-when ] unit-test
|
|
||||||
{ { { 0 0 } } } [ { 0 0 } [ 0 > ] split*-when ] unit-test
|
|
||||||
{ { { 1 2 } { 0 } { 3 } { 0 0 } } } [ { 1 2 0 3 0 0 } [ 0 > ] split*-when ] unit-test
|
|
||||||
{ { { 1 } { 2 3 } { 1 } { 4 5 } { 1 } { 6 } } } [
|
|
||||||
1 { 1 2 3 1 4 5 1 6 } [ dupd = ] split*-when nip
|
|
||||||
] unit-test
|
|
||||||
|
|
||||||
{ "abarbbarc" }
|
{ "abarbbarc" }
|
||||||
[ "afoobfooc" "foo" "bar" replace ] unit-test
|
[ "afoobfooc" "foo" "bar" replace ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -100,35 +100,6 @@ PRIVATE>
|
||||||
: split-slice ( seq separators -- pieces )
|
: split-slice ( seq separators -- pieces )
|
||||||
[ member? ] curry split-when-slice ; inline
|
[ member? ] curry split-when-slice ; inline
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
: (split*) ( n seq quot: ( ... elt -- ... ? ) slice-quot -- pieces )
|
|
||||||
pick [
|
|
||||||
swap curry [ keep swap ] curry [
|
|
||||||
[ [ find-from drop dup ] 2curry [ keep -rot ] curry ] 2keep
|
|
||||||
[ not ] compose [ find-from drop dup ] 2curry
|
|
||||||
[ dip -rot ] curry [ swap ] prepose
|
|
||||||
[ [ dup ] if ] curry [ 2dup = ] prepose
|
|
||||||
[ [ f ] if ] curry compose
|
|
||||||
] dip produce nip
|
|
||||||
] 2keep swap [
|
|
||||||
[ length [ swapd dupd < ] keep ] keep
|
|
||||||
] dip 2curry [ suffix ] compose [ drop ] if ; inline
|
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
: split*-when ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces )
|
|
||||||
[ 0 ] 2dip [ subseq ] (split*) ; inline
|
|
||||||
|
|
||||||
: split*-when-slice ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces )
|
|
||||||
[ 0 ] 2dip [ <slice> ] (split*) ; inline
|
|
||||||
|
|
||||||
: split* ( seq separators -- pieces )
|
|
||||||
[ member? ] curry split*-when ; inline
|
|
||||||
|
|
||||||
: split*-slice ( seq separators -- pieces )
|
|
||||||
[ member? ] curry split*-when-slice ; inline
|
|
||||||
|
|
||||||
GENERIC: string-lines ( str -- seq )
|
GENERIC: string-lines ( str -- seq )
|
||||||
|
|
||||||
M: string string-lines
|
M: string string-lines
|
||||||
|
|
Loading…
Reference in New Issue