factor/extra/io/encodings/ascii/ascii.factor

19 lines
547 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: io io.encodings strings kernel math sequences byte-arrays io.encodings ;
2008-02-16 17:25:45 -05:00
IN: io.encodings.ascii
: 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
: push-if< ( sbuf character max -- )
over <= [ drop HEX: fffd ] when swap push ;
2008-02-16 17:25:45 -05:00
TUPLE: ascii ;
M: ascii stream-write-encoded ( string stream encoding -- )
drop 128 encode-check< ;
2008-02-16 17:25:45 -05:00
M: ascii decode-step
drop 128 push-if< ;