Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed Jul 10, 2015
1 parent e17ecf4 commit 9dce7f5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 58 deletions.
8 changes: 4 additions & 4 deletions base/unicode/checkstring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const UTF_SURROGATE = 32 ##< surrogate pairs present
(ch << 6) | (byt & 0x3f)
end

"
"""
Validates and calculates number of characters in a UTF-8,UTF-16 or UTF-32 encoded vector/string
Warning: this function does not check the bounds of the start or end positions
Expand All @@ -46,7 +46,7 @@ Use `checkstring` to make sure the bounds are checked
### Throws:
* `UnicodeError`
"
"""
function unsafe_checkstring end

function unsafe_checkstring(dat::Vector{UInt8},
Expand Down Expand Up @@ -191,7 +191,7 @@ function unsafe_checkstring{T <: Union{Vector{UInt16}, Vector{UInt32}, AbstractS
return totalchar, flags, num4byte, num3byte, num2byte
end

"
"""
Validates and calculates number of characters in a UTF-8,UTF-16 or UTF-32 encoded vector/string
This function checks the bounds of the start and end positions
Expand All @@ -214,7 +214,7 @@ Use `unsafe_checkstring` to avoid that overhead if the bounds have already been
### Throws:
* `UnicodeError`
"
"""
function checkstring end

# No need to check bounds if using defaults
Expand Down
20 changes: 10 additions & 10 deletions base/unicode/utf16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ function isvalid(::Type{UTF16String}, data::AbstractArray{UInt16})
return i > n || !is_surrogate_codeunit(data[i])
end

"
"""
Converts an `AbstractString` to a `UTF16String`
### Returns:
* `UTF16String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF16String}, str::AbstractString)
len, flags, num4byte = unsafe_checkstring(str)
buf = Vector{UInt16}(len+num4byte+1)
Expand All @@ -128,15 +128,15 @@ function convert(::Type{UTF16String}, str::AbstractString)
UTF16String(buf)
end

"
"""
Converts a `UTF8String` to a `UTF16String`
### Returns:
* `UTF16String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF16String}, str::UTF8String)
dat = str.data
# handle zero length string quickly
Expand Down Expand Up @@ -174,15 +174,15 @@ function convert(::Type{UTF16String}, str::UTF8String)
UTF16String(buf)
end

"
"""
Converts a `UTF16String` to a `UTF8String`
### Returns:
* `UTF8String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF8String}, str::UTF16String)
dat = str.data
len = sizeof(dat) >>> 1
Expand All @@ -194,15 +194,15 @@ 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
Expand All @@ -216,7 +216,7 @@ function convert(::Type{UTF16String}, chrs::Vector{Char})
return encode_to_utf16(dat, len)
end

"
"""
Converts an already validated UTF-32 encoded vector of `UInt32` to a `UTF16String`
### Input Arguments:
Expand All @@ -225,7 +225,7 @@ Converts an already validated UTF-32 encoded vector of `UInt32` to a `UTF16Strin
### Returns:
* `::UTF16String`
"
"""
function encode_to_utf16(dat, len)
buf = Vector{UInt16}(len)
@inbounds buf[len] = 0 # NULL termination
Expand Down
20 changes: 10 additions & 10 deletions base/unicode/utf32.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ utf32(x) = convert(UTF32String, x)
convert(::Type{UTF32String}, c::Char) = UTF32String(Char[c, Char(0)])
convert(::Type{UTF32String}, s::UTF32String) = s

"
"""
Converts an `AbstractString` to a `UTF32String`
### Returns:
* `UTF32String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF32String}, str::AbstractString)
len, flags = unsafe_checkstring(str)
buf = Vector{Char}(len+1)
Expand All @@ -33,15 +33,15 @@ function convert(::Type{UTF32String}, str::AbstractString)
UTF32String(buf)
end

"
"""
Converts a `UTF32String` to a `UTF8String`
### Returns:
* `UTF8String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF8String}, str::UTF32String)
dat = reinterpret(UInt32, str.data)
len = sizeof(dat) >>> 2
Expand All @@ -53,15 +53,15 @@ function convert(::Type{UTF8String}, str::UTF32String)
return encode_to_utf8(UInt32, dat, len + num2byte + num3byte*2 + num4byte*3)
end

"
"""
Converts a `UTF8String` to a `UTF32String`
### Returns:
* `::UTF32String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF32String}, str::UTF8String)
dat = str.data
# handle zero length string quickly
Expand Down Expand Up @@ -107,15 +107,15 @@ function convert(::Type{UTF32String}, str::UTF8String)
UTF32String(buf)
end

"
"""
Converts a `UTF16String` to `UTF32String`
### Returns:
* `::UTF32String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF32String}, str::UTF16String)
dat = str.data
len = sizeof(dat)
Expand All @@ -138,15 +138,15 @@ function convert(::Type{UTF32String}, str::UTF16String)
UTF32String(buf)
end

"
"""
Converts a `UTF32String` to `UTF16String`
### Returns:
* `::UTF16String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF16String}, str::UTF32String)
dat = reinterpret(UInt32, str.data)
len = sizeof(dat)
Expand Down
12 changes: 6 additions & 6 deletions base/unicode/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ utf8(x) = convert(UTF8String, x)
convert(::Type{UTF8String}, s::UTF8String) = s
convert(::Type{UTF8String}, s::ASCIIString) = UTF8String(s.data)

"
"""
Converts a UTF-8 encoded vector of `UInt8` to a `UTF8String`
### Returns:
* `UTF8String`
### Throws:
* `UnicodeError`
"
"""
function convert(::Type{UTF8String}, dat::Vector{UInt8})
# handle zero length string quickly
isempty(dat) && return empty_utf8
Expand Down Expand Up @@ -302,15 +302,15 @@ function convert(::Type{UTF8String}, a::Vector{UInt8}, invalids_as::AbstractStri
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
Expand All @@ -322,7 +322,7 @@ function convert(::Type{UTF8String}, chrs::Vector{Char})
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`
### Input Arguments:
Expand All @@ -331,7 +331,7 @@ Converts an already validated vector of `UInt16` or `UInt32` to a `UTF8String`
### Returns:
* `UTF8String`
"
"""
function encode_to_utf8{T<:Union{UInt16, UInt32}}(::Type{T}, dat, len)
buf = Vector{UInt8}(len)
out = 0
Expand Down
Loading

0 comments on commit 9dce7f5

Please sign in to comment.