HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulebytestring-lexing-0.5.0.15Haskell2010

Data.ByteString.Lex.Integral

Functions for parsing and producing Integral values from/to ByteStrings based on the "Char8" encoding. That is, we assume an ASCII-compatible encoding of alphanumeric characters.

Since: 0.3.0

  • 9 values

General combinators

1 declaration

Decimal conversions

3 declarations
valuereadDecimal :: Integral a => ByteString -> Maybe (a, ByteString)
#

Read an unsigned/non-negative integral value in ASCII decimal format. Returns Nothing if there is no integer at the beginning of the string, otherwise returns Just the integer read and the remainder of the string.

If you are extremely concerned with performance, then it is more performant to use this function at Int or Word and then to call fromIntegral to perform the conversion at the end. However, doing this will make your code succeptible to overflow bugs if the target type is larger than Int.

valuereadDecimal_ :: Integral a => ByteString -> a
#

A variant of readDecimal which does not return the tail of the string, and returns 0 instead of Nothing. This is twice as fast for Int64 on 32-bit systems, but has identical performance to readDecimal for all other types and architectures.

Since: 0.4.0

Hexadecimal conversions

3 declarations

Read a non-negative integral value in ASCII hexadecimal format. Returns Nothing if there is no integer at the beginning of the string, otherwise returns Just the integer read and the remainder of the string.

This function does not recognize the various hexadecimal sigils like "0x", but because there are so many different variants, those are best handled by helper functions which then use this function for the actual numerical parsing. This function recognizes both upper-case, lower-case, and mixed-case hexadecimal.

Convert a bitvector into a lower-case ASCII hexadecimal string. This is helpful for visualizing raw binary data, rather than for parsing as such.

Octal conversions

2 declarations
valuereadOctal :: Integral a => ByteString -> Maybe (a, ByteString)
#

Read a non-negative integral value in ASCII octal format. Returns Nothing if there is no integer at the beginning of the string, otherwise returns Just the integer read and the remainder of the string.

This function does not recognize the various octal sigils like "0o", but because there are different variants, those are best handled by helper functions which then use this function for the actual numerical parsing.