Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed Jun 8, 2015
1 parent 2d23e4d commit 183074e
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions base/utf32.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ convert(::Type{UTF32String}, c::Char) = UTF32String(Char[c, Char(0)])
convert(::Type{UTF32String}, s::UTF32String) = s

"
Converts an AbstractString to a UTF16String
Converts an `AbstractString` to a `UTF16String`
### Input Arguments:
* ::Type{UTF32String}
* str::AbstractString
* `::Type{UTF32String}`
* `str::AbstractString`
### Returns:
* ::UTF32String
* `::UTF32String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF32String}, str::AbstractString)
len, flags = check_string(str)
Expand All @@ -34,17 +34,17 @@ function convert(::Type{UTF32String}, str::AbstractString)
end

"
Converts a UTF-32 encoded vector of UInt32 to a UTF8String
Converts a UTF-32 encoded vector of `UInt32` to a `UTF8String`
### Input Arguments:
* ::Type{UTF8String}
* dat::Vector{UInt32}
* `::Type{UTF8String}`
* `dat::Vector{UInt32}`
### Returns:
* ::UTF8String
* `::UTF8String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF8String}, dat::Vector{UInt32})
len = sizeof(dat)
Expand All @@ -57,17 +57,17 @@ function convert(::Type{UTF8String}, dat::Vector{UInt32})
end

"
Converts a UTF32String to a UTF8String
Converts a `UTF32String` to a `UTF8String`
### Input Arguments:
* ::Type{UTF8String}
* str::UTF32String
* `::Type{UTF8String}`
* `str::UTF32String`
### Returns:
* ::UTF8String
* `::UTF8String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF8String}, str::UTF32String)
dat = reinterpret(UInt32, str.data)
Expand All @@ -81,17 +81,17 @@ function convert(::Type{UTF8String}, str::UTF32String)
end

"
Converts a UTF8String to a UTF32String
Converts a `UTF8String` to a `UTF32String`
### Input Arguments:
* ::Type{UTF32String}
* str::UTF8String
* `::Type{UTF32String}`
* `str::UTF8String`
### Returns:
* ::UTF32String
* `::UTF32String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF32String}, str::UTF8String)
dat = str.data
Expand All @@ -100,11 +100,10 @@ function convert(::Type{UTF32String}, str::UTF8String)
# Validate UTF-8 encoding, and get number of words to create
len, flags = check_string(dat)
# Optimize case where no characters > 0x7f
totlen = len+1
flags == 0 && return fast_utf_copy(UTF32String, Char, totlen, dat)
flags == 0 && @inbounds return fast_utf_copy(UTF32String, Char, len, dat, true)
# has multi-byte UTF-8 sequences
buf = Vector{Char}(totlen)
@inbounds buf[totlen] = 0 # NULL termination
buf = Vector{Char}(len+1)
@inbounds buf[len+1] = 0 # NULL termination
local ch::UInt32, surr::UInt32
out = 0
pos = 0
Expand Down Expand Up @@ -140,17 +139,17 @@ function convert(::Type{UTF32String}, str::UTF8String)
end

"
Converts a UTF16String to UTF32String
Converts a `UTF16String` to `UTF32String`
### Input Arguments:
* ::Type{UTF32String}
* str::UTF16String
* `::Type{UTF32String}`
* `str::UTF16String`
### Returns:
* ::UTF32String
* `::UTF32String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF32String}, str::UTF16String)
dat = str.data
Expand All @@ -175,17 +174,17 @@ function convert(::Type{UTF32String}, str::UTF16String)
end

"
Converts a UTF-32 encoded vector of UInt32 to a UTF16String
Converts a UTF-32 encoded vector of `UInt32` to a `UTF16String`
### Input Arguments:
* ::Type{UTF16String}
* dat::Vector{UInt32}
* `::Type{UTF16String}`
* `dat::Vector{UInt32}`
### Returns:
* ::UTF16String
* `::UTF16String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF16String}, dat::Vector{UInt32})
len = sizeof(dat)
Expand All @@ -195,22 +194,22 @@ function convert(::Type{UTF16String}, dat::Vector{UInt32})
len, flags, num4byte = check_string(dat, len>>>2)
len += num4byte + 1
# optimized path, no surrogates
num4byte == 0 && return fast_utf_copy(UTF16String, UInt16, len, dat)
num4byte == 0 && @inbounds return fast_utf_copy(UTF16String, UInt16, len, dat)
return encode_to_utf16(dat, len)
end

"
Converts a UTF32String to UTF16String
Converts a `UTF32String` to `UTF16String`
### Input Arguments:
* ::Type{UTF16String}
* str::UTF32String
* `::Type{UTF16String}`
* `str::UTF32String`
### Returns:
* ::UTF16String
* `::UTF16String`
### Throws:
* UnicodeError
* `UnicodeError`
"
function convert(::Type{UTF16String}, str::UTF32String)
dat = reinterpret(UInt32, str.data)
Expand All @@ -225,14 +224,14 @@ function convert(::Type{UTF16String}, str::UTF32String)
end

"
Converts an already validated UTF-32 encoded vector of UInt32 to a UTF16String
Converts an already validated UTF-32 encoded vector of `UInt32` to a `UTF16String`
### Input Arguments:
* dat::Vector{UInt32} UTF-32 encoded data
* len length of output in 16-bit words
* `dat::Vector{UInt32}` UTF-32 encoded data
* `len` length of output in 16-bit words
### Returns:
* ::UTF16String
* `::UTF16String`
"
function encode_to_utf16(dat, len)
buf = Vector{UInt16}(len)
Expand All @@ -258,10 +257,12 @@ convert(::Type{UTF32String}, c::Char) = UTF32String(Char[c, Char(0)]

function convert(::Type{UTF32String}, str::ASCIIString)
dat = str.data
fast_utf_copy(UTF32String, Char, length(dat)+1, dat)
@inbounds return fast_utf_copy(UTF32String, Char, length(dat), dat, true)
end

convert(::Type{UTF32String}, dat::AbstractVector{Char}) = fast_utf_copy(UTF32String, Char, length(dat), dat, true)
function convert(::Type{UTF32String}, dat::AbstractVector{Char})
@inbounds return fast_utf_copy(UTF32String, Char, length(dat), dat, true)
end

function convert(::Type{UTF32String}, data::AbstractVector{Char})
len = length(data)
Expand Down

0 comments on commit 183074e

Please sign in to comment.