You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common usage of parse (at least for me) is for reading configuration files.
For boolean flags we can encounter either a "true" string or a "1" (or "false" / "0").
But parsing of AbstractString to Bool with numeric text doesn't work (it works with Chars '0' and '1').
julia> a =split("test: 0")
2-element Array{SubString{String},1}:"test:""0"
julia>parse(Bool,a[2])
ERROR: ArgumentError: invalid Bool representation:"0"
Stacktrace:
[1] macro expansion at ./gcutils.jl:88 [inlined]
[2] tryparse_internal(::Type{Bool}, ::SubString{String}, ::Int64, ::Int64, ::Int64, ::Bool) at ./parse.jl:188
[3] #parse#333(::Nothing, ::Function, ::Type{Bool}, ::SubString{String}) at ./parse.jl:225
[4] parse(::Type{Bool}, ::SubString{String}) at ./parse.jl:225
[5] top-level scope at none:0
julia>versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-2919:05 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU:Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
WORD_SIZE:64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)
Environment:
JULIA_NUM_THREADS =2
It is not difficult to work around this, but wouldn't it make sense to allow parsing of "0" and "1" (of any AbstractString type) to Bool?
The text was updated successfully, but these errors were encountered:
A common usage of
parse
(at least for me) is for reading configuration files.For boolean flags we can encounter either a
"true"
string or a"1"
(or"false"
/"0"
).But parsing of
AbstractString
toBool
with numeric text doesn't work (it works withChar
s'0'
and'1'
).It is not difficult to work around this, but wouldn't it make sense to allow parsing of
"0"
and"1"
(of anyAbstractString
type) toBool
?The text was updated successfully, but these errors were encountered: