diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 21a706bee25cd..5126aa73a6772 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -108,6 +108,8 @@ julia> "Hello " * "world" (.*){T<:AbstractString}(v::Vector{T},s::AbstractString) = [i*s for i in v] (.*){T<:AbstractString}(s::AbstractString,v::Vector{T}) = [s*i for i in v] +one{T<:AbstractString}(::Union{T,Type{T}}) = convert(T, "") + length(s::DirectIndexString) = endof(s) """ diff --git a/test/strings/basic.jl b/test/strings/basic.jl index aa1ccc2559ec6..949fabb9af2f4 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -416,6 +416,10 @@ foobaz(ch) = reinterpret(Char, typemax(UInt32)) @test ["b","c"].*"a" == ["ba","ca"] @test ["a","b"].*["c" "d"] == ["ac" "ad"; "bc" "bd"] +@test one(String) == "" +@test prod(["*" for i in 1:3]) == "***" +@test prod(["*" for i in 1:0]) == "" + # Make sure NULL pointers are handled consistently by String @test_throws ArgumentError unsafe_string(Ptr{UInt8}(0)) @test_throws ArgumentError unsafe_string(Ptr{UInt8}(0), 10)