-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IOBuffer keyword support #501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1304,7 +1304,7 @@ enable_debug(x::Bool) = DEBUG[] = x | |
@static if !isdefined(Base, Symbol("@debug")) | ||
function debug(msg) | ||
DEBUG[] || return | ||
buf = IOBuffer() | ||
buf = Base.IOBuffer() | ||
iob = Base.redirect(IOContext(buf, STDERR), Base.log_info_to, :debug) | ||
print_with_color(:blue, iob, "Debug: "; bold = true) | ||
Base.println_with_color(:blue, iob, chomp(string(msg))) | ||
|
@@ -1319,7 +1319,7 @@ else | |
end | ||
@static if !isdefined(Base, Symbol("@error")) | ||
function _error(msg) | ||
buf = IOBuffer() | ||
buf = Base.IOBuffer() | ||
iob = Base.redirect(IOContext(buf, STDERR), Base.log_error_to, :error) | ||
print_with_color(Base.error_color(), iob, "Error: "; bold = true) | ||
Base.println_with_color(Base.error_color(), iob, chomp(string(msg))) | ||
|
@@ -1513,7 +1513,7 @@ else | |
Base.findnext(t::AbstractString, s::AbstractString, i::Integer) = search(s, t, i) | ||
Base.findfirst(t::AbstractString, s::AbstractString) = search(s, t) | ||
|
||
Base.findfirst(delim::EqualTo{UInt8}, buf::IOBuffer) = search(buf, delim.x) | ||
Base.findfirst(delim::EqualTo{UInt8}, buf::Base.IOBuffer) = search(buf, delim.x) | ||
|
||
Base.findprev(c::EqualTo{Char}, s::AbstractString, i::Integer) = rsearch(s, c.x, i) | ||
Base.findlast(c::EqualTo{Char}, s::AbstractString) = rsearch(s, c.x) | ||
|
@@ -1559,6 +1559,37 @@ else | |
end | ||
end | ||
|
||
# https://github.com/JuliaLang/julia/pull/25872 | ||
if VERSION < v"0.7.0-DEV.3734" | ||
function IOBuffer( | ||
data::Union{AbstractVector{UInt8},Nothing}=nothing; | ||
read::Union{Bool,Nothing}=nothing, | ||
write::Union{Bool,Nothing}=nothing, | ||
truncate::Union{Bool,Nothing}=nothing, | ||
maxsize::Integer=typemax(Int), | ||
sizehint::Union{Integer,Nothing}=nothing) | ||
write === nothing && (write = false) | ||
read === nothing && (read = !write) | ||
truncate === nothing && (truncate = false) | ||
if maxsize < 0 | ||
throw(ArgumentError("negative maxsize: $(maxsize)")) | ||
end | ||
if sizehint !== nothing | ||
sizehint!(data, sizehint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong is |
||
end | ||
buf = if data !== nothing | ||
Base.IOBuffer(data, read, write, Int(maxsize)) | ||
else | ||
size = maxsize == typemax(Int) ? 32 : Int(maxsize) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
Base.IOBuffer(StringVector(size), read, write, Int(maxsize)) | ||
end | ||
if truncate | ||
buf.size = 0 | ||
end | ||
return buf | ||
end | ||
end | ||
|
||
include("deprecated.jl") | ||
|
||
end # module Compat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
data === nothing
these should default toread=write=true
.See https://github.com/JuliaLang/julia/blob/79c7bdd9ecf20bcfb685a0abb74b028f72ccf70c/base/iobuffer.jl#L105-L106