Skip to content

Commit f11a2ae

Browse files
authored
add copy(::StringView) (#10)
1 parent 943afe3 commit f11a2ae

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/StringViews.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ 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)
39+
3840
Base.Symbol(s::DenseStringViewAndSub) =
3941
return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int), s, ncodeunits(s))
4042

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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"
1819

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

0 commit comments

Comments
 (0)