Skip to content

Commit

Permalink
Merge pull request #20 from martinholters/mh/fix_ambiguity
Browse files Browse the repository at this point in the history
Remove string(::Union{ByteString,Char}...) method
  • Loading branch information
stevengj authored May 26, 2017
2 parents ac1c56d + 75daa46 commit 111de11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
30 changes: 0 additions & 30 deletions src/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,36 +157,6 @@ function string(a::ByteString...)
UTF8String(data)
end

function string(a::Union{ByteString,Char}...)
s = Vector{UInt8}(0)
for d in a
if isa(d,Char)
c = UInt32(d::Char)
if c < 0x80
push!(s, c%UInt8)
elseif c < 0x800
push!(s, (( c >> 6 ) | 0xC0)%UInt8)
push!(s, (( c & 0x3F ) | 0x80)%UInt8)
elseif c < 0x10000
push!(s, (( c >> 12 ) | 0xE0)%UInt8)
push!(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)
push!(s, (( c & 0x3F ) | 0x80)%UInt8)
elseif c < 0x110000
push!(s, (( c >> 18 ) | 0xF0)%UInt8)
push!(s, (((c >> 12) & 0x3F ) | 0x80)%UInt8)
push!(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)
push!(s, (( c & 0x3F ) | 0x80)%UInt8)
else
# '\ufffd'
push!(s, 0xef); push!(s, 0xbf); push!(s, 0xbd)
end
else
append!(s,d.data)
end
end
UTF8String(s)
end

function reverse(s::UTF8String)
dat = s.data
n = length(dat)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ end
# Specifically check UTF-8 string whose lead byte is same as a surrogate
@test convert(UTF8String,b"\xed\x9f\xbf") == "\ud7ff"

# issue #8
@test !isempty(methods(string, Tuple{Char}))

## UTF-16 tests

u8 = "\U10ffff\U1d565\U1d7f6\U00066\U2008a"
Expand Down

0 comments on commit 111de11

Please sign in to comment.