JuliaLang/julia

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

Geschlossen

#28.612 geöffnet am 12.08.2018

 (2 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Julia (5.773 Forks)batch import
arraysgood first issuestrings

Repository-Metriken

Stars
 (48.709 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 20T 6h) (157 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide