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

Trimming spaces and Maybe #88

Open
maxigit opened this issue Jun 10, 2015 · 0 comments
Open

Trimming spaces and Maybe #88

maxigit opened this issue Jun 10, 2015 · 0 comments

Comments

@maxigit
Copy link

maxigit commented Jun 10, 2015

I have a little problem trying to parse a csv which has spaces for null value (ex "item, ,").
The way to handle null values is obviously to use Nothing but the parser fails because the parsed string is not null but can't be parsed has an Int.

I've added some specs for what I think is the sensible behavior

, testGroup "Space trimming and Maybe"
  [ testCase "null::Int"           (expect (parseField ""     :: Parser (Maybe Int))    Nothing)
  , testCase "_::Int"              (expect (parseField " "    :: Parser (Maybe Int))    Nothing)
  , testCase "_Int"                (expect (parseField " 12"  :: Parser (Maybe Int))    (Just 12))
  , testCase "____"                (expect (parseField "    " :: Parser (Maybe Int))    Nothing)
  , testCase "null::String"        (expect (parseField ""     :: Parser (Maybe String)) Nothing)
  , testCase "quoted null::String" (expect (parseField "\"\""     :: Parser (Maybe String)) (Just ""))
  , testCase "_::String"           (expect (parseField " "    :: Parser (Maybe String)) (Just " "))

Case "null::String" and "quoted null::String" and hard to get working together.
I see many possibilities to solve the problem

1 - strip spaces before testing if a field is null in the Maybe code
2 - strip spaces at the parsing level, and maybe add a strip space options in the decodeOptions
3 - change parser to deal with Maybe by default

What do you think ? (I'm happy to help if needed).

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

1 participant