Skip to content

Commit

Permalink
Remove conversions from Vector{UInt32}
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed Jul 1, 2015
1 parent 000e7ae commit 725f9f4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions base/utf32.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ function convert(::Type{UTF32String}, str::AbstractString)
UTF32String(buf)
end

convert(::Type{UTF8String}, dat::Vector{Char}) = convert(UTF8String, reinterpret(UInt32, dat))
"
Converts a UTF-32 encoded vector of `UInt32` to a `UTF8String`
Converts a vector of `Char` to a `UTF8String`
### Returns:
* `UTF8String`
### Throws:
* `UnicodeError`
"
function convert(::Type{UTF8String}, dat::Vector{UInt32})
len = sizeof(dat)
function convert(::Type{UTF8String}, chrs::Vector{Char})
len = sizeof(chrs)
# handle zero length string quickly
len == 0 && return empty_utf8
dat = reinterpret(UInt32, chrs)
# get number of bytes to allocate
len, flags, num4byte, num3byte, num2byte = unsafe_checkstring(dat, 1, len>>>2)
flags == 0 && @inbounds return UTF8String(copy!(Vector{UInt8}(len), 1, dat, 1, len))
Expand Down Expand Up @@ -158,18 +160,19 @@ function convert(::Type{UTF32String}, str::UTF16String)
end

"
Converts a UTF-32 encoded vector of `UInt32` to a `UTF16String`
Converts a vector of `Char` to a `UTF16String`
### Returns:
* `::UTF16String`
### Throws:
* `UnicodeError`
"
function convert(::Type{UTF16String}, dat::Vector{UInt32})
len = sizeof(dat)
function convert(::Type{UTF16String}, chrs::Vector{Char})
len = sizeof(chrs)
# handle zero length string quickly
len <= 4 && return empty_utf16
len == 0 && return empty_utf16
dat = reinterpret(UInt32, chrs)
# get number of words to allocate
len, flags, num4byte = unsafe_checkstring(dat, 1, len>>>2)
len += num4byte + 1
Expand Down Expand Up @@ -226,9 +229,6 @@ function encode_to_utf16(dat, len)
UTF16String(buf)
end

convert(::Type{UTF8String}, dat::Vector{Char}) = convert(UTF8String, reinterpret(UInt32, dat))

convert(::Type{UTF16String}, dat::Vector{Char}) = convert(UTF16String, reinterpret(UInt32, dat))
convert(::Type{UTF32String}, c::Char) = UTF32String(Char[c, Char(0)])

function convert(::Type{UTF32String}, str::ASCIIString)
Expand Down

0 comments on commit 725f9f4

Please sign in to comment.