Skip to content

Commit

Permalink
Rename isupper, islower, ucfirst and lcfirst (#26442)
Browse files Browse the repository at this point in the history
Spell "uppercase" and "lowercase" in full for consistency with uppercase and lowercase functions.
  • Loading branch information
nalimilan authored and JeffBezanson committed Mar 15, 2018
1 parent 5ad5c12 commit e050ab6
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 64 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,9 @@ Deprecated or removed
`show(IOContext(io, :compact => true), x...)` ([#26080]).
Use `sprint(show, x..., context=:compact => true)` instead of `sprint(showcompact, x...)`.

* `isupper`, `islower`, `ucfirst` and `lcfirst` have been deprecated in favor of `isuppercase`,
`islowercase`, `uppercasefirst` and `lowercasefirst`, respectively ([#26442]).

Command-line option changes
---------------------------

Expand Down Expand Up @@ -1411,3 +1414,4 @@ Command-line option changes
[#26262]: https://github.com/JuliaLang/julia/issues/26262
[#26284]: https://github.com/JuliaLang/julia/issues/26284
[#26286]: https://github.com/JuliaLang/julia/issues/26286
[#26442]: https://github.com/JuliaLang/julia/issues/26442
5 changes: 5 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,11 @@ end
@deprecate showcompact(io, x) show(IOContext(io, :compact => true), x)
@deprecate sprint(::typeof(showcompact), args...) sprint(show, args...; context=:compact => true)

@deprecate isupper isuppercase
@deprecate islower islowercase
@deprecate ucfirst uppercasefirst
@deprecate lcfirst lowercasefirst

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
8 changes: 4 additions & 4 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,15 @@ export
isascii,
iscntrl,
isdigit,
islower,
islowercase,
isnumeric,
isprint,
ispunct,
isspace,
isupper,
isuppercase,
isxdigit,
lcfirst,
lowercase,
lowercasefirst,
isvalid,
join,
lpad,
Expand All @@ -606,9 +606,9 @@ export
thisind,
titlecase,
transcode,
ucfirst,
unescape_string,
uppercase,
uppercasefirst,

# text output
IOContext,
Expand Down
2 changes: 1 addition & 1 deletion base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo
blk = ifblk.args[2]
push!(blk.args, :((len, pt, neg) = args))
push!(blk.args, :(exp = pt-1))
expmark = isupper(c) ? "E" : "e"
expmark = isuppercase(c) ? "E" : "e"
if precision==0 && '#' in flags
expmark = string(".",expmark)
end
Expand Down
4 changes: 2 additions & 2 deletions base/strings/strings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ include("strings/substring.jl")
include("strings/search.jl")
include("strings/unicode.jl")

import .Unicode: textwidth, islower, isupper, isalpha, isdigit, isnumeric, iscntrl, ispunct,
isspace, isprint, isxdigit, lowercase, uppercase, titlecase, lcfirst, ucfirst
import .Unicode: textwidth, islowercase, isuppercase, isalpha, isdigit, isnumeric, iscntrl, ispunct,
isspace, isprint, isxdigit, lowercase, uppercase, titlecase, lowercasefirst, uppercasefirst

include("strings/util.jl")
include("strings/io.jl")
38 changes: 19 additions & 19 deletions base/strings/unicode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,48 +268,48 @@ isassigned(c) = UTF8PROC_CATEGORY_CN < category_code(c) <= UTF8PROC_CATEGORY_CO
## libc character class predicates ##

"""
islower(c::AbstractChar) -> Bool
islowercase(c::AbstractChar) -> Bool
Tests whether a character is a lowercase letter.
A character is classified as lowercase if it belongs to Unicode category Ll,
Letter: Lowercase.
# Examples
```jldoctest
julia> islower('α')
julia> islowercase('α')
true
julia> islower('Γ')
julia> islowercase('Γ')
false
julia> islower('❤')
julia> islowercase('❤')
false
```
"""
islower(c::AbstractChar) = category_code(c) == UTF8PROC_CATEGORY_LL
islowercase(c::AbstractChar) = category_code(c) == UTF8PROC_CATEGORY_LL

# true for Unicode upper and mixed case

"""
isupper(c::AbstractChar) -> Bool
isuppercase(c::AbstractChar) -> Bool
Tests whether a character is an uppercase letter.
A character is classified as uppercase if it belongs to Unicode category Lu,
Letter: Uppercase, or Lt, Letter: Titlecase.
# Examples
```jldoctest
julia> isupper('γ')
julia> isuppercase('γ')
false
julia> isupper('Γ')
julia> isuppercase('Γ')
true
julia> isupper('❤')
julia> isuppercase('❤')
false
```
"""
function isupper(c::AbstractChar)
function isuppercase(c::AbstractChar)
cat = category_code(c)
cat == UTF8PROC_CATEGORY_LU || cat == UTF8PROC_CATEGORY_LT
end
Expand Down Expand Up @@ -533,7 +533,7 @@ converted to lowercase, otherwise they are left unchanged.
By default, all non-letters are considered as word separators;
a predicate can be passed as the `wordsep` keyword to determine
which characters should be considered as word separators.
See also [`ucfirst`](@ref) to capitalize only the first
See also [`uppercasefirst`](@ref) to capitalize only the first
character in `s`.
# Examples
Expand Down Expand Up @@ -564,22 +564,22 @@ function titlecase(s::AbstractString; wordsep::Function = !iscased, strict::Bool
end

"""
ucfirst(s::AbstractString) -> String
uppercasefirst(s::AbstractString) -> String
Return `s` with the first character converted to uppercase (technically "title
case" for Unicode). See also [`titlecase`](@ref) to capitalize the first
character of every word in `s`.
See also: [`lcfirst`](@ref), [`uppercase`](@ref), [`lowercase`](@ref),
See also: [`lowercasefirst`](@ref), [`uppercase`](@ref), [`lowercase`](@ref),
[`titlecase`](@ref)
# Examples
```jldoctest
julia> ucfirst("python")
julia> uppercasefirst("python")
"Python"
```
"""
function ucfirst(s::AbstractString)
function uppercasefirst(s::AbstractString)
isempty(s) && return ""
c = s[1]
c′ = titlecase(c)
Expand All @@ -588,20 +588,20 @@ function ucfirst(s::AbstractString)
end

"""
lcfirst(s::AbstractString)
lowercasefirst(s::AbstractString)
Return `s` with the first character converted to lowercase.
See also: [`ucfirst`](@ref), [`uppercase`](@ref), [`lowercase`](@ref),
See also: [`uppercasefirst`](@ref), [`uppercase`](@ref), [`lowercase`](@ref),
[`titlecase`](@ref)
# Examples
```jldoctest
julia> lcfirst("Julia")
julia> lowercasefirst("Julia")
"julia"
```
"""
function lcfirst(s::AbstractString)
function lowercasefirst(s::AbstractString)
isempty(s) && return ""
c = s[1]
c′ = lowercase(c)
Expand Down
8 changes: 4 additions & 4 deletions doc/src/base/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ Base.last(::AbstractString, ::Integer)
Base.uppercase
Base.lowercase
Base.titlecase
Base.ucfirst
Base.lcfirst
Base.uppercasefirst
Base.lowercasefirst
Base.join
Base.chop
Base.chomp
Expand All @@ -66,12 +66,12 @@ Base.isalpha
Base.isascii
Base.iscntrl
Base.isdigit
Base.islower
Base.islowercase
Base.isnumeric
Base.isprint
Base.ispunct
Base.isspace
Base.isupper
Base.isuppercase
Base.isxdigit
Core.Symbol
Base.escape_string
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/Common/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function admonition(stream::IO, block::MD)
if contains(line, untitled)
m = match(untitled, line)
# When no title is provided we use CATEGORY_NAME, capitalising it.
m.captures[1], ucfirst(m.captures[1])
m.captures[1], uppercasefirst(m.captures[1])
elseif contains(line, titled)
m = match(titled, line)
# To have a blank TITLE provide an explicit empty string as TITLE.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/render/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ end

function plain(io::IO, md::Admonition)
s = sprint(plain, md.content)
title = md.title == ucfirst(md.category) ? "" : " \"$(md.title)\""
title = md.title == uppercasefirst(md.category) ? "" : " \"$(md.title)\""
println(io, "!!! ", md.category, title)
for line in split(rstrip(s), "\n")
println(io, isempty(line) ? "" : " ", line)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/render/rst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end

function rst(io::IO, md::Admonition)
s = sprint(rst, md.content)
title = md.title == ucfirst(md.category) ? "" : md.title
title = md.title == uppercasefirst(md.category) ? "" : md.title
println(io, ".. ", md.category, "::", isempty(title) ? "" : " $title")
for line in split(rstrip(s), "\n")
println(io, isempty(line) ? "" : " ", line)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ function edit_lower_case(s)
end
function edit_title_case(s)
set_action!(s, :edit_title_case)
edit_replace_word_right(s, ucfirst)
edit_replace_word_right(s, uppercasefirst)
end

function edit_replace_word_right(s, replace::Function)
Expand Down
56 changes: 28 additions & 28 deletions stdlib/Unicode/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ end
alower=['a', 'd', 'j', 'y', 'z']
ulower=['α', 'β', 'γ', 'δ', 'ф', 'я']
for c in vcat(alower,ulower)
@test islower(c) == true
@test isupper(c) == false
@test islowercase(c) == true
@test isuppercase(c) == false
@test isdigit(c) == false
@test isnumeric(c) == false
end
Expand All @@ -103,8 +103,8 @@ end
uupper= ['Δ', 'Γ', 'Π', 'Ψ', 'Dž', 'Ж', 'Д']

for c in vcat(aupper,uupper)
@test islower(c) == false
@test isupper(c) == true
@test islowercase(c) == false
@test isuppercase(c) == true
@test isdigit(c) == false
@test isnumeric(c) == false
end
Expand Down Expand Up @@ -201,8 +201,8 @@ end
@test !all(isspace,"ΣβΣβ")
@test all(isalpha,"ΣβΣβ")
@test all(isprint,"ΣβΣβ")
@test !all(isupper,"ΣβΣβ")
@test !all(islower,"ΣβΣβ")
@test !all(isuppercase,"ΣβΣβ")
@test !all(islowercase,"ΣβΣβ")
@test !all(isnumeric,"ΣβΣβ")
@test !all(iscntrl,"ΣβΣβ")
@test !all(ispunct,"ΣβΣβ")
Expand Down Expand Up @@ -329,17 +329,17 @@ end
@test collect(g) == ["1","2","3","α","5"]
end

@testset "ucfirst/lcfirst" begin
@test ucfirst("Hola")=="Hola"
@test ucfirst("hola")=="Hola"
@test ucfirst("")==""
@test ucfirst("*")=="*"
@test ucfirst("DŽxx") == ucfirst("džxx") == "Džxx"

@test lcfirst("Hola")=="hola"
@test lcfirst("hola")=="hola"
@test lcfirst("")==""
@test lcfirst("*")=="*"
@testset "uppercasefirst/lowercasefirst" begin
@test uppercasefirst("Hola")=="Hola"
@test uppercasefirst("hola")=="Hola"
@test uppercasefirst("")==""
@test uppercasefirst("*")=="*"
@test uppercasefirst("DŽxx") == uppercasefirst("džxx") == "Džxx"

@test lowercasefirst("Hola")=="hola"
@test lowercasefirst("hola")=="hola"
@test lowercasefirst("")==""
@test lowercasefirst("*")=="*"
end

@testset "issue #11482" begin
Expand All @@ -355,17 +355,17 @@ end
@test lowercase('\U118bf') == '\U118df'
@test uppercase('\U1044d') == '\U10425'
end
@testset "ucfirst/lcfirst" begin
@test ucfirst("Abc") == "Abc"
@test ucfirst("abc") == "Abc"
@test lcfirst("ABC") == "aBC"
@test lcfirst("aBC") == "aBC"
@test ucfirst(GenericString("")) == ""
@test lcfirst(GenericString("")) == ""
@test ucfirst(GenericString("a")) == "A"
@test lcfirst(GenericString("A")) == "a"
@test lcfirst(GenericString("a")) == "a"
@test ucfirst(GenericString("A")) == "A"
@testset "uppercasefirst/lowercasefirst" begin
@test uppercasefirst("Abc") == "Abc"
@test uppercasefirst("abc") == "Abc"
@test lowercasefirst("ABC") == "aBC"
@test lowercasefirst("aBC") == "aBC"
@test uppercasefirst(GenericString("")) == ""
@test lowercasefirst(GenericString("")) == ""
@test uppercasefirst(GenericString("a")) == "A"
@test lowercasefirst(GenericString("A")) == "a"
@test lowercasefirst(GenericString("a")) == "a"
@test uppercasefirst(GenericString("A")) == "A"
end
@testset "titlecase" begin
@test titlecase('lj') == 'Lj'
Expand Down
4 changes: 2 additions & 2 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Base.promote_rule(::Type{T19714}, ::Type{Int}) = T19714
end
@testset "function negation" begin
str = randstring(20)
@test filter(!isupper, str) == replace(str, r"[A-Z]" => "")
@test filter(!islower, str) == replace(str, r"[a-z]" => "")
@test filter(!isuppercase, str) == replace(str, r"[A-Z]" => "")
@test filter(!islowercase, str) == replace(str, r"[a-z]" => "")
end

# issue #19891
Expand Down

0 comments on commit e050ab6

Please sign in to comment.