From 183074eadfecb681bceccab015c618091e14ce32 Mon Sep 17 00:00:00 2001 From: ScottPJones Date: Mon, 8 Jun 2015 21:37:56 +0200 Subject: [PATCH] Update comments --- base/utf32.jl | 93 ++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/base/utf32.jl b/base/utf32.jl index 4844a11c886122..a3d3f7cee30904 100644 --- a/base/utf32.jl +++ b/base/utf32.jl @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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)