{-# LANGUAGE CPP #-}
module Data.ByteString.Builder.Prim.Internal.Base16 (
EncodingTable
, lowerTable
, encode8_as_16h
) where
import Foreign
import GHC.Exts (Addr#, Ptr(..))
#if PURE_HASKELL
import qualified Data.ByteString.Internal.Pure as Pure
#else
import Foreign.C.Types
#endif
data EncodingTable = EncodingTable Addr#
lowerTable :: EncodingTable
lowerTable :: EncodingTable
lowerTable =
#if PURE_HASKELL
case Pure.lower_hex_table of
Ptr p# -> EncodingTable p#
#else
case Ptr CChar
c_lower_hex_table of
Ptr Addr#
p# -> Addr# -> EncodingTable
EncodingTable Addr#
p#
foreign import ccall "&hs_bytestring_lower_hex_table"
c_lower_hex_table :: Ptr CChar
#endif
{-# INLINE encode8_as_16h #-}
encode8_as_16h :: EncodingTable -> Word8 -> IO Word16
encode8_as_16h :: EncodingTable -> Word8 -> IO Word16
encode8_as_16h (EncodingTable Addr#
table) =
Ptr Word16 -> Int -> IO Word16
forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff (Addr# -> Ptr Word16
forall a. Addr# -> Ptr a
Ptr Addr#
table) (Int -> IO Word16) -> (Word8 -> Int) -> Word8 -> IO Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral