factor/core/io/encodings/encodings.factor

29 lines
731 B
Factor
Raw Normal View History

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
: decode ( seq quot -- str )
>r [ length <sbuf> 0 begin ] keep r> each
2007-09-20 18:09:08 -04:00
finish-decoding ; inline