Skip to content

Commit

Permalink
eliminate method ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jul 8, 2016
1 parent fe437af commit 6b31fe3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
20 changes: 9 additions & 11 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,22 @@ 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.
to return a `Vector{UIntXX}` of UTF-`XX` data. Only conversion
to or from UTF-8 is currently supported.
"""
function transcode end

transcode{T<:Union{UInt8,UInt16}}(::Type{T}, src::Vector{T}) = src
transcode(T, src::String) = transcode(T, src.data)
transcode(::Type{String}, src) = String(transcode(UInt8, src))

transcode(::Type{Int32}, src::Vector{UInt32}) = reinterpret(Int32, src)
transcode{T<:Union{UInt8,UInt16,UInt32,Int32}}(::Type{T}, src::Vector{T}) = src
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::String) = T[T(c) for c in src]
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src) = transcode(T, transcode(String, src))
transcode{S<:Union{Int32,UInt32}}(T, src::Vector{S}) = transcode(T, transcode(String, src))
function transcode{S<:Union{Int32,UInt32}}(::Type{String}, src::Vector{S})
transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::Vector{UInt8}) = transcode(T, String(src))
function transcode{S<:Union{Int32,UInt32}}(::Type{UInt8}, src::Vector{S})
buf = IOBuffer()
for c in src; print(buf, Char(c)); end
takebuf_string(buf)
takebuf_array(buf)
end
transcode(::Type{UInt16}, src::Vector) = transcode(UInt16, transcode(UInt8, src))
transcode(::Type{String}, src::String) = src
transcode(T, src::String) = transcode(T, src.data)
transcode(::Type{String}, src) = String(transcode(UInt8, src))

function transcode(::Type{UInt16}, src::Vector{UInt8})
dst = UInt16[]
Expand Down
3 changes: 2 additions & 1 deletion doc/stdlib/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

.. Docstring generated from Julia source
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.
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.

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

Expand Down Expand Up @@ -506,3 +506,4 @@
.. Docstring generated from Julia source
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.

0 comments on commit 6b31fe3

Please sign in to comment.