Skip to content

Commit

Permalink
Fix typo in readuntil (#54259)
Browse files Browse the repository at this point in the history
Also use `isascii` instead of `≤ '\x7f'` because `isascii` handles malformed `Char` slightly better.
  • Loading branch information
nhz2 authored Apr 26, 2024
1 parent 69b73e0 commit c41c713
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ function readuntil_string(s::IOStream, delim::UInt8, keep::Bool)
@_lock_ios s ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, delim, 1, !keep)
end
readuntil(s::IOStream, delim::AbstractChar; keep::Bool=false) =
delim '\x7f' ? readuntil_string(s, delim % UInt8, keep) :
String(unsafe_take!(copyuntil(IOBuffer(sizehint=70), s, delim; keep)))
isascii(delim) ? readuntil_string(s, delim % UInt8, keep) :
String(_unsafe_take!(copyuntil(IOBuffer(sizehint=70), s, delim; keep)))

function readline(s::IOStream; keep::Bool=false)
@_lock_ios s ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, '\n', 1, keep ? 0 : 2)
Expand Down
4 changes: 4 additions & 0 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ for (name, f) in l
local t, s, m, kept
@test readuntil(io(t), s) == m
@test readuntil(io(t), s, keep=true) == kept
if isone(length(s))
@test readuntil(io(t), first(s)) == m
@test readuntil(io(t), first(s), keep=true) == kept
end
@test readuntil(io(t), SubString(s, firstindex(s))) == m
@test readuntil(io(t), SubString(s, firstindex(s)), keep=true) == kept
@test readuntil(io(t), GenericString(s)) == m
Expand Down

0 comments on commit c41c713

Please sign in to comment.