Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize Bool parse method to AbstractString (#47782)
* Generalize Bool parse method to AbstractString Fixes JuliaStrings/InlineStrings.jl#57. We currently have a specialization for `parse(Bool, ::Union{String, SubString{String})` where `true` and `false` are parsed appropriately. The restriction to `Union{String, SubString{String}}`, however, means we don't get this behavior for other `AbstractString`s. In the linked issue above, for InlineStrings, we end up going through the generic integer parsing codepath which results in an `InexactError` when we try to do `Bool(10)`. The proposal in this PR takes advantage of the fact that there is only the 2 comparisons where we do `_memcmp` that require the input string to be "dense" (in memory), and otherwise, we just do a comparison against a `SubString` of the input string. Relatedly, I've wanted to introduce the concept of an abstrac type like: ```julia abstract type MemoryAddressableString <: AbstractString ``` where the additional required interface would be being able to call `pointer(::MemoryAddressableString)`, since a lot of our string algorithms depend on doing these kind of pointer operations and hence makes it quite a pain to implement your own custom string type. * Apply suggestions from code review Co-authored-by: Stefan Karpinski <stefan@karpinski.org> Co-authored-by: Nick Robinson <npr251@gmail.com> Co-authored-by: Stefan Karpinski <stefan@karpinski.org> Co-authored-by: Nick Robinson <npr251@gmail.com>
- Loading branch information