Skip to content

Commit 6b31fe3

Browse files
committed
eliminate method ambiguities
1 parent fe437af commit 6b31fe3

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

base/c.jl

+9-11
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,22 @@ Convert string data between Unicode encodings. `src` is either a
129129
`String` or a `Vector{UIntXX}` of UTF-XX code units, where
130130
`XX` is 8, 16, or 32. `T` indicates the encoding of the return value:
131131
`String` to return a (UTF-8 encoded) `String` or `UIntXX`
132-
to return a `Vector{UIntXX}` of UTF-`XX` data.
132+
to return a `Vector{UIntXX}` of UTF-`XX` data. Only conversion
133+
to or from UTF-8 is currently supported.
133134
"""
134135
function transcode end
135136

136-
transcode{T<:Union{UInt8,UInt16}}(::Type{T}, src::Vector{T}) = src
137-
transcode(T, src::String) = transcode(T, src.data)
138-
transcode(::Type{String}, src) = String(transcode(UInt8, src))
139-
140-
transcode(::Type{Int32}, src::Vector{UInt32}) = reinterpret(Int32, src)
137+
transcode{T<:Union{UInt8,UInt16,UInt32,Int32}}(::Type{T}, src::Vector{T}) = src
141138
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::String) = T[T(c) for c in src]
142-
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src) = transcode(T, transcode(String, src))
143-
transcode{S<:Union{Int32,UInt32}}(T, src::Vector{S}) = transcode(T, transcode(String, src))
144-
function transcode{S<:Union{Int32,UInt32}}(::Type{String}, src::Vector{S})
139+
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::Vector{UInt8}) = transcode(T, String(src))
140+
function transcode{S<:Union{Int32,UInt32}}(::Type{UInt8}, src::Vector{S})
145141
buf = IOBuffer()
146142
for c in src; print(buf, Char(c)); end
147-
takebuf_string(buf)
143+
takebuf_array(buf)
148144
end
149-
transcode(::Type{UInt16}, src::Vector) = transcode(UInt16, transcode(UInt8, src))
145+
transcode(::Type{String}, src::String) = src
146+
transcode(T, src::String) = transcode(T, src.data)
147+
transcode(::Type{String}, src) = String(transcode(UInt8, src))
150148

151149
function transcode(::Type{UInt16}, src::Vector{UInt8})
152150
dst = UInt16[]

doc/stdlib/strings.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
.. Docstring generated from Julia source
6262
63-
Convert string data between Unicode encodings. ``src`` is either a ``String`` or a ``Vector{UIntXX}`` of UTF-XX code units, where ``XX`` is 8, 16, or 32. ``T`` indicates the encoding of the return value: ``String`` to return a (UTF-8 encoded) ``String`` or ``UIntXX`` to return a ``Vector{UIntXX}`` of UTF-``XX`` data.
63+
Convert string data between Unicode encodings. ``src`` is either a ``String`` or a ``Vector{UIntXX}`` of UTF-XX code units, where ``XX`` is 8, 16, or 32. ``T`` indicates the encoding of the return value: ``String`` to return a (UTF-8 encoded) ``String`` or ``UIntXX`` to return a ``Vector{UIntXX}`` of UTF-``XX`` data. Only conversion to or from UTF-8 is currently supported.
6464

6565
.. function:: unsafe_string(p::Ptr{UInt8}, [length::Integer])
6666

@@ -506,3 +506,4 @@
506506
.. Docstring generated from Julia source
507507
508508
Create a string from the address of a NUL-terminated UTF-32 string. A copy is made; the pointer can be safely freed. If ``length`` is specified, the string does not have to be NUL-terminated.
509+

0 commit comments

Comments
 (0)