io.encodings.string: make binary decode/encode nop
Fixes #319.
parent
eec7602aed
commit
7f94e07180
|
|
@ -1,10 +1,11 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg.
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: strings io.encodings.utf8 io.encodings.utf16
|
USING: strings io.encodings.utf8 io.encodings.utf16
|
||||||
io.encodings.string tools.test ;
|
io.encodings.string tools.test io.encodings.binary ;
|
||||||
IN: io.encodings.string.tests
|
IN: io.encodings.string.tests
|
||||||
|
|
||||||
[ "hello" ] [ "hello" utf8 decode ] unit-test
|
[ "hello" ] [ "hello" utf8 decode ] unit-test
|
||||||
|
[ B{ 0 1 22 255 } ] [ B{ 0 1 22 255 } binary decode ] unit-test
|
||||||
[ "he" ] [ "\0h\0e" utf16be decode ] unit-test
|
[ "he" ] [ "\0h\0e" utf16be decode ] unit-test
|
||||||
|
|
||||||
[ "hello" ] [ "hello" utf8 encode >string ] unit-test
|
[ "hello" ] [ "hello" utf8 encode >string ] unit-test
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,23 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg.
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: byte-vectors io io.encodings io.streams.byte-array
|
USING: byte-vectors io io.encodings io.streams.byte-array
|
||||||
io.streams.string kernel locals sbufs sequences ;
|
io.streams.string kernel locals sbufs sequences io.private
|
||||||
|
io.encodings.binary ;
|
||||||
IN: io.encodings.string
|
IN: io.encodings.string
|
||||||
|
|
||||||
:: decode ( byte-array encoding -- string )
|
:: decode ( byte-array encoding -- string )
|
||||||
byte-array encoding <byte-reader> :> reader
|
encoding binary eq? [ byte-array ] [
|
||||||
byte-array length encoding guess-decoded-length <sbuf> :> buf
|
byte-array encoding <byte-reader> :> reader
|
||||||
[ reader stream-read1 dup ] [ buf push ] while drop
|
byte-array length
|
||||||
buf "" like ; inline
|
encoding guess-decoded-length
|
||||||
|
reader stream-exemplar-growable new-resizable :> buf
|
||||||
|
[ reader stream-read1 dup ] [ buf push ] while drop
|
||||||
|
buf reader stream-exemplar like
|
||||||
|
] if ; inline
|
||||||
|
|
||||||
:: encode ( string encoding -- byte-array )
|
:: encode ( string encoding -- byte-array )
|
||||||
string length encoding guess-encoded-length <byte-vector> :> vec
|
encoding binary eq? [ string ] [
|
||||||
string vec encoding <encoder> stream-write
|
string length encoding guess-encoded-length <byte-vector> :> vec
|
||||||
vec B{ } like ; inline
|
string vec encoding <encoder> stream-write
|
||||||
|
vec B{ } like
|
||||||
|
] if ; inline
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue