1{-# LANGUAGE CPP #-}
2{-# LANGUAGE MagicHash #-}
3module Data.Attoparsec.Internal.Compat where
4
5import Data.ByteString.Internal (ByteString(..))
6import Data.Word (Word8)
7import Foreign.ForeignPtr (ForeignPtr)
8
9#if MIN_VERSION_bytestring(0,11,0)
10import Data.ByteString.Internal (plusForeignPtr)
11#endif
12
13withPS :: ByteString -> (ForeignPtr Word8 -> Int -> Int -> r) -> r
14#if MIN_VERSION_bytestring(0,11,0)
15withPS (BS fp len)     kont = kont fp 0   len
16#else
17withPS (PS fp off len) kont = kont fp off len
18#endif
19{-# INLINE withPS #-}
20
21mkPS :: ForeignPtr Word8 -> Int -> Int -> ByteString
22#if MIN_VERSION_bytestring(0,11,0)
23mkPS fp off len = BS (plusForeignPtr fp off) len
24#else
25mkPS fp off len = PS fp off len
26#endif
27{-# INLINE mkPS #-}
28