Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/DataStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,14 @@ Base.Symbol(s::DataString) = Symbol(String(s))
Base.promote_rule(::Type{DataString}, ::Type{String}) = String

function Base.write(io::IO, s::DataString)
n = 0
@inbounds for i = 1:ncodeunits(s)
n += write(io, codeunit(s, i))
n = ncodeunits(s)
# a view's content is one contiguous run of its retained buffer
n > INLINE_MAX && return GC.@preserve s unsafe_write(io, pointer(s.data, payloadpos(s.p)), n)
m = 0
@inbounds for i = 1:n
m += write(io, codeunit(s, i))
end
return n
return m
end
Base.print(io::IO, s::DataString) = (write(io, s); nothing)

Expand Down
6 changes: 6 additions & 0 deletions test/construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ end
@test read(io,String) == "伪尾"
end
@test DataString["a","b"] == ["a","b"]
longs = StringVector(["first long string value", "second long string value"])
for s in (DataString(""), DataString("伪尾"), DataString("twelve bytes"), longs[1], longs[2])
io = IOBuffer()
@test write(io, s) == ncodeunits(s)
@test String(take!(io)) == String(s)
end
values = Union{String,Missing}["a", "a long value retained by a view", missing]
col = StringVector(values)
retained = col[2]
Expand Down
Loading