factor/basis/io/encodings/ascii/ascii.factor

30 lines
679 B
Factor
Raw Normal View History

2008-02-21 16:22:49 -05:00
! 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 ;
2008-02-16 17:25:45 -05:00
IN: io.encodings.ascii
SINGLETON: ascii
2008-02-16 17:25:45 -05:00
2008-03-14 04:09:51 -04:00
M: ascii encode-char
drop
over 127 <= [ stream-write1 ] [ encode-error ] if ; inline
M: ascii encode-string
drop
[
dup aux>>
[ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
[ >byte-array ]
if
] dip
stream-write ;
2008-02-16 17:25:45 -05:00
2008-03-14 04:09:51 -04:00
M: ascii decode-char
drop
stream-read1 dup [
dup 127 <= [ >fixnum ] [ drop replacement-char ] if
] when ; inline
M: ascii decode-until (decode-until) ;