Hi Izzy, thanks for the proposal.
The trailing whitespace is not handled really, it is returned as is along
any trailing code. For example, it won't match if you expect `{12, ""}`.
For this reason, I don't think we should silently remove the leading
whitespace. You can call String.trim_leading if that's your preference.
On Mon, Mar 8, 2021 at 4:04 PM Izzy Elwyn <[email protected]> wrote:
> Hello, all!
>
> I recently had an issue with consistency in the behavior of
> Integer.parse/2 where it handles trailing whitespace, but fails to handle
> leading whitespace.
>
> Example:
> Integer.parse("12 ")
> {12, " "}
> Integer.parse(" 12")
> :error
>
> Because the trailing whitespace was handled, I had operated under the
> false assumption that the function would properly trim whitespace (both
> trailing *and* leading) and return a valid integer. For this reason, it
> look me a bit to track down leading whitespace as the root-cause of a
> production issue.
>
> I'd like to propose trimming whitespace as an enhancement to the
> functionality of Integer.parse/2 to improve consistency in its behavior.
>
> ~ Izzy
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/c76ea4b9-68cd-4402-9747-c61e503f11f2n%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/c76ea4b9-68cd-4402-9747-c61e503f11f2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4J18y3BWC970xCUoa%2BWp5mpmK%3DmSSxbCUdBArjOxe%3DEAA%40mail.gmail.com.