Skip to content

Commit 61ac4f2

Browse files
committed
Move back isascii() from Unicode to Base
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 d192302 commit 61ac4f2

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
@@ -743,7 +743,7 @@ Deprecated or removed
743743

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

base/char.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function show(io::IO, ::MIME"text/plain", c::Char)
139139
show(io, c)
140140
if !ismalformed(c)
141141
u = UInt32(c)
142-
print(io, ": ", Unicode.isascii(c) ? "ASCII/" : "", "Unicode U+", hex(u, u > 0xffff ? 6 : 4))
142+
print(io, ": ", isascii(c) ? "ASCII/" : "", "Unicode U+", hex(u, u > 0xffff ? 6 : 4))
143143
else
144144
print(io, ": Malformed UTF-8")
145145
end

base/distributed/Distributed.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using Base: Process, Semaphore, JLOptions, AnyDict, buffer_writes, wait_connecte
1515
binding_module, notify_error, atexit, julia_exename, julia_cmd,
1616
AsyncGenerator, display_error, acquire, release, invokelatest, warn_once,
1717
shell_escape_posixly, uv_error
18-
using Base.Unicode: isascii, isdigit, isnumeric
18+
using Base.Unicode: isdigit, isnumeric
1919

2020
# NOTE: clusterserialize.jl imports additional symbols from Base.Serializer for use
2121

base/exports.jl

+1
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ export
728728
hex2bytes,
729729
hex2bytes!,
730730
info,
731+
isascii,
731732
ismatch,
732733
isvalid,
733734
join,

base/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ julia> countlines(io, '.')
953953
```
954954
"""
955955
function countlines(io::IO, eol::Char='\n')
956-
Unicode.isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported"))
956+
isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported"))
957957
aeol = UInt8(eol)
958958
a = Vector{UInt8}(uninitialized, 8192)
959959
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
@@ -484,6 +484,30 @@ next(e::EachStringIndex, state) = (state, nextind(e.s, state))
484484
done(e::EachStringIndex, state) = done(e.s, state)
485485
eltype(::Type{EachStringIndex}) = Int
486486

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

489513
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/SuiteSparse/src/cholmod.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ end
615615

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

test/arrayops.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ end
468468
s = "julia"
469469
@test find(c -> c == 'l', s) == [3]
470470
g = Base.Unicode.graphemes("日本語")
471-
@test find(Base.Unicode.isascii, g) == Int[]
471+
@test find(isascii, g) == Int[]
472472
@test find(!iszero, (i % 2 for i in 1:10)) == collect(1:2:9)
473473
end
474474
@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)