io.encodings: re-encrypt into stack-ese for core
parent
008ef0afd7
commit
73b6648b0e
|
@ -3,8 +3,6 @@
|
||||||
USING: accessors combinators destructors io io.streams.plain
|
USING: accessors combinators destructors io io.streams.plain
|
||||||
kernel math namespaces sbufs sequences sequences.private
|
kernel math namespaces sbufs sequences sequences.private
|
||||||
splitting strings ;
|
splitting strings ;
|
||||||
USING: locals ; ! XXX
|
|
||||||
|
|
||||||
IN: io.encodings
|
IN: io.encodings
|
||||||
|
|
||||||
! The encoding descriptor protocol
|
! The encoding descriptor protocol
|
||||||
|
@ -69,32 +67,41 @@ M: decoder stream-seek stream>> stream-seek ; inline
|
||||||
: (read1) ( decoder -- ch )
|
: (read1) ( decoder -- ch )
|
||||||
>decoder< decode-char ; inline
|
>decoder< decode-char ; inline
|
||||||
|
|
||||||
:: fix-cr ( decoder c -- c' )
|
: fix-cr ( decoder c -- c' )
|
||||||
decoder cr>> [
|
over cr>> [
|
||||||
decoder cr-
|
over cr-
|
||||||
c CHAR: \n eq? [ decoder (read1) ] [ c ] if
|
dup CHAR: \n eq? [ drop (read1) ] [ nip ] if
|
||||||
] [ c ] if ; inline
|
] [ nip ] if ; inline
|
||||||
|
|
||||||
M: decoder stream-read1 ( decoder -- ch )
|
M: decoder stream-read1 ( decoder -- ch )
|
||||||
dup (read1) fix-cr ; inline
|
dup (read1) fix-cr ; inline
|
||||||
|
|
||||||
:: (read) ( count n buf stream encoding -- count )
|
: (read-first) ( n buf decoder -- buf stream encoding n c )
|
||||||
count n = [ count ] [
|
[ rot [ >decoder< ] dip 2over decode-char ]
|
||||||
stream encoding decode-char [
|
[ swap fix-cr ] bi ; inline
|
||||||
count buf set-nth-unsafe
|
|
||||||
count 1 + n buf stream encoding (read)
|
: (store-read) ( buf stream encoding n c i -- buf stream encoding n )
|
||||||
] [ count ] if*
|
[ rot [ set-nth-unsafe ] keep ] 2curry 3dip ; inline
|
||||||
|
|
||||||
|
: (finish-read) ( buf stream encoding n i -- i )
|
||||||
|
2nip 2nip ; inline
|
||||||
|
|
||||||
|
: (read-next) ( stream encoding n i -- stream encoding n i c )
|
||||||
|
[ 2dup decode-char ] 2dip rot ; inline
|
||||||
|
|
||||||
|
: (read-rest) ( buf stream encoding n i -- count )
|
||||||
|
2dup = [ (finish-read) ] [
|
||||||
|
(read-next) [
|
||||||
|
swap [ (store-read) ] [ 1 + ] bi (read-rest)
|
||||||
|
] [ (finish-read) ] if*
|
||||||
] if ; inline recursive
|
] if ; inline recursive
|
||||||
|
|
||||||
M:: decoder stream-read-unsafe ( n buf decoder -- count )
|
M: decoder stream-read-unsafe ( n buf decoder -- count )
|
||||||
n 0 = [ 0 ] [
|
pick 0 = [ 3drop 0 ] [
|
||||||
decoder >decoder< :> ( stream encoding )
|
(read-first) [
|
||||||
stream encoding decode-char :> c1
|
0 (store-read)
|
||||||
decoder c1 fix-cr :> c1'
|
1 (read-rest)
|
||||||
c1' [
|
] [ 2drop 2drop 0 ] if*
|
||||||
c1' 0 buf set-nth-unsafe
|
|
||||||
1 n buf stream encoding (read)
|
|
||||||
] [ 0 ] if
|
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
M: decoder stream-read-partial-unsafe stream-read-unsafe ; inline
|
M: decoder stream-read-partial-unsafe stream-read-unsafe ; inline
|
||||||
|
|
Loading…
Reference in New Issue