io.encodings: For decoders, try to gobble up the next newline if cr>> is true in stream-read-until. Add unit test. Fixes #1177.
parent
e50d9e5a4c
commit
5e16e54b98
|
@ -1,6 +1,7 @@
|
||||||
USING: accessors io io.encodings io.encodings.ascii
|
USING: accessors io io.encodings io.encodings.ascii
|
||||||
io.encodings.utf8 io.files io.streams.byte-array
|
io.encodings.string io.encodings.utf8 io.files
|
||||||
io.streams.string kernel namespaces tools.test ;
|
io.streams.byte-array io.streams.string kernel namespaces
|
||||||
|
tools.test ;
|
||||||
IN: io.encodings.tests
|
IN: io.encodings.tests
|
||||||
|
|
||||||
[ { } ]
|
[ { } ]
|
||||||
|
@ -73,3 +74,16 @@ unit-test
|
||||||
output-stream get code>>
|
output-stream get code>>
|
||||||
] with-byte-writer drop
|
] with-byte-writer drop
|
||||||
] unit-test
|
] 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
|
||||||
|
|
|
@ -161,7 +161,18 @@ M: decoder stream-contents*
|
||||||
{ CHAR: \n [ line-ends\n ] }
|
{ CHAR: \n [ line-ends\n ] }
|
||||||
} case ; inline
|
} 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
|
M: decoder stream-readln
|
||||||
"\r\n" over >decoder< decode-until handle-readln ;
|
"\r\n" over >decoder< decode-until handle-readln ;
|
||||||
|
|
Loading…
Reference in New Issue