Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parsing AbstractStrings to numbers #42210

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Wynand
Copy link

@Wynand Wynand commented Sep 10, 2021

Currently Base.parse takes any AbstractString string as a parameter, however internal methods are written only to support Union{String,Substring{String} strings.

This adds support for parsing any AbstractString (assuming it can be converted to String), but I believe it could be much more efficient

@Wynand Wynand marked this pull request as draft September 10, 2021 20:19
@simeonschaub
Copy link
Member

Thanks for the PR!

I think it might be slightly more idiomatic to do this with dispatch instead, i.e. just define:

tryparse_internal(::Type{Bool}, sbuff::AbstractString) = tryparse_internal(Bool, String(sbuff)::String)

alongside the tryparse_internal(::Type{Bool}, sbuff::Union{String, SubString{String}}) one.

Would you mind also adding a test that reproduces the issue you encountered?

@simeonschaub simeonschaub added needs tests Unit tests are required for this change strings "Strings!" labels Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Unit tests are required for this change strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants