io.encodings.ascii: make sure encode-string gets a string.
parent
5b58e1d3e8
commit
86639b9df0
|
@ -141,5 +141,3 @@ set-specializer
|
||||||
M\ hashtable set-at
|
M\ hashtable set-at
|
||||||
{ { object fixnum object } { object word object } }
|
{ { object fixnum object } { object word object } }
|
||||||
set-specializer
|
set-specializer
|
||||||
|
|
||||||
\ encode-string { string object object } set-specializer
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg.
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors byte-arrays io io.encodings
|
USING: accessors byte-arrays io io.encodings
|
||||||
io.encodings.private kernel math sequences ;
|
io.encodings.private kernel math sequences strings ;
|
||||||
IN: io.encodings.ascii
|
IN: io.encodings.ascii
|
||||||
|
|
||||||
SINGLETON: ascii
|
SINGLETON: ascii
|
||||||
|
@ -10,15 +10,20 @@ M: ascii encode-char
|
||||||
drop
|
drop
|
||||||
over 127 <= [ stream-write1 ] [ encode-error ] if ; inline
|
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
|
M: ascii encode-string
|
||||||
drop
|
drop
|
||||||
[
|
[ ascii> ] dip stream-write ;
|
||||||
dup aux>>
|
|
||||||
[ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
|
|
||||||
[ string>byte-array-fast ]
|
|
||||||
if
|
|
||||||
] dip
|
|
||||||
stream-write ;
|
|
||||||
|
|
||||||
M: ascii decode-char
|
M: ascii decode-char
|
||||||
drop
|
drop
|
||||||
|
|
Loading…
Reference in New Issue