Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3177fa3

Browse files
authored
Implementreadavailable andbytesavailable (#53)
These are used notably by the fallback `write(::IO, ::IO)` implementation.Their absence makes `CSV.File(open(f, enc"..."))` fail with recent CSV.jl versions.
1 parent2085821 commit3177fa3

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

‎src/StringEncodings.jl‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ using Libiconv_jll
66

77
using Base.Libc: errno, strerror, E2BIG, EINVAL, EILSEQ
88

9-
import Base: close, eachline, eof, flush, isreadable, iswritable,
10-
open, read, readbytes!, readline, readlines, readuntil, show, write
9+
import Base: bytesavailable, close, eachline, eof, flush, isreadable, iswritable,
10+
open, read, readavailable, readbytes!, readline, readlines,
11+
readuntil, show, write
1112

1213
export StringEncoder, StringDecoder, encode, decode, encodings
1314
export StringEncodingError, OutputBufferError, IConvError
@@ -339,6 +340,18 @@ function read(s::StringDecoder, ::Type{UInt8})
339340
eof(s)?throw(EOFError()): s.outbuf[s.skip+=1]
340341
end
341342

343+
bytesavailable(s::StringDecoder)=
344+
Int(BUFSIZE- s.outbytesleft[]- s.skip)
345+
346+
functionreadavailable(s::StringDecoder)
347+
s.cd==C_NULL&&throw(ArgumentError("cannot read from closed StringDecoder"))
348+
eof(s)# Load more data into buffer if it is empty
349+
ob= s.outbytesleft[]
350+
res= s.outbuf[(s.skip+1):(BUFSIZE- ob)]
351+
s.skip= BUFSIZE- ob
352+
return res
353+
end
354+
342355
isreadable(s::StringDecoder)= s.cd!=C_NULL&&isreadable(s.stream)
343356
iswritable(s::StringDecoder)=false
344357

‎test/runtests.jl‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,30 @@ end
246246
end
247247
end
248248

249+
@testset"readavailable and bytesavailable"begin
250+
s="a string チャネルパートナーの選択"^10
251+
b=IOBuffer(encode(s,"UTF-16LE"))
252+
p=StringDecoder(b,"UTF-16LE")
253+
@testread(p, String)== s
254+
255+
b=IOBuffer(encode(s,"UTF-16LE"))
256+
p=StringDecoder(b,"UTF-16LE")
257+
@testbytesavailable(p)==0
258+
@testread(p, UInt8)===0x61
259+
@testbytesavailable(p)==197
260+
@testString(readavailable(p))== s[2:196]
261+
@testbytesavailable(p)==0
262+
@testString(readavailable(p))== s[199:394]
263+
@testbytesavailable(p)==0
264+
@testString(readavailable(p))== s[397:end]
265+
@testisempty(readavailable(p))
266+
@testbytesavailable(p)==0
267+
@testeof(p)
268+
close(p)
269+
@testbytesavailable(p)==0
270+
@test_throws ArgumentErrorreadavailable(p)
271+
end
272+
249273

250274
## Test encodings support
251275
b=IOBuffer()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp