Skip to content

Commit 9e1c9aa

Browse files
authored
make copy(::StringView) return a StringView (with copied data) (#11)
* make copy(::StringView) return a StringView (with copied data) * fix test
1 parent 2ae9907 commit 9e1c9aa

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/StringViews.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Base.String(s::StringViewAndSub) = String(copyto!(Base.StringVector(ncodeunits(s
3535
StringView(s::StringView) = s
3636
StringView(s::String) = StringView(codeunits(s))
3737

38-
Base.copy(s::StringView) = String(s)
38+
Base.copy(s::StringView) = StringView(copy(s.data))
3939

4040
Base.Symbol(s::DenseStringViewAndSub) =
4141
return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int), s, ncodeunits(s))

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ su = StringView("föôẞαr")
1515
@test Vector{UInt8}(abc) == collect(0x61:0x63)
1616
@test Symbol(s) == :foobar
1717
@test Symbol(abc) == :abc
18-
@test copy(s)::String == "foobar"
18+
c = copy(s)
19+
@test c isa StringView
20+
@test c == "foobar"
21+
@test c.data !== s.data
1922

2023
@test StringView("foo") isa StringView{Base.CodeUnits{UInt8,String}}
2124

0 commit comments

Comments
 (0)