diff --git a/HISTORY.md b/HISTORY.md index 9edaa38af09a2..5ba6f47127cfc 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -516,7 +516,7 @@ Deprecated or removed [#18558], [#19711], [#19712], [#19791], [#19802], [#19931], [#20543], [#20228]). * All methods of character predicates (`isalnum`, `isalpha`, `iscntrl`, `isdigit`, - `isnumber`, `isgraph`, `islower`, `isprint`, `ispunct`, `isspace`, `isupper`, + `isnumber`, `isgraph`, `islowercase`, `isprint`, `ispunct`, `isspace`, `isuppercase`, `isxdigit`) that accept `AbstractStrings` have been deprecated in favor of `all`. For example, `isnumber("123")` should now be expressed `all(isnumber, "123")` ([#20342]). @@ -1369,7 +1369,7 @@ Library improvements * `graphemes(s)` returns an iterator over grapheme substrings of `s` ([#9261]). - * Character predicates such as `islower()`, `isspace()`, etc. use + * Character predicates such as `islowercase()`, `isspace()`, etc. use utf8proc to provide uniform cross-platform behavior and up-to-date, locale-independent support for Unicode standards ([#5939]). diff --git a/NEWS.md b/NEWS.md index 93c4882f4f351..5b8d0f515112e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1099,6 +1099,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 --------------------------- @@ -1396,4 +1399,5 @@ Command-line option changes [#26009]: https://github.com/JuliaLang/julia/issues/26009 [#26071]: https://github.com/JuliaLang/julia/issues/26071 [#26080]: https://github.com/JuliaLang/julia/issues/26080 -[#26149]: https://github.com/JuliaLang/julia/issues/26149 \ No newline at end of file +[#26149]: https://github.com/JuliaLang/julia/issues/26149 +[#26442]: https://github.com/JuliaLang/julia/issues/26442 \ No newline at end of file diff --git a/base/deprecated.jl b/base/deprecated.jl index e0154169efd79..e73decb5d86bf 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1518,6 +1518,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 diff --git a/base/exports.jl b/base/exports.jl index 25cd630665e61..05e1bbe302fa5 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -574,15 +574,15 @@ export isascii, iscntrl, isdigit, - islower, + islowercase, isnumeric, isprint, ispunct, isspace, - isupper, + isuppercase, isxdigit, - lcfirst, lowercase, + lowercasefirst, isvalid, join, lpad, @@ -606,9 +606,9 @@ export thisind, titlecase, transcode, - ucfirst, unescape_string, uppercase, + uppercasefirst, # text output IOContext, diff --git a/base/printf.jl b/base/printf.jl index 96078bb9d1a24..3816eaf2794d6 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -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 diff --git a/base/strings/strings.jl b/base/strings/strings.jl index 326fd0f2e2a2a..2abcc984b7ebc 100644 --- a/base/strings/strings.jl +++ b/base/strings/strings.jl @@ -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") diff --git a/base/strings/unicode.jl b/base/strings/unicode.jl index 61d5aa7b6e074..a2f40494d6904 100644 --- a/base/strings/unicode.jl +++ b/base/strings/unicode.jl @@ -268,7 +268,7 @@ 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, @@ -276,22 +276,22 @@ 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, @@ -299,17 +299,17 @@ 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 @@ -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 @@ -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) @@ -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) diff --git a/doc/src/base/strings.md b/doc/src/base/strings.md index 816f607e915c6..35c3405bd7de2 100644 --- a/doc/src/base/strings.md +++ b/doc/src/base/strings.md @@ -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 @@ -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 diff --git a/stdlib/Markdown/src/Common/block.jl b/stdlib/Markdown/src/Common/block.jl index fd6c9de93d1ac..06b97b6359048 100644 --- a/stdlib/Markdown/src/Common/block.jl +++ b/stdlib/Markdown/src/Common/block.jl @@ -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. diff --git a/stdlib/Markdown/src/render/plain.jl b/stdlib/Markdown/src/render/plain.jl index dbee4dcf33fa6..ff0c356b56b44 100644 --- a/stdlib/Markdown/src/render/plain.jl +++ b/stdlib/Markdown/src/render/plain.jl @@ -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) diff --git a/stdlib/Markdown/src/render/rst.jl b/stdlib/Markdown/src/render/rst.jl index 737cf316c8851..0ec17bf407265 100644 --- a/stdlib/Markdown/src/render/rst.jl +++ b/stdlib/Markdown/src/render/rst.jl @@ -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) diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl index 3a52459da4d93..1b25f376aee70 100644 --- a/stdlib/REPL/src/LineEdit.jl +++ b/stdlib/REPL/src/LineEdit.jl @@ -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) diff --git a/stdlib/Unicode/test/runtests.jl b/stdlib/Unicode/test/runtests.jl index ccdb4edb393a8..7f902bfa7506c 100644 --- a/stdlib/Unicode/test/runtests.jl +++ b/stdlib/Unicode/test/runtests.jl @@ -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 @@ -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 @@ -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,"ΣβΣβ") @@ -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 @@ -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' diff --git a/test/operators.jl b/test/operators.jl index 7cf493296e00b..ea6db5cac49f1 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -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