Skip to content

Commit

Permalink
io.encodings: fix for read-until seps not containing \n.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Oct 31, 2014
1 parent 632ee27 commit 5961cfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 12 additions & 0 deletions core/io/encodings/encodings-tests.factor
Expand Up @@ -87,3 +87,15 @@ unit-test
"\r\n" read-until
] with-byte-reader
] unit-test

{
"! lol"
"! wa"
116
} [
"! lol\r\n! wat\r\n" utf8 encode
utf8 [
readln
"t" read-until
] with-byte-reader
] unit-test
15 changes: 10 additions & 5 deletions core/io/encodings/encodings.factor
Expand Up @@ -163,13 +163,18 @@ M: decoder stream-contents*

M: decoder stream-read-until
dup cr>> [
2dup
dup cr- 2dup
>decoder< decode-until
2dup [ empty? ] [ CHAR: \n = ] bi* and [
2drop stream-read-until
over [
dup CHAR: \n = [
2drop stream-read-until
] [
[ 2drop ] 2dip
] if
] [
[ cr- drop ] 2dip
] if
first-unsafe CHAR: \n = [ [ rest ] dip ] when
[ 2drop ] 2dip
] if-empty
] [
>decoder< decode-until
] if ;
Expand Down

0 comments on commit 5961cfb

Please sign in to comment.