Skip to content

Commit 9c1faae

Browse files
authored
Move back isascii() from Unicode to Base (#25076)
This function is not really Unicode-related and its definition does not depend on the Unicode standard version. This fixes a bug introduced when moving isascii() to Base.Unicode, as it was not exported from Unicode stdlib module as it should have been.
1 parent c640381 commit 9c1faae

File tree

14 files changed

+37
-38
lines changed

14 files changed

+37
-38
lines changed

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ Deprecated or removed
766766

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

base/char.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function show(io::IO, ::MIME"text/plain", c::Char)
147147
isoverlong(c) && print(io, "[overlong] ")
148148
u = UInt32(c)
149149
h = hex(u, u 0xffff ? 4 : 6)
150-
print(io, (Unicode.isascii(c) ? "ASCII/" : ""), "Unicode U+", h)
150+
print(io, (isascii(c) ? "ASCII/" : ""), "Unicode U+", h)
151151
else
152152
print(io, ": Malformed UTF-8")
153153
end

base/exports.jl

+1
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ export
726726
hex2bytes,
727727
hex2bytes!,
728728
info,
729+
isascii,
729730
ismatch,
730731
isvalid,
731732
join,

base/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ julia> countlines(io, '.')
967967
```
968968
"""
969969
function countlines(io::IO, eol::Char='\n')
970-
Unicode.isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported"))
970+
isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported"))
971971
aeol = UInt8(eol)
972972
a = Vector{UInt8}(uninitialized, 8192)
973973
nl = 0

base/loading.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ elseif Sys.isapple()
6868

6969
# If there is no match, it's possible that the file does exist but HFS+
7070
# performed unicode normalization. See https://developer.apple.com/library/mac/qa/qa1235/_index.html.
71-
Unicode.isascii(path_basename) && return false
71+
isascii(path_basename) && return false
7272
Vector{UInt8}(Unicode.normalize(path_basename, :NFD)) == casepreserved_basename
7373
end
7474
else

base/repl/latex_symbols.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ open(fname) do f
5656
split(replace(L, r"[{}\"]+", "\t"), "\t"))
5757
c = Char(parse(Int, x[2], 16))
5858
if (Base.is_id_char(c) || Base.isoperator(Symbol(c))) &&
59-
string(c) ∉ latex_strings && !Unicode.isascii(c)
59+
string(c) ∉ latex_strings && !isascii(c)
6060
tabcomname = escape_string(x[3])
6161
if startswith(tabcomname, "\\\\math")
6262
tabcomname = string("\\\\", tabcomname[7:end])

base/socket.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ Gets all of the IP addresses of the `host`.
636636
Uses the operating system's underlying getaddrinfo implementation, which may do a DNS lookup.
637637
"""
638638
function getalladdrinfo(host::String)
639-
Unicode.isascii(host) || error("non-ASCII hostname: $host")
639+
isascii(host) || error("non-ASCII hostname: $host")
640640
req = Libc.malloc(_sizeof_uv_getaddrinfo)
641641
uv_req_set_data(req, C_NULL) # in case we get interrupted before arriving at the wait call
642642
status = ccall(:jl_getaddrinfo, Int32, (Ptr{Void}, Ptr{Void}, Cstring, Ptr{Void}, Ptr{Void}),

base/strings/basic.jl

+24
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,30 @@ next(e::EachStringIndex, state) = (state, nextind(e.s, state))
486486
done(e::EachStringIndex, state) = done(e.s, state)
487487
eltype(::Type{EachStringIndex}) = Int
488488

489+
"""
490+
isascii(c::Union{Char,AbstractString}) -> Bool
491+
492+
Test whether a character belongs to the ASCII character set, or whether this is true for
493+
all elements of a string.
494+
495+
# Examples
496+
```jldoctest
497+
julia> isascii('a')
498+
true
499+
500+
julia> isascii('α')
501+
false
502+
503+
julia> isascii("abc")
504+
true
505+
506+
julia> isascii("αβγ")
507+
false
508+
```
509+
"""
510+
isascii(c::Char) = bswap(reinterpret(UInt32, c)) < 0x80
511+
isascii(s::AbstractString) = all(isascii, s)
512+
489513
## string map, filter, has ##
490514

491515
function map(f, s::AbstractString)

base/strings/search.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function search(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = 1
2828
end
2929

3030
function search(a::ByteArray, b::Char, i::Integer = 1)
31-
if Unicode.isascii(b)
31+
if isascii(b)
3232
search(a,UInt8(b),i)
3333
else
3434
search(a,Vector{UInt8}(string(b)),i).start
@@ -59,7 +59,7 @@ function rsearch(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer =
5959
end
6060

6161
function rsearch(a::ByteArray, b::Char, i::Integer = length(a))
62-
if Unicode.isascii(b)
62+
if isascii(b)
6363
rsearch(a,UInt8(b),i)
6464
else
6565
rsearch(a,Vector{UInt8}(string(b)),i).start

base/strings/unicode.jl

-26
Original file line numberDiff line numberDiff line change
@@ -597,32 +597,6 @@ true
597597
"""
598598
isgraph(c::Char) = UTF8PROC_CATEGORY_LU <= category_code(c) <= UTF8PROC_CATEGORY_SO
599599

600-
"""
601-
isascii(c::Union{Char,AbstractString}) -> Bool
602-
603-
Test whether a character belongs to the ASCII character set, or whether this is true for
604-
all elements of a string.
605-
606-
# Examples
607-
```jldoctest
608-
julia> using Unicode
609-
610-
julia> isascii('a')
611-
true
612-
613-
julia> isascii('α')
614-
false
615-
616-
julia> isascii("abc")
617-
true
618-
619-
julia> isascii("αβγ")
620-
false
621-
```
622-
"""
623-
isascii(c::Char) = bswap(reinterpret(UInt32, c)) < 0x80
624-
isascii(s::AbstractString) = all(isascii, s)
625-
626600
"""
627601
isxdigit(c::Char) -> Bool
628602

stdlib/Distributed/src/Distributed.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using Base: Process, Semaphore, JLOptions, AnyDict, buffer_writes, wait_connecte
1717
binding_module, notify_error, atexit, julia_exename, julia_cmd,
1818
AsyncGenerator, acquire, release, invokelatest,
1919
shell_escape_posixly, uv_error, coalesce, notnothing
20-
using Base.Unicode: isascii, isdigit, isnumeric
20+
using Base.Unicode: isdigit, isnumeric
2121

2222
# NOTE: clusterserialize.jl imports additional symbols from Base.Serializer for use
2323

stdlib/SuiteSparse/src/cholmod.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ end
611611

612612
### cholmod_check.h ###
613613
function print_sparse(A::Sparse{Tv}, name::String) where Tv<:VTypes
614-
Unicode.isascii(name) || error("non-ASCII name: $name")
614+
isascii(name) || error("non-ASCII name: $name")
615615
set_print_level(common_struct, 3)
616616
@isok ccall((@cholmod_name("print_sparse", SuiteSparse_long),:libcholmod), Cint,
617617
(Ptr{C_Sparse{Tv}}, Ptr{UInt8}, Ptr{UInt8}),

test/arrayops.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ end
464464
s = "julia"
465465
@test find(c -> c == 'l', s) == [3]
466466
g = Base.Unicode.graphemes("日本語")
467-
@test find(Base.Unicode.isascii, g) == Int[]
467+
@test find(isascii, g) == Int[]
468468
@test find(!iszero, (i % 2 for i in 1:10)) == collect(1:2:9)
469469
end
470470
@testset "findn" begin

test/strings/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
cp, ch, st = cx[i,:]
6767
@test cp == convert(UInt32, ch)
6868
@test string(ch) == unescape_string(st)
69-
if Base.Unicode.isascii(ch) || !Base.Unicode.isprint(ch)
69+
if isascii(ch) || !Base.Unicode.isprint(ch)
7070
@test st == escape_string(string(ch))
7171
end
7272
for j = 1:size(cx,1)

0 commit comments

Comments
 (0)