io.encodings.ascii: make sure encode-string gets a string.

db4
John Benediktsson 2015-07-14 22:18:12 -07:00
parent 5b58e1d3e8
commit 86639b9df0
2 changed files with 13 additions and 10 deletions

View File

@ -141,5 +141,3 @@ set-specializer
M\ hashtable set-at
{ { object fixnum object } { object word object } }
set-specializer
\ encode-string { string object object } set-specializer

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors byte-arrays io io.encodings
io.encodings.private kernel math sequences ;
io.encodings.private kernel math sequences strings ;
IN: io.encodings.ascii
SINGLETON: ascii
@ -10,15 +10,20 @@ M: ascii encode-char
drop
over 127 <= [ stream-write1 ] [ encode-error ] if ; inline
<PRIVATE
GENERIC: ascii> ( string -- byte-array )
M: string ascii>
dup aux>>
[ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
[ string>byte-array-fast ] if ; inline
PRIVATE>
M: ascii encode-string
drop
[
dup aux>>
[ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
[ string>byte-array-fast ]
if
] dip
stream-write ;
[ ascii> ] dip stream-write ;
M: ascii decode-char
drop