{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
module Data.ByteString.Base64.URL
(
encode
, decode
, decodeLenient
, joinWith
) where
import Data.ByteString.Base64.Internal
import qualified Data.ByteString as B
import Data.ByteString.Internal (ByteString(..))
import Data.Word (Word8)
import Foreign.ForeignPtr (ForeignPtr)
encode :: ByteString -> ByteString
encode = encodeWith (mkEncodeTable alphabet)
decode :: ByteString -> Either String ByteString
decode = decodeWithTable decodeFP
decodeLenient :: ByteString -> ByteString
decodeLenient = decodeLenientWithTable decodeFP
alphabet :: ByteString
alphabet = B.pack $ [65..90] ++ [97..122] ++ [48..57] ++ [45,95]
{-# NOINLINE alphabet #-}
decodeFP :: ForeignPtr Word8
PS decodeFP _ _ = B.pack $ replicate 45 x ++ [62,x,x] ++ [52..61] ++ [x,x,
x,done,x,x,x] ++ [0..25] ++ [x,x,x,x,63,x] ++ [26..51] ++ replicate 133 x
{-# NOINLINE decodeFP #-}
x :: Integral a => a
x = 255
{-# INLINE x #-}