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 optional spacer for parser #5

Open
sitch opened this issue Sep 23, 2020 · 1 comment
Open

Add optional spacer for parser #5

sitch opened this issue Sep 23, 2020 · 1 comment

Comments

@sitch
Copy link

sitch commented Sep 23, 2020

Was parsing output from dstat and you see values like:

504k   11k
1189B 2733B
59k   14k
14M 8959B 

Which fails parsing due to the mandatory single spacer " " in the regex between the value and unit

i.e.:

iex> FileSize.parse("1GB") 
{:error, %FileSize.ParseError{reason: :format, value: "1GB"}}

whereas if the space is there it works

iex> FileSize.parse("1 GB") 
{:ok, #FileSize<"1 GB">}
@tlux
Copy link
Owner

tlux commented Sep 25, 2020

See the discussion in #7. I suggest to introduce FileSize.parse/2 and allow these options to be passed:

:symbols - map of symbols, as for FileSize.format/2
:ignore_whitespace - boolean to toggle whether the parser should ignore whitespace characters between value and unit

@tlux tlux mentioned this issue Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants