]> gitweb.factorcode.org Git - factor.git/commitdiff
io.encodings.latin1: re-implement M\ latin1 encode-string.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 28 Feb 2018 18:35:23 +0000 (10:35 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 28 Feb 2018 18:35:23 +0000 (10:35 -0800)
basis/io/encodings/latin1/latin1.factor

index 3932c0643a8ca4c48e9141743dc273c29e31158b..e0761cf383ff0ecf8df03342665f8619af48c830 100644 (file)
@@ -1,11 +1,17 @@
-USING: io io.encodings io.encodings.iana kernel math ;
+USING: io io.encodings io.encodings.iana kernel math sequences ;
 
 IN: io.encodings.latin1
 
 SINGLETON: latin1
 
+: latin1-encode ( char -- byte )
+    dup 256 < [ encode-error ] unless ; inline
+
 M: latin1 encode-char
-    drop over 256 < [ stream-write1 ] [ encode-error ] if ;
+    drop [ latin1-encode ] dip stream-write1 ;
+
+M: latin1 encode-string
+    drop [ [ latin1-encode ] B{ } map-as ] dip stream-write ;
 
 M: latin1 decode-char
     drop stream-read1 [