Skip to content

Commit

Permalink
add doc string for uppercase(::AbstractChar) and friends (JuliaLang…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias314 authored Mar 22, 2022
1 parent 7cde4be commit d3698a8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions base/strings/unicode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,64 @@ julia> textwidth("March")
"""
textwidth(s::AbstractString) = mapreduce(textwidth, +, s; init=0)

"""
lowercase(c::AbstractChar)
Convert `c` to lowercase.
See also [`uppercase`](@ref), [`titlecase`](@ref).
# Examples
```jldoctest
julia> lowercase('A')
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
julia> lowercase('Ö')
'ö': Unicode U+00F6 (category Ll: Letter, lowercase)
```
"""
lowercase(c::T) where {T<:AbstractChar} = isascii(c) ? ('A' <= c <= 'Z' ? c + 0x20 : c) :
T(ccall(:utf8proc_tolower, UInt32, (UInt32,), c))

"""
uppercase(c::AbstractChar)
Convert `c` to uppercase.
See also [`lowercase`](@ref), [`titlecase`](@ref).
# Examples
```jldoctest
julia> uppercase('a')
'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase)
julia> uppercase('ê')
'Ê': Unicode U+00CA (category Lu: Letter, uppercase)
```
"""
uppercase(c::T) where {T<:AbstractChar} = isascii(c) ? ('a' <= c <= 'z' ? c - 0x20 : c) :
T(ccall(:utf8proc_toupper, UInt32, (UInt32,), c))

"""
titlecase(c::AbstractChar)
Convert `c` to titlecase. This may differ from uppercase for digraphs,
compare the example below.
See also [`uppercase`](@ref), [`lowercase`](@ref).
# Examples
```jldoctest
julia> titlecase('a')
'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase)
julia> titlecase('dž')
'Dž': Unicode U+01C5 (category Lt: Letter, titlecase)
julia> uppercase('dž')
'DŽ': Unicode U+01C4 (category Lu: Letter, uppercase)
```
"""
titlecase(c::T) where {T<:AbstractChar} = isascii(c) ? ('a' <= c <= 'z' ? c - 0x20 : c) :
T(ccall(:utf8proc_totitle, UInt32, (UInt32,), c))

Expand Down

0 comments on commit d3698a8

Please sign in to comment.