io.encodings: For decoders, try to gobble up the next newline if cr>> is true in stream-read-until. Add unit test. Fixes #1177.

db4
Doug Coleman 2014-10-31 00:58:53 -07:00
parent e50d9e5a4c
commit 5e16e54b98
2 changed files with 28 additions and 3 deletions

View File

@ -1,6 +1,7 @@
USING: accessors io io.encodings io.encodings.ascii
io.encodings.utf8 io.files io.streams.byte-array
io.streams.string kernel namespaces tools.test ;
io.encodings.string io.encodings.utf8 io.files
io.streams.byte-array io.streams.string kernel namespaces
tools.test ;
IN: io.encodings.tests
[ { } ]
@ -73,3 +74,16 @@ unit-test
output-stream get code>>
] with-byte-writer drop
] unit-test
! Bug 1177.
{
"! lol"
"! wat"
13
} [
"! lol\r\n! wat\r\n" utf8 encode
utf8 [
readln
"\r\n" read-until
] with-byte-reader
] unit-test

View File

@ -161,7 +161,18 @@ M: decoder stream-contents*
{ CHAR: \n [ line-ends\n ] }
} case ; inline
M: decoder stream-read-until >decoder< decode-until ;
M: decoder stream-read-until
dup cr>> [
2dup
>decoder< decode-until
2dup [ empty? ] [ CHAR: \n = ] bi* and [
2drop stream-read-until
] [
[ cr- drop ] 2dip
] if
] [
>decoder< decode-until
] if ;
M: decoder stream-readln
"\r\n" over >decoder< decode-until handle-readln ;