2008-02-21 16:22:49 -05:00
|
|
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: io io.encodings strings kernel math sequences byte-arrays io.encodings ;
|
2008-02-16 17:25:45 -05:00
|
|
|
IN: io.encodings.ascii
|
|
|
|
|
2008-03-06 16:07:00 -05:00
|
|
|
: encode-check< ( string stream max -- )
|
2008-03-06 15:46:11 -05:00
|
|
|
[ pick <= [ encode-error ] [ stream-write1 ] if ] 2curry each ;
|
2008-02-16 17:25:45 -05:00
|
|
|
|
2008-03-06 16:07:00 -05:00
|
|
|
: push-if< ( sbuf character max -- )
|
|
|
|
over <= [ drop HEX: fffd ] when swap push ;
|
|
|
|
|
2008-02-16 17:25:45 -05:00
|
|
|
TUPLE: ascii ;
|
|
|
|
|
2008-03-06 01:23:38 -05:00
|
|
|
M: ascii stream-write-encoded ( string stream encoding -- )
|
2008-03-06 16:07:00 -05:00
|
|
|
drop 128 encode-check< ;
|
2008-02-16 17:25:45 -05:00
|
|
|
|
|
|
|
M: ascii decode-step
|
2008-03-06 16:07:00 -05:00
|
|
|
drop 128 push-if< ;
|