Skip to content

Commit

Permalink
move case functions and char predicates back to Base (#25479)
Browse files Browse the repository at this point in the history
fixes #25394
  • Loading branch information
JeffBezanson authored Jan 13, 2018
1 parent 4a50e64 commit c5cd13e
Show file tree
Hide file tree
Showing 55 changed files with 120 additions and 223 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ The steps required to add a new docstring are listed below:
Examples written within docstrings can be used as testcases known as "doctests" by annotating code blocks with `jldoctest`.

```jldoctest
julia> Unicode.uppercase("Docstring test")
julia> uppercase("Docstring test")
"DOCSTRING TEST"
```

Expand Down
14 changes: 5 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,11 @@ Deprecated or removed
* The `sum_kbn` and `cumsum_kbn` functions have been moved to the
[KahanSummation](https://github.com/JuliaMath/KahanSummation.jl) package ([#24869]).

* Unicode-related string functions have been moved to the new `Unicode` standard
library module ([#25021]). This applies to `normalize_string`, `graphemes`,
`is_assigned_char`, `textwidth`, `islower`, `isupper`, `isalpha`,
`isdigit`, `isxdigit`, `isnumber`, `isalnum`, `iscntrl`, `ispunct`, `isspace`,
`isprint`, `isgraph`, `lowercase`, `uppercase`, `titlecase`, `lcfirst` and `ucfirst`.
* `isnumber` has been renamed to `isnumeric` ([#25021]).

* `is_assigned_char` and `normalize_string` have been renamed to `isassigned` and
`normalize`, and moved to the new `Unicode` standard library module.
`graphemes` has also been moved to that module ([#25021]).

* The functions `eigs` and `svds` have been moved to the `IterativeEigensolvers` standard
library module ([#24714]).
Expand All @@ -887,10 +887,6 @@ Deprecated or removed

* `@printf` and `@sprintf` have been moved to the `Printf` standard library ([#23929],[#25056]).

* `isnumber` has been deprecated in favor of `isnumeric`, `is_assigned_char`
in favor of `isassigned` and `normalize_string` in favor of `normalize`, all three
in the new `Unicode` standard library module ([#25021]).

* The aliases `Complex32`, `Complex64` and `Complex128` have been deprecated in favor of `ComplexF16`,
`ComplexF32` and `ComplexF64` respectively ([#24647]).

Expand Down
2 changes: 1 addition & 1 deletion base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat,
screenwidth -= length(pre) + length(post)
presp = repeat(" ", length(pre)) # indent each row to match pre string
postsp = ""
@assert Unicode.textwidth(hdots) == Unicode.textwidth(ddots)
@assert textwidth(hdots) == textwidth(ddots)
sepsize = length(sep)
rowsA, colsA = axes(X,1), axes(X,2)
m, n = length(rowsA), length(colsA)
Expand Down
2 changes: 1 addition & 1 deletion base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function show(io::IO, c::Char)
(u <<= 8) == 0 && break
end
write(io, 0x27)
elseif Unicode.isprint(c)
elseif isprint(c)
write(io, 0x27, c, 0x27)
else # unprintable, well-formed, non-overlong Unicode
u = UInt32(c)
Expand Down
21 changes: 4 additions & 17 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2614,23 +2614,10 @@ end
@deprecate_moved normalize_string "Unicode" true true
@deprecate_moved graphemes "Unicode" true true
@deprecate_moved is_assigned_char "Unicode" true true
@deprecate_moved textwidth "Unicode" true true
@deprecate_moved islower "Unicode" true true
@deprecate_moved isupper "Unicode" true true
@deprecate_moved isalpha "Unicode" true true
@deprecate_moved isdigit "Unicode" true true
@deprecate_moved isnumber "Unicode" true true
@deprecate_moved isalnum "Unicode" true true
@deprecate_moved iscntrl "Unicode" true true
@deprecate_moved ispunct "Unicode" true true
@deprecate_moved isspace "Unicode" true true
@deprecate_moved isprint "Unicode" true true
@deprecate_moved isgraph "Unicode" true true
@deprecate_moved lowercase "Unicode" true true
@deprecate_moved uppercase "Unicode" true true
@deprecate_moved titlecase "Unicode" true true
@deprecate_moved lcfirst "Unicode" true true
@deprecate_moved ucfirst "Unicode" true true

@deprecate isalnum(c::Char) isalpha(c) || isnumeric(c)
@deprecate isgraph(c::Char) isprint(c) && !isspace(c)
@deprecate isnumber(c::Char) isnumeric(c)

# PR #24647
@deprecate_binding Complex32 ComplexF16
Expand Down
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

function _truncate_at_width_or_chars(str, width, chars="", truncmark="")
truncwidth = Unicode.textwidth(truncmark)
truncwidth = textwidth(truncmark)
(width <= 0 || width < truncwidth) && return ""

wid = truncidx = lastidx = 0
idx = start(str)
while !done(str, idx)
lastidx = idx
c, idx = next(str, idx)
wid += Unicode.textwidth(c)
wid += textwidth(c)
wid >= width - truncwidth && truncidx == 0 && (truncidx = lastidx)
(wid >= width || c in chars) && break
end
Expand Down
5 changes: 2 additions & 3 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Text / HTML objects

import Base: print, show, ==, hash
using Base.Unicode

export HTML, @html_str

Expand Down Expand Up @@ -222,8 +221,8 @@ function matchinds(needle, haystack; acronym = false)
for (i, char) in enumerate(haystack)
isempty(chars) && break
while chars[1] == ' ' popfirst!(chars) end # skip spaces
if Unicode.lowercase(char) == Unicode.lowercase(chars[1]) &&
(!acronym || !Unicode.isalpha(lastc))
if lowercase(char) == lowercase(chars[1]) &&
(!acronym || !isalpha(lastc))
push!(is, i)
popfirst!(chars)
end
Expand Down
16 changes: 16 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,19 @@ export
hex2bytes,
hex2bytes!,
info,
isalpha,
isascii,
iscntrl,
isdigit,
islower,
isnumeric,
isprint,
ispunct,
isspace,
isupper,
isxdigit,
lcfirst,
lowercase,
isvalid,
join,
logging,
Expand Down Expand Up @@ -728,9 +740,13 @@ export
string,
strip,
summary,
textwidth,
thisind,
titlecase,
transcode,
ucfirst,
unescape_string,
uppercase,
warn,

# logging frontend
Expand Down
2 changes: 1 addition & 1 deletion base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function edit(path::AbstractString, line::Integer=0)
cmd = line != 0 ? `$command $path -l $line` : `$command $path`
elseif startswith(name, "subl") || startswith(name, "atom")
cmd = line != 0 ? `$command $path:$line` : `$command $path`
elseif name == "code" || (Sys.iswindows() && Unicode.uppercase(name) == "CODE.EXE")
elseif name == "code" || (Sys.iswindows() && uppercase(name) == "CODE.EXE")
cmd = line != 0 ? `$command -g $path:$line` : `$command -g $path`
elseif startswith(name, "notepad++")
cmd = line != 0 ? `$command $path -n$line` : `$command $path`
Expand Down
2 changes: 0 additions & 2 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,6 @@ characters from that character until the start of the next line are ignored.
julia> buf = IOBuffer(" text")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=8, maxsize=Inf, ptr=1, mark=-1)
julia> using Unicode
julia> skipchars(buf, isspace)
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=8, maxsize=Inf, ptr=5, mark=-1)
Expand Down
4 changes: 2 additions & 2 deletions base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function uv_sizeof_req(req)
end

for h in uv_handle_types
@eval const $(Symbol("_sizeof_",Unicode.lowercase(string(h)))) = uv_sizeof_handle($h)
@eval const $(Symbol("_sizeof_",lowercase(string(h)))) = uv_sizeof_handle($h)
end
for r in uv_req_types
@eval const $(Symbol("_sizeof_",Unicode.lowercase(string(r)))) = uv_sizeof_req($r)
@eval const $(Symbol("_sizeof_",lowercase(string(r)))) = uv_sizeof_req($r)
end

uv_handle_data(handle) = ccall(:jl_uv_handle_data,Ptr{Cvoid},(Ptr{Cvoid},),handle)
Expand Down
1 change: 0 additions & 1 deletion base/markdown/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Markdown

import Base: show, ==, with_output_color
import Core: @doc_str
using Base.Unicode: lowercase, ucfirst, isspace

include(joinpath("parse", "config.jl"))
include(joinpath("parse", "util.jl"))
Expand Down
2 changes: 1 addition & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ BigFloat(x::Union{Float16,Float32}) = BigFloat(Float64(x))
BigFloat(x::Rational) = BigFloat(numerator(x)) / BigFloat(denominator(x))

function tryparse(::Type{BigFloat}, s::AbstractString, base::Int=0)
!isempty(s) && Base.Unicode.isspace(s[end]) && return tryparse(BigFloat, rstrip(s), base)
!isempty(s) && isspace(s[end]) && return tryparse(BigFloat, rstrip(s), base)
z = BigFloat()
err = ccall((:mpfr_set_str, :libmpfr), Int32, (Ref{BigFloat}, Cstring, Int32, Int32), z, s, base, ROUNDING_MODE[])
err == 0 ? z : nothing
Expand Down
2 changes: 0 additions & 2 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,6 @@ entered in the Julia REPL (and most editors, appropriately configured) by typing
# Examples
```jldoctest
julia> using Unicode
julia> map(uppercase∘hex, 250:255)
6-element Array{String,1}:
"FA"
Expand Down
18 changes: 9 additions & 9 deletions base/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
function parseint_preamble(signed::Bool, base::Int, s::AbstractString, startpos::Int, endpos::Int)
c, i, j = parseint_next(s, startpos, endpos)

while Unicode.isspace(c)
while isspace(c)
c, i, j = parseint_next(s,i,endpos)
end
(j == 0) && (return 0, 0, 0)
Expand All @@ -66,7 +66,7 @@ function parseint_preamble(signed::Bool, base::Int, s::AbstractString, startpos:
end
end

while Unicode.isspace(c)
while isspace(c)
c, i, j = parseint_next(s,i,endpos)
end
(j == 0) && (return 0, 0, 0)
Expand Down Expand Up @@ -124,10 +124,10 @@ function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::
return n
end
c, i = next(s,i)
Unicode.isspace(c) && break
isspace(c) && break
end
(T <: Signed) && (n *= sgn)
while !Unicode.isspace(c)
while !isspace(c)
d::T = '0' <= c <= '9' ? c-'0' :
'A' <= c <= 'Z' ? c-'A'+10 :
'a' <= c <= 'z' ? c-'a'+a : base
Expand All @@ -148,7 +148,7 @@ function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::
end
while i <= endpos
c, i = next(s,i)
if !Unicode.isspace(c)
if !isspace(c)
raise && throw(ArgumentError("extra characters after whitespace in $(repr(SubString(s,startpos,endpos)))"))
return nothing
end
Expand All @@ -167,10 +167,10 @@ function tryparse_internal(::Type{Bool}, sbuff::Union{String,SubString{String}},
orig_end = endpos

# Ignore leading and trailing whitespace
while Unicode.isspace(sbuff[startpos]) && startpos <= endpos
while isspace(sbuff[startpos]) && startpos <= endpos
startpos = nextind(sbuff, startpos)
end
while Unicode.isspace(sbuff[endpos]) && endpos >= startpos
while isspace(sbuff[endpos]) && endpos >= startpos
endpos = prevind(sbuff, endpos)
end

Expand All @@ -185,7 +185,7 @@ function tryparse_internal(::Type{Bool}, sbuff::Union{String,SubString{String}},

if raise
substr = SubString(sbuff, orig_start, orig_end) # show input string in the error to avoid confusion
if all(Unicode.isspace, substr)
if all(isspace, substr)
throw(ArgumentError("input string only contains whitespace"))
else
throw(ArgumentError("invalid Bool representation: $(repr(substr))"))
Expand Down Expand Up @@ -272,7 +272,7 @@ tryparse_internal(::Type{Float16}, s::AbstractString, startpos::Int, endpos::Int

function tryparse_internal(::Type{Complex{T}}, s::Union{String,SubString{String}}, i::Int, e::Int, raise::Bool) where {T<:Real}
# skip initial whitespace
while i e && Unicode.isspace(s[i])
while i e && isspace(s[i])
i = nextind(s, i)
end
if i > e
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function available()
for (pkg, vers) in all_avail
any(x->Types.satisfies("julia", VERSION, x[2].requires), vers) && push!(avail, pkg)
end
sort!(avail, by=Base.Unicode.lowercase)
sort!(avail, by=lowercase)
end

function available(pkg::AbstractString)
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/reqs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function write(io::IO, lines::Vector{Line})
end
end
function write(io::IO, reqs::Requires)
for pkg in sort!(collect(keys(reqs)), by=Unicode.lowercase)
for pkg in sort!(collect(keys(reqs)), by=lowercase)
println(io, Requirement(pkg, reqs[pkg]).content)
end
end
Expand Down
3 changes: 0 additions & 3 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ precompile(Tuple{typeof(Base.lstrip), Base.SubString{String}, Array{Char, 1}})
precompile(Tuple{getfield(Base, Symbol("#kw##split")), Array{Any, 1}, typeof(Base.split), String, Char})
precompile(Tuple{getfield(Base, Symbol("#kw##split")), Array{Any, 1}, typeof(Base.split), Base.SubString{String}, Char})
precompile(Tuple{typeof(Base.map!), typeof(Base.strip), Array{Base.SubString{String}, 1}, Array{Base.SubString{String}, 1}})
precompile(Tuple{typeof(Base.Unicode.isnumeric), Base.SubString{String}})
precompile(Tuple{Type{Core.Inference.Generator{I, F} where F where I}, Type{Core.Inference.Const}, Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}})
precompile(Tuple{Type{Core.Inference.Generator{Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}, Type{Core.Inference.Const}}}, Type{Core.Inference.Const}, Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}})
precompile(Tuple{typeof(Core.Inference.convert), Type{Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}}, Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}})
Expand Down Expand Up @@ -745,7 +744,6 @@ precompile(Tuple{Type{Base.Generator{I, F} where F where I}, typeof(Base.string)
precompile(Tuple{typeof(Base._collect), Array{Any, 1}, Base.Generator{Array{Any, 1}, typeof(Base.string)}, Base.EltypeUnknown, Base.HasShape})
precompile(Tuple{typeof(Base.similar), Array{Any, 1}, Type{String}, Tuple{Base.OneTo{Int64}}})
precompile(Tuple{typeof(Base.collect_to!), Array{String, 1}, Base.Generator{Array{Any, 1}, typeof(Base.string)}, Int64, Int64})
precompile(Tuple{typeof(Base.Unicode.isalpha), Char})
precompile(Tuple{getfield(Base.Docs, Symbol("#kw##matchinds")), Array{Any, 1}, typeof(Base.Docs.matchinds), String, String})
precompile(Tuple{typeof(Base.Docs.bestmatch), String, String})
precompile(Tuple{typeof(Base.length), Tuple{DataType, DataType}})
Expand Down Expand Up @@ -908,7 +906,6 @@ precompile(Tuple{typeof(Base.lstrip), String, Char})
precompile(Tuple{typeof(Base.Markdown.blockquote), Base.GenericIOBuffer{Array{UInt8, 1}}, Base.Markdown.MD})
precompile(Tuple{getfield(Base.Markdown, Symbol("#kw##parse")), Array{Any, 1}, typeof(Base.Markdown.parse), String})
precompile(Tuple{typeof(Base.Markdown.admonition), Base.GenericIOBuffer{Array{UInt8, 1}}, Base.Markdown.MD})
precompile(Tuple{typeof(Base.Unicode.isupper), Char})
precompile(Tuple{getfield(Base.Markdown, Symbol("#kw##linecontains")), Array{Any, 1}, typeof(Base.Markdown.linecontains), Base.GenericIOBuffer{Array{UInt8, 1}}, String})
precompile(Tuple{typeof(Base.ucfirst), Base.SubString{String}})
precompile(Tuple{typeof(Base.Markdown.blocktex), Base.GenericIOBuffer{Array{UInt8, 1}}, Base.Markdown.MD})
Expand Down
1 change: 0 additions & 1 deletion base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Printf
using Base.Grisu
using Base.GMP
using Base.Unicode: lowercase, textwidth, isupper

### printf formatter generation ###
const SmallFloatingPoint = Union{Float64,Float32,Float16}
Expand Down
2 changes: 1 addition & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct FileRedirect
filename::AbstractString
append::Bool
function FileRedirect(filename, append)
if Unicode.lowercase(filename) == (@static Sys.iswindows() ? "nul" : "/dev/null")
if lowercase(filename) == (@static Sys.iswindows() ? "nul" : "/dev/null")
@warn "For portability use DevNull instead of a file redirect" maxlog=1
end
new(filename, append)
Expand Down
2 changes: 1 addition & 1 deletion base/random/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ UInt128(u::UUID) = u.value
let groupings = [1:8; 10:13; 15:18; 20:23; 25:36]
global UUID
function UUID(s::AbstractString)
s = Base.Unicode.lowercase(s)
s = lowercase(s)

if !contains(s, r"^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$")
throw(ArgumentError("Malformed UUID string"))
Expand Down
6 changes: 3 additions & 3 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ function _replace(io, repl_s::SubstitutionString, str, r, re)
if repl[next_i] == SUB_CHAR
write(io, SUB_CHAR)
i = nextind(repl, next_i)
elseif Unicode.isdigit(repl[next_i])
elseif isdigit(repl[next_i])
group = parse(Int, repl[next_i])
i = nextind(repl, next_i)
while i <= e
if Unicode.isdigit(repl[i])
if isdigit(repl[i])
group = 10group + parse(Int, repl[i])
i = nextind(repl, i)
else
Expand All @@ -349,7 +349,7 @@ function _replace(io, repl_s::SubstitutionString, str, r, re)
end
# TODO: avoid this allocation
groupname = SubString(repl, groupstart, prevind(repl, i))
if all(Unicode.isdigit, groupname)
if all(isdigit, groupname)
_write_capture(io, re, parse(Int, groupname))
else
group = PCRE.substring_number_from_name(re.regex, groupname)
Expand Down
2 changes: 0 additions & 2 deletions base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import ..Terminals: raw!, width, height, cmove, getX,

import Base: ensureroom, peek, show, AnyDict, position

using Base.Unicode: lowercase, uppercase, ucfirst, textwidth, isspace

abstract type TextInterface end
abstract type ModeState end

Expand Down
2 changes: 1 addition & 1 deletion base/repl/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ function ends_with_semicolon(line::AbstractString)
else
# outside of a comment, encountering anything but whitespace
# means the semi-colon was internal to the expression
Base.Unicode.isspace(c) || return false
isspace(c) || return false
end
end
return true
Expand Down
Loading

0 comments on commit c5cd13e

Please sign in to comment.