]> gitweb.factorcode.org Git - factor.git/commitdiff
io.encodings: allow encode-string to be called with non-strings.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 7 Apr 2016 19:17:00 +0000 (12:17 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 7 Apr 2016 19:17:00 +0000 (12:17 -0700)
core/io/encodings/utf16/utf16.factor
core/io/encodings/utf8/utf8.factor

index 0660ddfd774784118e80c769c5e357eb9e6c1fb7..24491a7a26ce64e118710104241a608a2ab3b5a5 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors byte-arrays combinators io io.binary
 io.encodings kernel math math.private namespaces sbufs
-sequences sequences.private splitting strings.private vectors ;
+sequences sequences.private splitting strings strings.private
+vectors ;
 IN: io.encodings.utf16
 
 SINGLETON: utf16be
@@ -115,13 +116,13 @@ M: utf16le encode-char ( char stream encoding -- )
 
 M: utf16le encode-string
     drop
-    over aux>>
+    over dup string? [ aux>> ] [ drop t ] if
     [ [ char>utf16le ] curry each ]
     [ ascii-string>utf16le ] if ;
 
 M: utf16be encode-string
     drop
-    over aux>>
+    over dup string? [ aux>> ] [ drop t ] if
     [ [ char>utf16be ] curry each ]
     [ ascii-string>utf16be ] if ;
 
index 28ce4899f0534e2f101d3bf3ec2f16294d76817c..d07893c0efd99f05018ec72d932e8e2c6941ec6b 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors combinators io io.encodings
-io.encodings.private kernel math math.order sequences ;
+io.encodings.private kernel math math.order sequences strings ;
 IN: io.encodings.utf8
 
 ! Decoding UTF-8
@@ -86,7 +86,7 @@ M: utf8 encode-char
 
 M: utf8 encode-string
     drop
-    over aux>>
+    over dup string? [ aux>> ] [ drop t ] if
     [ [ char>utf8 ] curry each ]
     [ [ string>byte-array-fast ] dip stream-write ] if ;