haskell / base16-bytestring

Fast base16 (hexadecimal) encoding and decoding for Haskell bytestrings.
Other
27 stars 10 forks source link

Add 'decodeEither' function #6

Closed chshersh closed 4 years ago

chshersh commented 6 years ago

This function is convenient. Here is the sample implementation of this function:

newtype Decode16Error = Decode16Error ByteString

-- | Decode base16-encoded ByteString.
decodeEither :: ByteString -> Either Decode16Error ByteString
decodeEither = handleError . decode
  where
    handleError (res,rest)
      | BS.null rest = Right res
      | otherwise = Left $ Decode16Error $ "suffix is not in base-16 format: " <> rest
23Skidoo commented 5 years ago

PRs welcome.

emilypi commented 4 years ago

@chshersh I'm addressing this in #10. My counterproposal is that the signature for decodes should change entirely to be flush with the APIs of the other base encoding libraries which provide offsets pointing at the invalid chars, instead of slices of the bytestring. The end result will be

decode :: ByteString -> Either String ByteString
chshersh commented 4 years ago

@emilypi Thanks for working on this!

emilypi commented 4 years ago

@chshersh released v1.0.0.0 to hackage 😄