Skip to content

Commit

Permalink
Merge pull request JuliaLang#13727 from bjarthur/stringmultiply
Browse files Browse the repository at this point in the history
Vector{String} .* String
  • Loading branch information
jakebolewski committed Dec 8, 2015
2 parents d2da18c + 9476d7f commit 665fdd2
Show file tree
Hide file tree
Showing 2 changed files with 8 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 @@ -48,6 +48,8 @@ sizeof(s::AbstractString) = error("type $(typeof(s)) has no canonical binary rep
eltype{T<:AbstractString}(::Type{T}) = Char

(*)(s1::AbstractString, ss::AbstractString...) = string(s1, ss...)
(.*){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]

length(s::DirectIndexString) = endof(s)
function length(s::AbstractString)
Expand Down
6 changes: 6 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,9 @@ foobaz(ch) = reinterpret(Char, typemax(UInt32))
@test_throws UnicodeError map(foomap, utf16(str))
@test_throws UnicodeError map(foobar, utf16(str))
@test_throws UnicodeError map(foobaz, utf16(str))

@test "a".*["b","c"] == ["ab","ac"]
@test ["b","c"].*"a" == ["ba","ca"]
@test utf8("a").*["b","c"] == ["ab","ac"]
@test "a".*map(utf8,["b","c"]) == ["ab","ac"]
@test ["a","b"].*["c","d"]' == ["ac" "ad"; "bc" "bd"]

0 comments on commit 665fdd2

Please sign in to comment.