Skip to content

Commit 111de11

Browse files
authored
Merge pull request #20 from martinholters/mh/fix_ambiguity
Remove string(::Union{ByteString,Char}...) method
2 parents ac1c56d + 75daa46 commit 111de11

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

src/utf8.jl

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -157,36 +157,6 @@ function string(a::ByteString...)
157157
UTF8String(data)
158158
end
159159

160-
function string(a::Union{ByteString,Char}...)
161-
s = Vector{UInt8}(0)
162-
for d in a
163-
if isa(d,Char)
164-
c = UInt32(d::Char)
165-
if c < 0x80
166-
push!(s, c%UInt8)
167-
elseif c < 0x800
168-
push!(s, (( c >> 6 ) | 0xC0)%UInt8)
169-
push!(s, (( c & 0x3F ) | 0x80)%UInt8)
170-
elseif c < 0x10000
171-
push!(s, (( c >> 12 ) | 0xE0)%UInt8)
172-
push!(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)
173-
push!(s, (( c & 0x3F ) | 0x80)%UInt8)
174-
elseif c < 0x110000
175-
push!(s, (( c >> 18 ) | 0xF0)%UInt8)
176-
push!(s, (((c >> 12) & 0x3F ) | 0x80)%UInt8)
177-
push!(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)
178-
push!(s, (( c & 0x3F ) | 0x80)%UInt8)
179-
else
180-
# '\ufffd'
181-
push!(s, 0xef); push!(s, 0xbf); push!(s, 0xbd)
182-
end
183-
else
184-
append!(s,d.data)
185-
end
186-
end
187-
UTF8String(s)
188-
end
189-
190160
function reverse(s::UTF8String)
191161
dat = s.data
192162
n = length(dat)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ end
235235
# Specifically check UTF-8 string whose lead byte is same as a surrogate
236236
@test convert(UTF8String,b"\xed\x9f\xbf") == "\ud7ff"
237237

238+
# issue #8
239+
@test !isempty(methods(string, Tuple{Char}))
240+
238241
## UTF-16 tests
239242

240243
u8 = "\U10ffff\U1d565\U1d7f6\U00066\U2008a"

0 commit comments

Comments
 (0)