mime.multipart: Simplify the code a bit.

Fixes #2107
freebsd-work
Doug Coleman 2019-01-21 15:08:07 -06:00
parent d73fb5f80f
commit 0ae9b17734
2 changed files with 16 additions and 10 deletions

View File

@ -77,3 +77,10 @@ SYMBOL: mime-test-server
[
] with-test-server
] unit-test
[
"--\r\n\r\n" <string-reader> [
"\r\n\r\n" <multipart>
"\r\n\r\n" parse-multipart
] with-input-stream
] [ mime-decoding-ran-out-of-bytes? ] must-fail-with

View File

@ -40,20 +40,19 @@ C: <mime-variable> mime-variable
[ '[ _ B{ } append-as ] change-bytes ]
[ t >>end-of-stream? ] if* ;
: split-bytes ( bytes separator -- leftover-bytes safe-to-dump )
dupd [ length ] bi@ 1 - - short cut-slice swap ;
ERROR: mime-decoding-ran-out-of-bytes ;
: dump-until-separator ( multipart -- multipart )
dup
[ current-separator>> ] [ bytes>> ] bi
[ nip ] [ subseq-start ] 2bi [
[ ] [ current-separator>> ] [ bytes>> ] tri
dup [ mime-decoding-ran-out-of-bytes ] unless
2dup subseq-start [
cut-slice
[ mime-write ]
[ over current-separator>> length short tail-slice >>bytes ] bi*
[ swap length tail-slice >>bytes ] bi*
] [
drop
dup [ bytes>> ] [ current-separator>> ] bi split-bytes mime-write
>>bytes fill-bytes dup end-of-stream?>> [ dump-until-separator ] unless
tuck [ length ] bi@ - 1 - cut-slice
[ mime-write ]
[ >>bytes ] bi* fill-bytes
dup end-of-stream?>> [ dump-until-separator ] unless
] if* ;
: dump-string ( multipart separator -- multipart string )