Skip to content

Commit 73c1b4b

Browse files
authored
Merge pull request #23 from JuliaString/spj/split
Fix sprint, Vararg deprecation, deal with change in Meta.parse result
2 parents 99d4fbb + 5857e5a commit 73c1b4b

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/io.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,15 @@ print(io::IO, str::MaybeSub{<:Str{<:CSE}}) = (_write(UTF8CSE, io, str) ; nothing
213213
print(io::IO, str::MaybeSub{T}) where {T<:Str{<:Union{Binary_CSEs,ASCIICSE,UTF8_CSEs}}} =
214214
(_fastwrite(io, str); nothing)
215215

216-
function Base.sprint(f::Function, ::Type{T}, args...;
217-
context=nothing, sizehint::Integer=0) where {T<:Union{String, Str}}
216+
function Base.sprint(f::Function, ::T, args...; context=nothing, sizehint::Integer=0
217+
) where {C<:Union{Binary_CSEs,ASCIICSE,UTF8_CSEs},T<:Str{C}}
218218
s = IOBuffer(sizehint=sizehint)
219-
if context !== nothing
220-
f(IOContext(s, context), args...)
221-
S = get(context, :type, T)
222-
S(resize!(s.data, s.size))
219+
if context != nothing
220+
f(context isa Tuple ? IOContext(s, context...) : IOContext(s, context), args...)
221+
Str(get(s.dict, :type, C), resize!(s.data, s.size))
223222
else
224223
f(s, args...)
225-
T(resize!(s.data, s.size))
224+
String(_unsafe_take!(s))
226225
end
227226
end
228227

src/util.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ rpad(ch::Chr, cnt::Integer, pad::AbstractChar=' ') =
6363
(cnt -= 1) <= 0 ? string(ch) : string(ch, pad^cnt)
6464

6565
const SetOfChars =
66-
Union{Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}
66+
Union{Tuple{Vararg{AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}
6767

6868
function __split(str, splitter, limit::Integer, keep_empty::Bool, strs::Vector)
6969
pos = 1

test/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ end
962962
@test Meta.lower(Main, sym) === sym
963963
res = string(Meta.parse(string(Char(0xdcdb)," = 1"),1,raise=false)[1])
964964
@static if VERSION v"1.5.0-DEV.460"
965-
@test res == "\$(Expr(:error, \"invalid UTF-8 sequence\"))"
965+
@test contains(res, "invalid UTF-8 sequence")
966966
else
967967
@test startswith(res, "\$(Expr(:error, \"invalid character \\\"\\udcdb\\\"")
968968
@test endswith(res, "\"))")

0 commit comments

Comments
 (0)