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

octal parsing #164

Open
joeyh opened this issue Dec 6, 2019 · 0 comments
Open

octal parsing #164

joeyh opened this issue Dec 6, 2019 · 0 comments

Comments

@joeyh
Copy link

joeyh commented Dec 6, 2019

Data.Attoparsec.ByteString.Char8 has decimal and hexadecimal, but no octal. Since octals are used for file permissions, it would be good to have a ready made parser for them. In my case I'm parsing git ls-tree output, which includes file permissions.

It's easy enough to adapt the decimal and hexadecimal code into the following.
I mostly submitted this because now, having modified your code, I have to include the 3 clause BSD license in my program in order to properly document your copyright, and would rather send it upstream. ;)

-- | Parse and decode an unsigned octal number.
--
-- This parser does not accept a leading @\"0o\"@ string.
octal :: Integral a => A.Parser a
octal = B8.foldl' step 0 `fmap` I.takeWhile1 isOctDigit
  where
        isOctDigit w = w >= 48 && w <= 55
        step a w = a * 8 + fromIntegral (w - 48)
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