Fix stream-read-until on byte-readers
parent
60fe59d873
commit
f97389503f
|
@ -1,5 +1,5 @@
|
||||||
USING: tools.test io.streams.byte-array io.encodings.binary
|
USING: tools.test io.streams.byte-array io.encodings.binary
|
||||||
io.encodings.utf8 io kernel arrays strings ;
|
io.encodings.utf8 io kernel arrays strings namespaces ;
|
||||||
|
|
||||||
[ B{ 1 2 3 } ] [ binary [ { 1 2 3 } write ] with-byte-writer ] unit-test
|
[ B{ 1 2 3 } ] [ binary [ { 1 2 3 } write ] with-byte-writer ] unit-test
|
||||||
[ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
|
[ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
|
||||||
|
@ -7,3 +7,23 @@ io.encodings.utf8 io kernel arrays strings ;
|
||||||
[ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
|
[ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
|
||||||
[ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } utf8 [ write ] with-byte-writer ] unit-test
|
[ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } utf8 [ write ] with-byte-writer ] unit-test
|
||||||
[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 <byte-reader> contents dup >array swap string? ] unit-test
|
[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 <byte-reader> contents dup >array swap string? ] unit-test
|
||||||
|
|
||||||
|
[ B{ 121 120 } 0 ] [
|
||||||
|
B{ 0 121 120 0 0 0 0 0 0 } binary
|
||||||
|
[ 1 read drop "\0" read-until ] with-byte-reader
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ 1 1 4 11 f ] [
|
||||||
|
B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
|
||||||
|
[
|
||||||
|
read1
|
||||||
|
0 seek-absolute input-stream get stream-seek
|
||||||
|
read1
|
||||||
|
2 seek-relative input-stream get stream-seek
|
||||||
|
read1
|
||||||
|
-2 seek-end input-stream get stream-seek
|
||||||
|
read1
|
||||||
|
0 seek-end input-stream get stream-seek
|
||||||
|
read1
|
||||||
|
] with-byte-reader
|
||||||
|
] unit-test
|
|
@ -28,7 +28,7 @@ M: byte-reader stream-seek ( n seek-type stream -- )
|
||||||
swap {
|
swap {
|
||||||
{ seek-absolute [ (>>i) ] }
|
{ seek-absolute [ (>>i) ] }
|
||||||
{ seek-relative [ [ + ] change-i drop ] }
|
{ seek-relative [ [ + ] change-i drop ] }
|
||||||
{ seek-end [ dup underlying>> length >>i [ + ] change-i drop ] }
|
{ seek-end [ [ underlying>> length + ] keep (>>i) ] }
|
||||||
[ bad-seek-type ]
|
[ bad-seek-type ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@ SLOT: i
|
||||||
[ 1+ ] change-i drop ; inline
|
[ 1+ ] change-i drop ; inline
|
||||||
|
|
||||||
: sequence-read1 ( stream -- elt/f )
|
: sequence-read1 ( stream -- elt/f )
|
||||||
[ >sequence-stream< ?nth ]
|
[ >sequence-stream< ?nth ] [ next ] bi ; inline
|
||||||
[ next ] bi ; inline
|
|
||||||
|
|
||||||
: add-length ( n stream -- i+n )
|
: add-length ( n stream -- i+n )
|
||||||
[ i>> + ] [ underlying>> length ] bi min ; inline
|
[ i>> + ] [ underlying>> length ] bi min ; inline
|
||||||
|
@ -32,8 +31,8 @@ SLOT: i
|
||||||
[ (sequence-read) ] [ 2drop f ] if ; inline
|
[ (sequence-read) ] [ 2drop f ] if ; inline
|
||||||
|
|
||||||
: find-sep ( seps stream -- sep/f n )
|
: find-sep ( seps stream -- sep/f n )
|
||||||
swap [ >sequence-stream< ] dip
|
swap [ >sequence-stream< swap tail-slice ] dip
|
||||||
[ memq? ] curry find-from swap ; inline
|
[ memq? ] curry find swap ; inline
|
||||||
|
|
||||||
: sequence-read-until ( separators stream -- seq sep/f )
|
: sequence-read-until ( separators stream -- seq sep/f )
|
||||||
[ find-sep ] keep
|
[ find-sep ] keep
|
||||||
|
|
Loading…
Reference in New Issue