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

Support scanning an integer from a string with various configuration options #4

Open
jwodder opened this issue Nov 4, 2023 · 0 comments
Labels
enhancement New feature or request therefor

Comments

@jwodder
Copy link
Owner

jwodder commented Nov 4, 2023

Add a struct with a scan<T: StrToInt>(&self, s: &str) -> Result<(T, &str), Error> method that parses an integer from the initial portion of s and returns the integer & the remainder of s

  • The following options can be set as fields of the struct (possibly via a builder interface?):

    • what base to use in the absence of a base prefix
      • Bases should be specified as a Base newtype around u32
        • impl TryFrom<u32> for Base, failing for 0, 1, and anything greater than 36
        • Give Base constants for common bases: DECIMAL, HEXADECIMAL, OCTAL, and BINARY
    • whether to allow a base prefix
    • whether to allow a base prefix for a different base than the "default" one
    • whether to require a base prefix?
    • whether to allow an uppercase base prefix
    • whether to allow underscores
    • whether to consume trailing underscores
      • Should this always be done?
    • whether to allow a sign
    • whether to allow a + sign
    • whether to allow -0 for unsigned types
  • The scanner will always consume as many digits as there are at the start of the string, even if doing so would cause an overflow/underflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request therefor
Projects
None yet
Development

No branches or pull requests

1 participant