diff --git a/src/StringViews.jl b/src/StringViews.jl index d72c428..20688ff 100644 --- a/src/StringViews.jl +++ b/src/StringViews.jl @@ -39,6 +39,7 @@ Base.Vector{UInt8}(s::StringViewAndSub) = Vector{UInt8}(codeunits(s)) Base.Array{UInt8}(s::StringViewAndSub) = Vector{UInt8}(s) Base.String(s::StringViewAndSub) = String(copyto!(Base.StringVector(ncodeunits(s)), codeunits(s))) StringView(s::StringView) = s +StringView{S}(s::StringView{S}) where {S<:AbstractVector{UInt8}} = s StringView(s::String) = StringView(codeunits(s)) # iobuffer constructor (note that buf.data is always 1-based) @@ -85,7 +86,9 @@ end Base.:(==)(s1::StringViewAndSub, s2::StringAndSub) = s2 == s1 Base.typemin(::Type{StringView{Vector{UInt8}}}) = StringView(Vector{UInt8}(undef,0)) +Base.typemin(::Type{StringView{Base.CodeUnits{UInt8, String}}}) = StringView("") Base.typemin(::T) where {T<:StringView} = typemin(T) +Base.one(::Union{T,Type{T}}) where {T<:StringView} = typemin(T) if VERSION < v"1.10.0-DEV.1007" # JuliaLang/julia#47880 Base.isvalid(s::DenseStringViewAndSub) = ccall(:u8_isvalid, Int32, (Ptr{UInt8}, Int), s, sizeof(s)) ≠ 0 diff --git a/test/runtests.jl b/test/runtests.jl index c0eaeca..200eb7c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -157,6 +157,10 @@ end @test Base.typemin(s) isa StringView{Vector{UInt8}} @test Base.typemin(s) == "" + @test one(s) == one(typeof(s)) == typemin(s) == "" + @test oneunit(s) == oneunit(typeof(s)) == one(s) == "" + @test one(su) == one(typeof(su)) == typemin(su) == "" + @test oneunit(su) == oneunit(typeof(su)) == one(su) == "" @test isascii(s) @test !isascii(StringView("fööbār"))