]> gitweb.factorcode.org Git - factor.git/commitdiff
io.encodings: For decoders, try to gobble up the next newline if cr>> is true in...
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 31 Oct 2014 07:58:53 +0000 (00:58 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 31 Oct 2014 07:58:53 +0000 (00:58 -0700)
core/io/encodings/encodings-tests.factor
core/io/encodings/encodings.factor

index cc32f30060ba9396940b08220b8c800ea93123bb..f6c94684bd3d95b44ed815140a6b80fdc1983038 100644 (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
index 2ee100dd521f8685027fbd8cd29ffe9339387bed..63538dba9edf12cc1c661570890746bb913fa0e4 100644 (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 ;