Skip to content

Commit

Permalink
Add one for AbstractString (#19548)
Browse files Browse the repository at this point in the history
Add `one` for AbstractString
  • Loading branch information
bdeonovic authored and stevengj committed Dec 31, 2016
1 parent de957a5 commit 6484f4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ julia> "Hello " * "world"
"""
(*)(s1::AbstractString, ss::AbstractString...) = string(s1, ss...)

one{T<:AbstractString}(::Union{T,Type{T}}) = convert(T, "")

length(s::DirectIndexString) = endof(s)

"""
Expand Down
4 changes: 4 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6484f4c

Please sign in to comment.