@@ -18,17 +18,17 @@ const ByteArray = Union{Vector{UInt8},Vector{Int8}}
1818"""
1919 String(v::AbstractVector{UInt8})
2020
21- Create a new `String` from a vector `v` of bytes containing
22- UTF-8 encoded characters.
23-
24- When possible, the data in `v` will be used directly rather than making
25- a copy. This is the case for `Vector{UInt8}` arrays returned by [`take!`](@ref)
26- on a writable [`IOBuffer`](@ref) or by [`read(io, nb)`](@ref). Else, a copy is made.
27- In all cases, one should assume that the function takes "ownership" of the array
28- and that its contents should not be subsequently modified. Implementations may choose
29- to resize `v` to a zero length to enforce this (which is the case when `v` is a `Vector`) .
30-
31- If you need to subsequently modify `v`, use `String(copy(v))` instead .
21+ Create a new `String` object from a byte vector `v` containing UTF-8 encoded
22+ characters. If `v` is `Vector{UInt8}` it will be truncated to zero length and
23+ future modification of `v` cannot affect the contents of the resulting string.
24+ To avoid truncation use `String(copy(v))`.
25+
26+ When possible, the memory of `v` will be used without copying when the `String`
27+ object is created. This is guaranteed to be the case for byte vectors returned
28+ by [`take!`](@ref) on a writable [`IOBuffer`](@ref) and by calls to
29+ [`read(io, nb)`](@ref). This allows zero-copy conversion of I/O data to strings .
30+ In other cases, `Vector{UInt8}` data may be copied, but `v` is truncated anyway
31+ to guarantee consistent behavior .
3232"""
3333String (v:: AbstractVector{UInt8} ) = String (copyto! (StringVector (length (v)), v))
3434String (v:: Vector{UInt8} ) = ccall (:jl_array_to_string , Ref{String}, (Any,), v)
0 commit comments