2007-09-20 18:09:08 -04:00
|
|
|
! Copyright (C) 2006, 2007 Daniel Ehrenberg.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: math kernel sequences sbufs vectors
|
2008-02-01 18:45:35 -05:00
|
|
|
namespaces unicode.syntax ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: io.encodings
|
|
|
|
|
|
|
|
TUPLE: encode-error ;
|
|
|
|
|
|
|
|
: encode-error ( -- * ) \ encode-error construct-empty throw ;
|
|
|
|
|
|
|
|
TUPLE: decode-error ;
|
|
|
|
|
2008-02-02 00:59:46 -05:00
|
|
|
: decode-error ( -- * ) \ decode-error construct-empty throw ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
SYMBOL: begin
|
|
|
|
|
|
|
|
: decoded ( buf ch -- buf ch state )
|
|
|
|
over push 0 begin ;
|
|
|
|
|
2008-02-01 18:45:35 -05:00
|
|
|
: push-replacement ( buf -- buf ch state )
|
|
|
|
UNICHAR: replacement-character decoded ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: finish-decoding ( buf ch state -- str )
|
2008-02-01 17:21:42 -05:00
|
|
|
begin eq? [ decode-error ] unless drop "" like ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-11 00:14:42 -05:00
|
|
|
: decode ( ch state seq quot -- buf ch state )
|
|
|
|
[ -rot ] swap compose each ; inline
|
|
|
|
|
|
|
|
: start-decoding ( seq -- buf ch state seq )
|
|
|
|
[ length <sbuf> 0 begin ] keep ;
|
|
|
|
|
|
|
|
GENERIC: init-decoding ( stream encoding -- decoded-stream )
|
|
|
|
|
|
|
|
: <decoding> ( stream decoding-class -- decoded-stream )
|
|
|
|
construct-empty init-decoding ;
|
|
|
|
|
|
|
|
GENERIC: init-encoding ( stream encoding -- encoded-stream )
|
|
|
|
|
|
|
|
: <encoding> ( stream encoding-class -- encoded-stream )
|
|
|
|
construct-empty init-encoding ;
|