haskell / haskell/attoparsec

octal parsing

Open
#164 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
531
Forks
98
PR merge metrics
No merged PRs in 30d

Description

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)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.