Merge branch 'master' of git://factorcode.org/git/factor
commit
cc4c5949b1
|
@ -24,38 +24,32 @@ TUPLE: multipart-stream stream n leftover separator ;
|
||||||
[ f ] change-leftover
|
[ f ] change-leftover
|
||||||
[ n>> ] [ stream>> ] bi stream-read [ ?append ] keep not ;
|
[ n>> ] [ stream>> ] bi stream-read [ ?append ] keep not ;
|
||||||
|
|
||||||
: multipart-split ( bytes separator -- before after ? empty? )
|
: multipart-split ( bytes separator -- before after seq=? )
|
||||||
#! first boolean: return true if found
|
2dup sequence= [ 2drop f f t ] [ split1 f ] if ;
|
||||||
#! second boolean: true if sequence=
|
|
||||||
2dup sequence= [
|
|
||||||
2drop f f f t
|
|
||||||
] [
|
|
||||||
split1 dup >boolean f
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
:: multipart-step ( stream bytes end-stream? separator quot: ( bytes -- ) -- ? end-stream? )
|
:: multipart-step ( stream bytes end-stream? separator quot: ( bytes -- ) -- ? end-stream? )
|
||||||
#! return t to loop again
|
#! return t to loop again
|
||||||
bytes separator multipart-split [
|
bytes separator multipart-split [ dup >boolean ] dip [
|
||||||
! separator == input
|
! separator == input
|
||||||
3drop f quot call f
|
3drop f quot call f
|
||||||
] [
|
] [
|
||||||
[
|
[
|
||||||
! found
|
! found
|
||||||
[ [ quot call ] unless-empty ]
|
[ quot unless-empty ]
|
||||||
[
|
[
|
||||||
stream (>>leftover)
|
stream (>>leftover)
|
||||||
[ quot call ] unless-empty
|
quot unless-empty
|
||||||
] if-empty f quot call f
|
] if-empty f quot call f
|
||||||
] [
|
] [
|
||||||
! not found
|
! not found
|
||||||
drop
|
drop
|
||||||
end-stream? [
|
end-stream? [
|
||||||
[ quot call ] unless-empty f
|
quot unless-empty f
|
||||||
] [
|
] [
|
||||||
separator length 1- ?cut* stream (>>leftover)
|
separator length 1- ?cut* stream (>>leftover)
|
||||||
[ quot call ] unless-empty t
|
quot unless-empty t
|
||||||
] if
|
] if
|
||||||
] if
|
] if
|
||||||
] if stream leftover>> end-stream? not or ;
|
] if stream leftover>> end-stream? not or ;
|
||||||
|
|
Loading…
Reference in New Issue