Skip to content

Commit

Permalink
Remove conversions from Vector{Char} to UTF8String and UTF16String
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman committed Jul 19, 2015
1 parent c08b1bb commit 5cac28a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
22 changes: 0 additions & 22 deletions base/unicode/utf16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,6 @@ function convert(::Type{UTF8String}, str::UTF16String)
return encode_to_utf8(UInt16, dat, len + num2byte + num3byte*2 + num4byte*3)
end

"
Converts a vector of `Char` to a `UTF16String`
### Returns:
* `::UTF16String`
### Throws:
* `UnicodeError`
"
function convert(::Type{UTF16String}, chrs::Vector{Char})
len = sizeof(chrs)
# handle zero length string quickly
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
# optimized path, no surrogates
num4byte == 0 && @inbounds return fast_utf_copy(UTF16String, UInt16, len, dat)
return encode_to_utf16(dat, len)
end

"
Converts an already validated UTF-32 encoded vector of `UInt32` to a `UTF16String`
Expand Down
20 changes: 0 additions & 20 deletions base/unicode/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,26 +238,6 @@ function convert(::Type{UTF8String}, a::Array{UInt8,1}, invalids_as::AbstractStr
end
convert(::Type{UTF8String}, s::AbstractString) = utf8(bytestring(s))

"
Converts a vector of `Char` to a `UTF8String`
### Returns:
* `UTF8String`
### Throws:
* `UnicodeError`
"
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))
return encode_to_utf8(UInt32, dat, len + num2byte + num3byte*2 + num4byte*3)
end

"
Converts an already validated vector of `UInt16` or `UInt32` to a `UTF8String`
Expand Down

0 comments on commit 5cac28a

Please sign in to comment.