Skip to content

Commit

Permalink
Add Compat.readline (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb authored Mar 6, 2017
1 parent 9a95537 commit 2d0f590
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.isapprox` with `nans` keyword argument ([#20022])

* `Compat.readline` with `chomp` keyword argument ([#20203])

* `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s ([#19841])

* The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation.
Expand Down Expand Up @@ -336,6 +338,7 @@ includes this fix. Find the minimum version from there.
[#19950]: https://github.com/JuliaLang/julia/issues/19950
[#20022]: https://github.com/JuliaLang/julia/issues/20022
[#20164]: https://github.com/JuliaLang/julia/issues/20164
[#20203]: https://github.com/JuliaLang/julia/issues/20203
[#20321]: https://github.com/JuliaLang/julia/issues/20321
[#20414]: https://github.com/JuliaLang/julia/issues/20414
[#20418]: https://github.com/JuliaLang/julia/issues/20418
Expand Down
16 changes: 14 additions & 2 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ if VERSION < v"0.5.0-dev+2228"
Base.read(filename::AbstractString, args...) = open(io->read(io, args...), filename)
Base.read!(filename::AbstractString, a) = open(io->read!(io, a), filename)
Base.readuntil(filename::AbstractString, args...) = open(io->readuntil(io, args...), filename)
Base.readline(filename::AbstractString) = open(readline, filename)
Base.readlines(filename::AbstractString) = open(readlines, filename)
Base.readline(filename::AbstractString) = open(Base.readline, filename)
Base.readlines(filename::AbstractString) = open(Base.readlines, filename)
Base.readavailable(s::IOStream) = read!(s, @compat Vector{UInt8}(nb_available(s)))
Base.readavailable(s::IOBuffer) = read(s)

Expand Down Expand Up @@ -1411,6 +1411,18 @@ if VERSION < v"0.6.0-dev.2840"
IndexStyle(args...) = Base.linearindexing(args...)
end

# https://github.com/JuliaLang/julia/pull/20203
if VERSION < v"0.6.0-dev.2283"
# not exported
function readline(s::IO=STDIN; chomp::Bool=true)
if chomp
Base.chomp!(Base.readline(s))
else
Base.readline(s)
end
end
end

include("to-be-deprecated.jl")

end # module Compat
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1763,4 +1763,9 @@ let a = CompatArray.CartesianArray(rand(2,3)), b = CompatArray.LinearArray(rand(
@test IndexStyle(b) === IndexLinear()
end

# PR 20203
@test Compat.readline(IOBuffer("Hello, World!\n")) == "Hello, World!"
@test Compat.readline(IOBuffer("x\n"), chomp=true) == "x"
@test Compat.readline(IOBuffer("x\n"), chomp=false) == "x\n"

include("to-be-deprecated.jl")

0 comments on commit 2d0f590

Please sign in to comment.