Skip to content

Commit f9a7bd8

Browse files
committed
Tweak empty input handling
1 parent 4885df0 commit f9a7bd8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/parse.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ function _base_parse(::Type{FD{T, f}}, source::AbstractString, mode::RoundingMod
213213
throw(ArgumentError("Unhandled rounding mode $mode"))
214214
end
215215

216-
isempty(source) && throw(("Empty input is not allowed"))
217216
bytes = codeunits(source)
218217
options = mode === RoundNearest ? OPTIONS_ROUND_NEAREST :
219218
mode === RoundToZero ? OPTIONS_ROUND_TO_ZERO :
@@ -223,12 +222,14 @@ function _base_parse(::Type{FD{T, f}}, source::AbstractString, mode::RoundingMod
223222
end
224223

225224
function Base.tryparse(::Type{FD{T, f}}, source::AbstractString, mode::RoundingMode=RoundNearest) where {T, f}
225+
isempty(source) && return nothing
226226
res = _base_parse(FD{T, f}, source, mode)
227227
# If we didn't reach eof, there was some garbage at the end of the string after something that looked like a number
228228
return (Parsers.eof(res.code) && Parsers.ok(res.code)) ? res.val : nothing
229229
end
230230

231231
function Base.parse(::Type{FD{T, f}}, source::AbstractString, mode::RoundingMode=RoundNearest) where {T, f}
232+
isempty(source) && throw(ArgumentError("Empty input is not allowed"))
232233
res = _base_parse(FD{T, f}, source, mode)
233234
Parsers.inexact(res.code) && throw(InexactError(:parse, FD{T, f}, source))
234235
Parsers.overflow(res.code) && throw(OverflowError("overflow parsing $(repr(source)) as $(FD{T, f})"))

0 commit comments

Comments
 (0)