2008-02-21 16:22:49 -05:00
|
|
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-04-19 02:13:21 -04:00
|
|
|
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
|
|
|
|
|
2008-05-10 21:17:24 -04:00
|
|
|
SINGLETON: ascii
|
2008-02-16 17:25:45 -05:00
|
|
|
|
2008-03-14 04:09:51 -04:00
|
|
|
M: ascii encode-char
|
2010-04-19 02:13:21 -04:00
|
|
|
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
|
2010-04-19 02:13:21 -04:00
|
|
|
drop
|
|
|
|
stream-read1 dup [
|
|
|
|
dup 127 <= [ >fixnum ] [ drop replacement-char ] if
|
|
|
|
] when ; inline
|
2013-03-18 16:35:22 -04:00
|
|
|
|
|
|
|
M: ascii decode-until (decode-until) ;
|