Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Char * String and Char * Char #22532

Merged
merged 10 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ julia> "Hello " * "world"
```
"""
(*)(s1::AbstractString, ss::AbstractString...) = string(s1, ss...)
(*)(c::Char, s::AbstractString) = string(c, s)
(*)(s::AbstractString, c::Char) = string(s, c)
(*)(c1::Char, c2::Char) = string(c1, c2)
Copy link
Contributor

@pabloferz pabloferz Jun 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might subsume all these with

(*)(s::AbstractString, ss::Union{Char,AbstractString}...) = string(s, ss...)
(*)(c::Char, ss::Union{Char,AbstractString}...) = string(c, ss...)

and take advantage of the string(::Union{Char,String}...) method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reduced it further to one method (see next commit)


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

Expand Down
7 changes: 7 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,10 @@ Base.endof(x::CharStr) = endof(x.chars)
# issue #12495: check that logical indexing attempt raises ArgumentError
@test_throws ArgumentError "abc"[[true, false, true]]
@test_throws ArgumentError "abc"[BitArray([true, false, true])]

@test "ab" * "cd" == "abcd"
@test 'a' * "bc" == "abc"
@test "ab" * 'c' == "abc"
@test 'a' * 'b' == "ab"
@test 'a' * "b" * 'c' == "abc"
@test "a" * 'b' * 'c' == "abc"