Skip to content

Commit 4987606

Browse files
authored
Revert recent PRs causing CI failures (#59799)
1 parent 829666d commit 4987606

File tree

3 files changed

+11
-40
lines changed

3 files changed

+11
-40
lines changed

base/parse.jl

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,16 @@ julia> parse(Complex{Float64}, "3.2e-1 + 4.5im")
3838
parse(T::Type, str; base = Int)
3939
parse(::Type{Union{}}, slurp...; kwargs...) = error("cannot parse a value as Union{}")
4040

41-
@noinline function _invalid_base(base)
42-
throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
43-
end
44-
45-
@noinline _invalid_digit(base, char) = throw(ArgumentError("invalid base $base digit $(repr(char))"))
46-
47-
function parse_char(::Type{T}, c::AbstractChar, base::Integer, throw::Bool) where T
48-
a::UInt8 = (base <= 36 ? 10 : 36)
49-
(2 <= base <= 62) || _invalid_base(base)
50-
base = base % UInt8
51-
cp = codepoint(c)
52-
cp = cp > 0x7a ? 0xff : cp % UInt8
53-
d = UInt8('0') cp UInt8('9') ? cp - UInt8('0') :
54-
UInt8('A') cp UInt8('Z') ? cp - UInt8('A') + UInt8(10) :
55-
UInt8('a') cp UInt8('z') ? cp - UInt8('a') + a :
56-
0xff
57-
d < base || (throw ? _invalid_digit(base, c) : return nothing)
58-
convert(T, d)::T
59-
end
60-
61-
function parse(::Type{T}, c::AbstractChar; base::Integer=10) where {T <: Integer}
62-
@inline parse_char(T, c, base, true)
41+
function parse(::Type{T}, c::AbstractChar; base::Integer = 10) where T<:Integer
42+
a::Int = (base <= 36 ? 10 : 36)
43+
2 <= base <= 62 || throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
44+
d = '0' <= c <= '9' ? c-'0' :
45+
'A' <= c <= 'Z' ? c-'A'+10 :
46+
'a' <= c <= 'z' ? c-'a'+a : throw(ArgumentError("invalid digit: $(repr(c))"))
47+
d < base || throw(ArgumentError("invalid base $base digit $(repr(c))"))
48+
convert(T, d)
6349
end
6450

65-
function tryparse(::Type{T}, c::AbstractChar; base::Integer=10) where {T <: Integer}
66-
@inline parse_char(T, c, base, false)
67-
end
68-
69-
# For consistency with parse(t, AbstractString), support a `base` argument only when T<:Integer
70-
parse(::Type{T}, c::AbstractChar) where T = @inline parse_char(T, c, 10, true)
71-
tryparse(::Type{T}, c::AbstractChar) where T = @inline parse_char(T, c, 10, false)
72-
7351
function parseint_iterate(s::AbstractString, startpos::Int, endpos::Int)
7452
(0 < startpos <= endpos) || (return Char(0), 0, 0)
7553
j = startpos
@@ -138,7 +116,8 @@ function tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::
138116
return nothing
139117
end
140118
if !(2 <= base <= 62)
141-
raise ? _invalid_base(base) : return nothing
119+
raise && throw(ArgumentError(LazyString("invalid base: base must be 2 ≤ base ≤ 62, got ", base)))
120+
return nothing
142121
end
143122
if i == 0
144123
raise && throw(ArgumentError("premature end of integer: $(repr(SubString(s,startpos,endpos)))"))
@@ -257,7 +236,7 @@ end
257236
if 2 <= base <= 62
258237
return base
259238
end
260-
_invalid_base(base)
239+
throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
261240
end
262241

263242
"""

base/public.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
public
44
# Modules
5-
Cartesian,
65
Checked,
76
Filesystem,
87
Order,

test/parse.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@
2929
@test parse(Int, 'a', base=16) == 10
3030
@test_throws ArgumentError parse(Int, 'a')
3131
@test_throws ArgumentError parse(Int,typemax(Char))
32-
33-
@test tryparse(Int, '8') === 8
34-
@test tryparse(Int, 'a') === nothing
35-
@test tryparse(Int, 'a'; base=11) === 10
36-
@test tryparse(Int32, 'a'; base=11) === Int32(10)
37-
@test tryparse(UInt8, 'f'; base=16) === 0x0f
38-
@test tryparse(UInt8, 'f'; base=15) === nothing
3932
end
4033

4134
# Issue 29451

0 commit comments

Comments
 (0)