flatparse-0.5.1.0: High-performance parsing from strict bytestrings
Safe HaskellSafe-Inferred
LanguageHaskell2010

FlatParse.Common.Assorted

Synopsis

Compatibility

Char predicates

isDigit :: Char -> Bool Source #

isDigit c = '0' <= c && c <= '9'

isLatinLetter :: Char -> Bool Source #

isLatinLetter c = ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')

isGreekLetter :: Char -> Bool Source #

isGreekLetter c = ('Α' <= c && c <= 'Ω') || ('α' <= c && c <= 'ω')

Other

splitBytes :: [Word] -> ([Word], [Word]) Source #

UTF-8 conversions

strToUtf8 :: String -> ByteString Source #

Convert an UTF8-encoded String to a ByteString.

utf8ToStr :: ByteString -> String Source #

Convert a ByteString to an UTF8-encoded String.

Shortcuts

derefChar8# :: Addr# -> Char# Source #

Shortcut for 'indexCharOffAddr# addr# 0#'.

Boxed integer coercions

These functions should be no-ops. They correspond to the similarly-named GHC 9.4 primops which work on unboxed integers.

Helpers

withPosInt# :: Int# -> r -> r Source #

Assert for the given Int# that n >= 0.

Throws a runtime error if given a negative integer.

withIntUnwrap# :: (Int# -> r) -> Int -> r Source #

Unwrap the Int# from an Int and apply it to the given function.

Bit manipulation

zbytel :: (FiniteBits a, Num a) => a -> Int Source #

Index of leftmost null byte, or (number of bytes in type) if not present.

Adapted from Hacker's Delight 6-1. Useful in big-endian environments.

zbytel'intermediate :: (FiniteBits a, Num a) => a -> a Source #

bit mangling, returns 0 for inputs without a null byte

Separating allows us to skip some index calculation if there was no null byte.

zbytel'toIdx :: (FiniteBits a, Num a) => a -> Int Source #

bit mangling, turns intermediate value into an index

Separating allows us to skip some index calculation if there was no null byte.

zbyter :: (FiniteBits a, Num a) => a -> Int Source #

Index of rightmost null byte, or (number of bytes in type) if not present

Adapted from Hacker's Delight 6-1. Useful in little-endian environments.

zbyter'intermediate :: (FiniteBits a, Num a) => a -> a Source #

bit mangling, returns 0 for inputs without a null byte

Separating allows us to skip some index calculation if there was no null byte.

zbyter'toIdx :: (FiniteBits a, Num a) => a -> Int Source #

bit mangling, turns intermediate value into an index

Separating allows us to skip some index calculation if there was no null byte.