Skip to content

Commit

Permalink
make Vector{UInt8}(::String) copy as documented.
Browse files Browse the repository at this point in the history
closes #24388
  • Loading branch information
JeffBezanson committed Dec 6, 2018
1 parent 1c05d0c commit f72ee3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/strings/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ String(s::Symbol) = unsafe_string(unsafe_convert(Ptr{UInt8}, s))
unsafe_wrap(::Type{Vector{UInt8}}, s::String) = ccall(:jl_string_to_array, Ref{Vector{UInt8}}, (Any,), s)

(::Type{Vector{UInt8}})(s::CodeUnits{UInt8,String}) = copyto!(Vector{UInt8}(undef, length(s)), s)
(::Type{Vector{UInt8}})(s::String) = Vector{UInt8}(codeunits(s))
(::Type{Array{UInt8}})(s::String) = Vector{UInt8}(codeunits(s))

String(s::CodeUnits{UInt8,String}) = s.s

Expand Down
4 changes: 4 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,10 @@ let v = unsafe_wrap(Vector{UInt8}, "abc")
@test_throws BoundsError v[1]
push!(v, UInt8('x'))
@test s == "abc"
s = "abc"
v = Vector{UInt8}(s)
v[1] = 0x40
@test s == "abc"
end

# PR #25535
Expand Down

0 comments on commit f72ee3c

Please sign in to comment.