Skip to content

Commit a91655b

Browse files
nhz2KristofferC
authored andcommitted
Fix typo in readuntil (#54259)
Also use `isascii` instead of `≤ '\x7f'` because `isascii` handles malformed `Char` slightly better. (cherry picked from commit c41c713)
1 parent 92db099 commit a91655b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

base/iostream.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ function readuntil_string(s::IOStream, delim::UInt8, keep::Bool)
446446
@_lock_ios s ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, delim, 1, !keep)
447447
end
448448
readuntil(s::IOStream, delim::AbstractChar; keep::Bool=false) =
449-
delim '\x7f' ? readuntil_string(s, delim % UInt8, keep) :
450-
String(unsafe_take!(copyuntil(IOBuffer(sizehint=70), s, delim; keep)))
449+
isascii(delim) ? readuntil_string(s, delim % UInt8, keep) :
450+
String(_unsafe_take!(copyuntil(IOBuffer(sizehint=70), s, delim; keep)))
451451

452452
function readline(s::IOStream; keep::Bool=false)
453453
@_lock_ios s ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, '\n', 1, keep ? 0 : 2)

test/read.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ for (name, f) in l
170170
local t, s, m, kept
171171
@test readuntil(io(t), s) == m
172172
@test readuntil(io(t), s, keep=true) == kept
173+
if isone(length(s))
174+
@test readuntil(io(t), first(s)) == m
175+
@test readuntil(io(t), first(s), keep=true) == kept
176+
end
173177
@test readuntil(io(t), SubString(s, firstindex(s))) == m
174178
@test readuntil(io(t), SubString(s, firstindex(s)), keep=true) == kept
175179
@test readuntil(io(t), GenericString(s)) == m

0 commit comments

Comments
 (0)