JuliaLang/julia

transcode(String, ::Vector{UInt}) is destructive

已關閉

#28,612 建立於 2018年8月12日

 (2 則留言) (0 個反應) (1 位負責人)Julia (5,773 個分叉)batch import
arraysgood first issuestrings

倉庫指標

星標
 (48,709 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

I'm seeing the following behaviour on 1.0:

julia> a = collect(transcode(UInt8, "abc"))
3-element Array{UInt8,1}:
 0x61
 0x62
 0x63

julia> b = transcode(String, a)
"abc"

julia> a
0-element Array{UInt8,1}

Note that this is only the case when a is a Vector{UInt8} (obtained through collect). When keeping the CodeUnits variable returned by the transcode(UInt8,...) call, there is no destruction:

julia> a = transcode(UInt8, "abc")
3-element Base.CodeUnits{UInt8,String}:
 0x61
 0x62
 0x63

julia> b = transcode(String, a)
"abc"

julia> a
3-element Base.CodeUnits{UInt8,String}:
 0x61
 0x62
 0x63

貢獻者指南