{-# LANGUAGE CPP, ForeignFunctionInterface, BangPatterns #-}
{-# LANGUAGE UnliftedFFITypes, MagicHash,
UnboxedTuples, DeriveDataTypeable #-}
#if __GLASGOW_HASKELL__ >= 703
{-# LANGUAGE Unsafe #-}
#endif
{-# OPTIONS_HADDOCK not-home #-}
module Data.ByteString.Internal (
ByteString(..),
packBytes, packUptoLenBytes, unsafePackLenBytes,
packChars, packUptoLenChars, unsafePackLenChars,
unpackBytes, unpackAppendBytesLazy, unpackAppendBytesStrict,
unpackChars, unpackAppendCharsLazy, unpackAppendCharsStrict,
unsafePackAddress,
create,
createUptoN,
createAndTrim,
createAndTrim',
unsafeCreate,
unsafeCreateUptoN,
mallocByteString,
fromForeignPtr,
toForeignPtr,
nullForeignPtr,
checkedAdd,
c_strlen,
c_free_finalizer,
memchr,
memcmp,
memcpy,
memset,
c_reverse,
c_intersperse,
c_maximum,
c_minimum,
c_count,
w2c, c2w, isSpaceWord8, isSpaceChar8,
accursedUnutterablePerformIO,
inlinePerformIO
) where
import Prelude hiding (concat, null)
import qualified Data.List as List
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Ptr (Ptr, FunPtr, plusPtr)
import Foreign.Storable (Storable(..))
#if MIN_VERSION_base(4,5,0) || __GLASGOW_HASKELL__ >= 703
import Foreign.C.Types (CInt(..), CSize(..), CULong(..))
#else
import Foreign.C.Types (CInt, CSize, CULong)
#endif
import Foreign.C.String (CString)
#if !(MIN_VERSION_base(4,11,0)) && MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup((<>)))
#endif
#if !(MIN_VERSION_base(4,8,0))
import Data.Monoid (Monoid(..))
#endif
import Control.DeepSeq (NFData(rnf))
import Data.String (IsString(..))
import Control.Exception (assert)
import Data.Char (ord)
import Data.Word (Word8)
import Data.Typeable (Typeable)
import Data.Data (Data(..), mkNoRepType)
import GHC.Base (nullAddr#,realWorld#,unsafeChr)
#if MIN_VERSION_base(4,4,0)
import GHC.CString (unpackCString#)
#else
import GHC.Base (unpackCString#)
#endif
import GHC.Prim (Addr#)
#if __GLASGOW_HASKELL__ >= 611
import GHC.IO (IO(IO),unsafeDupablePerformIO)
#else
import GHC.IOBase (IO(IO),RawBuffer,unsafeDupablePerformIO)
#endif
import GHC.ForeignPtr (ForeignPtr(ForeignPtr)
,newForeignPtr_, mallocPlainForeignPtrBytes)
import GHC.Ptr (Ptr(..), castPtr)
{-# CFILES cbits/fpstring.c #-}
data ByteString = PS {-# UNPACK #-} !(ForeignPtr Word8)
{-# UNPACK #-} !Int
{-# UNPACK #-} !Int
deriving (Typeable)
instance Eq ByteString where
== :: ByteString -> ByteString -> Bool
(==) = ByteString -> ByteString -> Bool
eq
instance Ord ByteString where
compare :: ByteString -> ByteString -> Ordering
compare = ByteString -> ByteString -> Ordering
compareBytes
#if MIN_VERSION_base(4,9,0)
instance Semigroup ByteString where
<> :: ByteString -> ByteString -> ByteString
(<>) = ByteString -> ByteString -> ByteString
append
#endif
instance Monoid ByteString where
mempty :: ByteString
mempty = ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
nullForeignPtr 0 0
#if MIN_VERSION_base(4,9,0)
mappend :: ByteString -> ByteString -> ByteString
mappend = ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
(<>)
#else
mappend = append
#endif
mconcat :: [ByteString] -> ByteString
mconcat = [ByteString] -> ByteString
concat
instance NFData ByteString where
rnf :: ByteString -> ()
rnf PS{} = ()
instance Show ByteString where
showsPrec :: Int -> ByteString -> ShowS
showsPrec p :: Int
p ps :: ByteString
ps r :: String
r = Int -> String -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (ByteString -> String
unpackChars ByteString
ps) String
r
instance Read ByteString where
readsPrec :: Int -> ReadS ByteString
readsPrec p :: Int
p str :: String
str = [ (String -> ByteString
packChars String
x, String
y) | (x :: String
x, y :: String
y) <- Int -> ReadS String
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
str ]
instance IsString ByteString where
fromString :: String -> ByteString
fromString = String -> ByteString
packChars
instance Data ByteString where
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ByteString -> c ByteString
gfoldl f :: forall d b. Data d => c (d -> b) -> d -> c b
f z :: forall g. g -> c g
z txt :: ByteString
txt = ([Word8] -> ByteString) -> c ([Word8] -> ByteString)
forall g. g -> c g
z [Word8] -> ByteString
packBytes c ([Word8] -> ByteString) -> [Word8] -> c ByteString
forall d b. Data d => c (d -> b) -> d -> c b
`f` ByteString -> [Word8]
unpackBytes ByteString
txt
toConstr :: ByteString -> Constr
toConstr _ = String -> Constr
forall a. HasCallStack => String -> a
error "Data.ByteString.ByteString.toConstr"
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ByteString
gunfold _ _ = String -> Constr -> c ByteString
forall a. HasCallStack => String -> a
error "Data.ByteString.ByteString.gunfold"
dataTypeOf :: ByteString -> DataType
dataTypeOf _ = String -> DataType
mkNoRepType "Data.ByteString.ByteString"
packBytes :: [Word8] -> ByteString
packBytes :: [Word8] -> ByteString
packBytes ws :: [Word8]
ws = Int -> [Word8] -> ByteString
unsafePackLenBytes ([Word8] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
List.length [Word8]
ws) [Word8]
ws
packChars :: [Char] -> ByteString
packChars :: String -> ByteString
packChars cs :: String
cs = Int -> String -> ByteString
unsafePackLenChars (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
List.length String
cs) String
cs
{-# INLINE [0] packChars #-}
{-# RULES
"ByteString packChars/packAddress" forall s .
packChars (unpackCString# s) = accursedUnutterablePerformIO (unsafePackAddress s)
#-}
unsafePackLenBytes :: Int -> [Word8] -> ByteString
unsafePackLenBytes :: Int -> [Word8] -> ByteString
unsafePackLenBytes len :: Int
len xs0 :: [Word8]
xs0 =
Int -> (Ptr Word8 -> IO ()) -> ByteString
unsafeCreate Int
len ((Ptr Word8 -> IO ()) -> ByteString)
-> (Ptr Word8 -> IO ()) -> ByteString
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> [Word8] -> IO ()
forall b. Storable b => Ptr b -> [b] -> IO ()
go Ptr Word8
p [Word8]
xs0
where
go :: Ptr b -> [b] -> IO ()
go !Ptr b
_ [] = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go !Ptr b
p (x :: b
x:xs :: [b]
xs) = Ptr b -> b -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr b
p b
x IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr b -> [b] -> IO ()
go (Ptr b
p Ptr b -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 1) [b]
xs
unsafePackLenChars :: Int -> [Char] -> ByteString
unsafePackLenChars :: Int -> String -> ByteString
unsafePackLenChars len :: Int
len cs0 :: String
cs0 =
Int -> (Ptr Word8 -> IO ()) -> ByteString
unsafeCreate Int
len ((Ptr Word8 -> IO ()) -> ByteString)
-> (Ptr Word8 -> IO ()) -> ByteString
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> String -> IO ()
go Ptr Word8
p String
cs0
where
go :: Ptr Word8 -> String -> IO ()
go !Ptr Word8
_ [] = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go !Ptr Word8
p (c :: Char
c:cs :: String
cs) = Ptr Word8 -> Word8 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Word8
p (Char -> Word8
c2w Char
c) IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Word8 -> String -> IO ()
go (Ptr Word8
p Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 1) String
cs
unsafePackAddress :: Addr# -> IO ByteString
unsafePackAddress :: Addr# -> IO ByteString
unsafePackAddress addr# :: Addr#
addr# = do
ForeignPtr Word8
p <- Ptr Word8 -> IO (ForeignPtr Word8)
forall a. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ (Ptr CChar -> Ptr Word8
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
cstr)
CSize
l <- Ptr CChar -> IO CSize
c_strlen Ptr CChar
cstr
ByteString -> IO ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$ ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
p 0 (CSize -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CSize
l)
where
cstr :: CString
cstr :: Ptr CChar
cstr = Addr# -> Ptr CChar
forall a. Addr# -> Ptr a
Ptr Addr#
addr#
{-# INLINE unsafePackAddress #-}
packUptoLenBytes :: Int -> [Word8] -> (ByteString, [Word8])
packUptoLenBytes :: Int -> [Word8] -> (ByteString, [Word8])
packUptoLenBytes len :: Int
len xs0 :: [Word8]
xs0 =
Int -> (Ptr Word8 -> IO (Int, [Word8])) -> (ByteString, [Word8])
forall a. Int -> (Ptr Word8 -> IO (Int, a)) -> (ByteString, a)
unsafeCreateUptoN' Int
len ((Ptr Word8 -> IO (Int, [Word8])) -> (ByteString, [Word8]))
-> (Ptr Word8 -> IO (Int, [Word8])) -> (ByteString, [Word8])
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> Int -> [Word8] -> IO (Int, [Word8])
forall b. Storable b => Ptr b -> Int -> [b] -> IO (Int, [b])
go Ptr Word8
p Int
len [Word8]
xs0
where
go :: Ptr b -> Int -> [b] -> IO (Int, [b])
go !Ptr b
_ !Int
n [] = (Int, [b]) -> IO (Int, [b])
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
n, [])
go !Ptr b
_ !Int
0 xs :: [b]
xs = (Int, [b]) -> IO (Int, [b])
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
len, [b]
xs)
go !Ptr b
p !Int
n (x :: b
x:xs :: [b]
xs) = Ptr b -> b -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr b
p b
x IO () -> IO (Int, [b]) -> IO (Int, [b])
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr b -> Int -> [b] -> IO (Int, [b])
go (Ptr b
p Ptr b -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 1) (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) [b]
xs
packUptoLenChars :: Int -> [Char] -> (ByteString, [Char])
packUptoLenChars :: Int -> String -> (ByteString, String)
packUptoLenChars len :: Int
len cs0 :: String
cs0 =
Int -> (Ptr Word8 -> IO (Int, String)) -> (ByteString, String)
forall a. Int -> (Ptr Word8 -> IO (Int, a)) -> (ByteString, a)
unsafeCreateUptoN' Int
len ((Ptr Word8 -> IO (Int, String)) -> (ByteString, String))
-> (Ptr Word8 -> IO (Int, String)) -> (ByteString, String)
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> Int -> String -> IO (Int, String)
go Ptr Word8
p Int
len String
cs0
where
go :: Ptr Word8 -> Int -> String -> IO (Int, String)
go !Ptr Word8
_ !Int
n [] = (Int, String) -> IO (Int, String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
n, [])
go !Ptr Word8
_ !Int
0 cs :: String
cs = (Int, String) -> IO (Int, String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
len, String
cs)
go !Ptr Word8
p !Int
n (c :: Char
c:cs :: String
cs) = Ptr Word8 -> Word8 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Word8
p (Char -> Word8
c2w Char
c) IO () -> IO (Int, String) -> IO (Int, String)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Word8 -> Int -> String -> IO (Int, String)
go (Ptr Word8
p Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 1) (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) String
cs
unpackBytes :: ByteString -> [Word8]
unpackBytes :: ByteString -> [Word8]
unpackBytes bs :: ByteString
bs = ByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy ByteString
bs []
unpackChars :: ByteString -> [Char]
unpackChars :: ByteString -> String
unpackChars bs :: ByteString
bs = ByteString -> ShowS
unpackAppendCharsLazy ByteString
bs []
unpackAppendBytesLazy :: ByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy :: ByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy (PS fp :: ForeignPtr Word8
fp off :: Int
off len :: Int
len) xs :: [Word8]
xs
| Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 100 = ByteString -> [Word8] -> [Word8]
unpackAppendBytesStrict (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp Int
off Int
len) [Word8]
xs
| Bool
otherwise = ByteString -> [Word8] -> [Word8]
unpackAppendBytesStrict (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp Int
off 100) [Word8]
remainder
where
remainder :: [Word8]
remainder = ByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp (Int
offInt -> Int -> Int
forall a. Num a => a -> a -> a
+100) (Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-100)) [Word8]
xs
unpackAppendCharsLazy :: ByteString -> [Char] -> [Char]
unpackAppendCharsLazy :: ByteString -> ShowS
unpackAppendCharsLazy (PS fp :: ForeignPtr Word8
fp off :: Int
off len :: Int
len) cs :: String
cs
| Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 100 = ByteString -> ShowS
unpackAppendCharsStrict (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp Int
off Int
len) String
cs
| Bool
otherwise = ByteString -> ShowS
unpackAppendCharsStrict (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp Int
off 100) String
remainder
where
remainder :: String
remainder = ByteString -> ShowS
unpackAppendCharsLazy (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp (Int
offInt -> Int -> Int
forall a. Num a => a -> a -> a
+100) (Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-100)) String
cs
unpackAppendBytesStrict :: ByteString -> [Word8] -> [Word8]
unpackAppendBytesStrict :: ByteString -> [Word8] -> [Word8]
unpackAppendBytesStrict (PS fp :: ForeignPtr Word8
fp off :: Int
off len :: Int
len) xs :: [Word8]
xs =
IO [Word8] -> [Word8]
forall a. IO a -> a
accursedUnutterablePerformIO (IO [Word8] -> [Word8]) -> IO [Word8] -> [Word8]
forall a b. (a -> b) -> a -> b
$ ForeignPtr Word8 -> (Ptr Word8 -> IO [Word8]) -> IO [Word8]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO [Word8]) -> IO [Word8])
-> (Ptr Word8 -> IO [Word8]) -> IO [Word8]
forall a b. (a -> b) -> a -> b
$ \base :: Ptr Word8
base ->
Ptr Word8 -> Ptr Word8 -> [Word8] -> IO [Word8]
forall b. Storable b => Ptr b -> Ptr b -> [b] -> IO [b]
loop (Ptr Word8
base Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
offInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)) (Ptr Word8
base Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
offInt -> Int -> Int
forall a. Num a => a -> a -> a
-1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
len)) [Word8]
xs
where
loop :: Ptr b -> Ptr b -> [b] -> IO [b]
loop !Ptr b
sentinal !Ptr b
p acc :: [b]
acc
| Ptr b
p Ptr b -> Ptr b -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr b
sentinal = [b] -> IO [b]
forall (m :: * -> *) a. Monad m => a -> m a
return [b]
acc
| Bool
otherwise = do b
x <- Ptr b -> IO b
forall a. Storable a => Ptr a -> IO a
peek Ptr b
p
Ptr b -> Ptr b -> [b] -> IO [b]
loop Ptr b
sentinal (Ptr b
p Ptr b -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (-1)) (b
xb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
acc)
unpackAppendCharsStrict :: ByteString -> [Char] -> [Char]
(PS fp :: ForeignPtr Word8
fp off :: Int
off len :: Int
len) xs :: String
xs =
IO String -> String
forall a. IO a -> a
accursedUnutterablePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ ForeignPtr Word8 -> (Ptr Word8 -> IO String) -> IO String
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO String) -> IO String)
-> (Ptr Word8 -> IO String) -> IO String
forall a b. (a -> b) -> a -> b
$ \base :: Ptr Word8
base ->
Ptr Word8 -> Ptr Word8 -> String -> IO String
loop (Ptr Word8
base Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
offInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)) (Ptr Word8
base Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
offInt -> Int -> Int
forall a. Num a => a -> a -> a
-1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
len)) String
xs
where
loop :: Ptr Word8 -> Ptr Word8 -> String -> IO String
loop !Ptr Word8
sentinal !Ptr Word8
p acc :: String
acc
| Ptr Word8
p Ptr Word8 -> Ptr Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Word8
sentinal = String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
acc
| Bool
otherwise = do Word8
x <- Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
p
Ptr Word8 -> Ptr Word8 -> String -> IO String
loop Ptr Word8
sentinal (Ptr Word8
p Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (-1)) (Word8 -> Char
w2c Word8
xChar -> ShowS
forall a. a -> [a] -> [a]
:String
acc)
nullForeignPtr :: ForeignPtr Word8
nullForeignPtr :: ForeignPtr Word8
nullForeignPtr = Addr# -> ForeignPtrContents -> ForeignPtr Word8
forall a. Addr# -> ForeignPtrContents -> ForeignPtr a
ForeignPtr Addr#
nullAddr# (String -> ForeignPtrContents
forall a. HasCallStack => String -> a
error "nullForeignPtr")
fromForeignPtr :: ForeignPtr Word8
-> Int
-> Int
-> ByteString
fromForeignPtr :: ForeignPtr Word8 -> Int -> Int -> ByteString
fromForeignPtr = ForeignPtr Word8 -> Int -> Int -> ByteString
PS
{-# INLINE fromForeignPtr #-}
toForeignPtr :: ByteString -> (ForeignPtr Word8, Int, Int)
toForeignPtr :: ByteString -> (ForeignPtr Word8, Int, Int)
toForeignPtr (PS ps :: ForeignPtr Word8
ps s :: Int
s l :: Int
l) = (ForeignPtr Word8
ps, Int
s, Int
l)
{-# INLINE toForeignPtr #-}
unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString
unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString
unsafeCreate l :: Int
l f :: Ptr Word8 -> IO ()
f = IO ByteString -> ByteString
forall a. IO a -> a
unsafeDupablePerformIO (Int -> (Ptr Word8 -> IO ()) -> IO ByteString
create Int
l Ptr Word8 -> IO ()
f)
{-# INLINE unsafeCreate #-}
unsafeCreateUptoN :: Int -> (Ptr Word8 -> IO Int) -> ByteString
unsafeCreateUptoN :: Int -> (Ptr Word8 -> IO Int) -> ByteString
unsafeCreateUptoN l :: Int
l f :: Ptr Word8 -> IO Int
f = IO ByteString -> ByteString
forall a. IO a -> a
unsafeDupablePerformIO (Int -> (Ptr Word8 -> IO Int) -> IO ByteString
createUptoN Int
l Ptr Word8 -> IO Int
f)
{-# INLINE unsafeCreateUptoN #-}
unsafeCreateUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> (ByteString, a)
unsafeCreateUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> (ByteString, a)
unsafeCreateUptoN' l :: Int
l f :: Ptr Word8 -> IO (Int, a)
f = IO (ByteString, a) -> (ByteString, a)
forall a. IO a -> a
unsafeDupablePerformIO (Int -> (Ptr Word8 -> IO (Int, a)) -> IO (ByteString, a)
forall a. Int -> (Ptr Word8 -> IO (Int, a)) -> IO (ByteString, a)
createUptoN' Int
l Ptr Word8 -> IO (Int, a)
f)
{-# INLINE unsafeCreateUptoN' #-}
create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString
create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString
create l :: Int
l f :: Ptr Word8 -> IO ()
f = do
ForeignPtr Word8
fp <- Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
l
ForeignPtr Word8 -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO ()) -> IO ()) -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> IO ()
f Ptr Word8
p
ByteString -> IO ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$! ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp 0 Int
l
{-# INLINE create #-}
createUptoN :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString
createUptoN :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString
createUptoN l :: Int
l f :: Ptr Word8 -> IO Int
f = do
ForeignPtr Word8
fp <- Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
l
Int
l' <- ForeignPtr Word8 -> (Ptr Word8 -> IO Int) -> IO Int
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO Int) -> IO Int)
-> (Ptr Word8 -> IO Int) -> IO Int
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> IO Int
f Ptr Word8
p
Bool -> IO ByteString -> IO ByteString
forall a. HasCallStack => Bool -> a -> a
assert (Int
l' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
l) (IO ByteString -> IO ByteString) -> IO ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$! ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp 0 Int
l'
{-# INLINE createUptoN #-}
createUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> IO (ByteString, a)
createUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> IO (ByteString, a)
createUptoN' l :: Int
l f :: Ptr Word8 -> IO (Int, a)
f = do
ForeignPtr Word8
fp <- Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
l
(l' :: Int
l', res :: a
res) <- ForeignPtr Word8 -> (Ptr Word8 -> IO (Int, a)) -> IO (Int, a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO (Int, a)) -> IO (Int, a))
-> (Ptr Word8 -> IO (Int, a)) -> IO (Int, a)
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> IO (Int, a)
f Ptr Word8
p
Bool -> IO (ByteString, a) -> IO (ByteString, a)
forall a. HasCallStack => Bool -> a -> a
assert (Int
l' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
l) (IO (ByteString, a) -> IO (ByteString, a))
-> IO (ByteString, a) -> IO (ByteString, a)
forall a b. (a -> b) -> a -> b
$ (ByteString, a) -> IO (ByteString, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp 0 Int
l', a
res)
{-# INLINE createUptoN' #-}
createAndTrim :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString
createAndTrim :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString
createAndTrim l :: Int
l f :: Ptr Word8 -> IO Int
f = do
ForeignPtr Word8
fp <- Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
l
ForeignPtr Word8 -> (Ptr Word8 -> IO ByteString) -> IO ByteString
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO ByteString) -> IO ByteString)
-> (Ptr Word8 -> IO ByteString) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> do
Int
l' <- Ptr Word8 -> IO Int
f Ptr Word8
p
if Bool -> Bool -> Bool
forall a. HasCallStack => Bool -> a -> a
assert (Int
l' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
l) (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Int
l' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
l
then ByteString -> IO ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> IO ByteString) -> ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$! ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp 0 Int
l
else Int -> (Ptr Word8 -> IO ()) -> IO ByteString
create Int
l' ((Ptr Word8 -> IO ()) -> IO ByteString)
-> (Ptr Word8 -> IO ()) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ \p' :: Ptr Word8
p' -> Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy Ptr Word8
p' Ptr Word8
p Int
l'
{-# INLINE createAndTrim #-}
createAndTrim' :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a)
createAndTrim' :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a)
createAndTrim' l :: Int
l f :: Ptr Word8 -> IO (Int, Int, a)
f = do
ForeignPtr Word8
fp <- Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
l
ForeignPtr Word8
-> (Ptr Word8 -> IO (ByteString, a)) -> IO (ByteString, a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO (ByteString, a)) -> IO (ByteString, a))
-> (Ptr Word8 -> IO (ByteString, a)) -> IO (ByteString, a)
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> do
(off :: Int
off, l' :: Int
l', res :: a
res) <- Ptr Word8 -> IO (Int, Int, a)
f Ptr Word8
p
if Bool -> Bool -> Bool
forall a. HasCallStack => Bool -> a -> a
assert (Int
l' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
l) (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Int
l' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
l
then (ByteString, a) -> IO (ByteString, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp 0 Int
l, a
res)
else do ByteString
ps <- Int -> (Ptr Word8 -> IO ()) -> IO ByteString
create Int
l' ((Ptr Word8 -> IO ()) -> IO ByteString)
-> (Ptr Word8 -> IO ()) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ \p' :: Ptr Word8
p' ->
Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy Ptr Word8
p' (Ptr Word8
p Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off) Int
l'
(ByteString, a) -> IO (ByteString, a)
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString
ps, a
res)
mallocByteString :: Int -> IO (ForeignPtr a)
mallocByteString :: Int -> IO (ForeignPtr a)
mallocByteString = Int -> IO (ForeignPtr a)
forall a. Int -> IO (ForeignPtr a)
mallocPlainForeignPtrBytes
{-# INLINE mallocByteString #-}
eq :: ByteString -> ByteString -> Bool
eq :: ByteString -> ByteString -> Bool
eq a :: ByteString
a@(PS fp :: ForeignPtr Word8
fp off :: Int
off len :: Int
len) b :: ByteString
b@(PS fp' :: ForeignPtr Word8
fp' off' :: Int
off' len' :: Int
len')
| Int
len Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
len' = Bool
False
| ForeignPtr Word8
fp ForeignPtr Word8 -> ForeignPtr Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== ForeignPtr Word8
fp' Bool -> Bool -> Bool
&& Int
off Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
off' = Bool
True
| Bool
otherwise = ByteString -> ByteString -> Ordering
compareBytes ByteString
a ByteString
b Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ
{-# INLINE eq #-}
compareBytes :: ByteString -> ByteString -> Ordering
compareBytes :: ByteString -> ByteString -> Ordering
compareBytes (PS _ _ 0) (PS _ _ 0) = Ordering
EQ
compareBytes (PS fp1 :: ForeignPtr Word8
fp1 off1 :: Int
off1 len1 :: Int
len1) (PS fp2 :: ForeignPtr Word8
fp2 off2 :: Int
off2 len2 :: Int
len2) =
IO Ordering -> Ordering
forall a. IO a -> a
accursedUnutterablePerformIO (IO Ordering -> Ordering) -> IO Ordering -> Ordering
forall a b. (a -> b) -> a -> b
$
ForeignPtr Word8 -> (Ptr Word8 -> IO Ordering) -> IO Ordering
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp1 ((Ptr Word8 -> IO Ordering) -> IO Ordering)
-> (Ptr Word8 -> IO Ordering) -> IO Ordering
forall a b. (a -> b) -> a -> b
$ \p1 :: Ptr Word8
p1 ->
ForeignPtr Word8 -> (Ptr Word8 -> IO Ordering) -> IO Ordering
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp2 ((Ptr Word8 -> IO Ordering) -> IO Ordering)
-> (Ptr Word8 -> IO Ordering) -> IO Ordering
forall a b. (a -> b) -> a -> b
$ \p2 :: Ptr Word8
p2 -> do
CInt
i <- Ptr Word8 -> Ptr Word8 -> Int -> IO CInt
memcmp (Ptr Word8
p1 Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off1) (Ptr Word8
p2 Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off2) (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
len1 Int
len2)
Ordering -> IO Ordering
forall (m :: * -> *) a. Monad m => a -> m a
return (Ordering -> IO Ordering) -> Ordering -> IO Ordering
forall a b. (a -> b) -> a -> b
$! case CInt
i CInt -> CInt -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` 0 of
EQ -> Int
len1 Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Int
len2
x :: Ordering
x -> Ordering
x
append :: ByteString -> ByteString -> ByteString
append :: ByteString -> ByteString -> ByteString
append (PS _ _ 0) b :: ByteString
b = ByteString
b
append a :: ByteString
a (PS _ _ 0) = ByteString
a
append (PS fp1 :: ForeignPtr Word8
fp1 off1 :: Int
off1 len1 :: Int
len1) (PS fp2 :: ForeignPtr Word8
fp2 off2 :: Int
off2 len2 :: Int
len2) =
Int -> (Ptr Word8 -> IO ()) -> ByteString
unsafeCreate (Int
len1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
len2) ((Ptr Word8 -> IO ()) -> ByteString)
-> (Ptr Word8 -> IO ()) -> ByteString
forall a b. (a -> b) -> a -> b
$ \destptr1 :: Ptr Word8
destptr1 -> do
let destptr2 :: Ptr b
destptr2 = Ptr Word8
destptr1 Ptr Word8 -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
len1
ForeignPtr Word8 -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp1 ((Ptr Word8 -> IO ()) -> IO ()) -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \p1 :: Ptr Word8
p1 -> Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy Ptr Word8
destptr1 (Ptr Word8
p1 Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off1) Int
len1
ForeignPtr Word8 -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp2 ((Ptr Word8 -> IO ()) -> IO ()) -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \p2 :: Ptr Word8
p2 -> Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy Ptr Word8
forall b. Ptr b
destptr2 (Ptr Word8
p2 Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off2) Int
len2
concat :: [ByteString] -> ByteString
concat :: [ByteString] -> ByteString
concat = \bss0 :: [ByteString]
bss0 -> [ByteString] -> [ByteString] -> ByteString
goLen0 [ByteString]
bss0 [ByteString]
bss0
where
goLen0 :: [ByteString] -> [ByteString] -> ByteString
goLen0 _ [] = ByteString
forall a. Monoid a => a
mempty
goLen0 bss0 :: [ByteString]
bss0 (PS _ _ 0 :bss :: [ByteString]
bss) = [ByteString] -> [ByteString] -> ByteString
goLen0 [ByteString]
bss0 [ByteString]
bss
goLen0 bss0 :: [ByteString]
bss0 (bs :: ByteString
bs :bss :: [ByteString]
bss) = [ByteString] -> ByteString -> [ByteString] -> ByteString
goLen1 [ByteString]
bss0 ByteString
bs [ByteString]
bss
goLen1 :: [ByteString] -> ByteString -> [ByteString] -> ByteString
goLen1 _ bs :: ByteString
bs [] = ByteString
bs
goLen1 bss0 :: [ByteString]
bss0 bs :: ByteString
bs (PS _ _ 0 :bss :: [ByteString]
bss) = [ByteString] -> ByteString -> [ByteString] -> ByteString
goLen1 [ByteString]
bss0 ByteString
bs [ByteString]
bss
goLen1 bss0 :: [ByteString]
bss0 bs :: ByteString
bs (PS _ _ len :: Int
len:bss :: [ByteString]
bss) = [ByteString] -> Int -> [ByteString] -> ByteString
goLen [ByteString]
bss0 (String -> Int -> Int -> Int
checkedAdd "concat" Int
len' Int
len) [ByteString]
bss
where PS _ _ len' :: Int
len' = ByteString
bs
goLen :: [ByteString] -> Int -> [ByteString] -> ByteString
goLen bss0 :: [ByteString]
bss0 !Int
total (PS _ _ len :: Int
len:bss :: [ByteString]
bss) = [ByteString] -> Int -> [ByteString] -> ByteString
goLen [ByteString]
bss0 Int
total' [ByteString]
bss
where total' :: Int
total' = String -> Int -> Int -> Int
checkedAdd "concat" Int
total Int
len
goLen bss0 :: [ByteString]
bss0 total :: Int
total [] =
Int -> (Ptr Word8 -> IO ()) -> ByteString
unsafeCreate Int
total ((Ptr Word8 -> IO ()) -> ByteString)
-> (Ptr Word8 -> IO ()) -> ByteString
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr Word8
ptr -> [ByteString] -> Ptr Word8 -> IO ()
goCopy [ByteString]
bss0 Ptr Word8
ptr
goCopy :: [ByteString] -> Ptr Word8 -> IO ()
goCopy [] !Ptr Word8
_ = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
goCopy (PS _ _ 0 :bss :: [ByteString]
bss) !Ptr Word8
ptr = [ByteString] -> Ptr Word8 -> IO ()
goCopy [ByteString]
bss Ptr Word8
ptr
goCopy (PS fp :: ForeignPtr Word8
fp off :: Int
off len :: Int
len:bss :: [ByteString]
bss) !Ptr Word8
ptr = do
ForeignPtr Word8 -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fp ((Ptr Word8 -> IO ()) -> IO ()) -> (Ptr Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \p :: Ptr Word8
p -> Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy Ptr Word8
ptr (Ptr Word8
p Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off) Int
len
[ByteString] -> Ptr Word8 -> IO ()
goCopy [ByteString]
bss (Ptr Word8
ptr Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
len)
{-# NOINLINE concat #-}
{-# RULES
"ByteString concat [] -> mempty"
concat [] = mempty
"ByteString concat [bs] -> bs" forall x.
concat [x] = x
#-}
checkedAdd :: String -> Int -> Int -> Int
checkedAdd :: String -> Int -> Int -> Int
checkedAdd fun :: String
fun x :: Int
x y :: Int
y
| Int
r Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 0 = Int
r
| Bool
otherwise = String -> Int
forall a. String -> a
overflowError String
fun
where r :: Int
r = Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
y
{-# INLINE checkedAdd #-}
w2c :: Word8 -> Char
w2c :: Word8 -> Char
w2c = Int -> Char
unsafeChr (Int -> Char) -> (Word8 -> Int) -> Word8 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE w2c #-}
c2w :: Char -> Word8
c2w :: Char -> Word8
c2w = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord
{-# INLINE c2w #-}
isSpaceWord8 :: Word8 -> Bool
isSpaceWord8 :: Word8 -> Bool
isSpaceWord8 w :: Word8
w =
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0x20 Bool -> Bool -> Bool
||
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0x0A Bool -> Bool -> Bool
||
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0x09 Bool -> Bool -> Bool
||
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0x0C Bool -> Bool -> Bool
||
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0x0D Bool -> Bool -> Bool
||
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0x0B Bool -> Bool -> Bool
||
Word8
w Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== 0xA0
{-# INLINE isSpaceWord8 #-}
isSpaceChar8 :: Char -> Bool
isSpaceChar8 :: Char -> Bool
isSpaceChar8 c :: Char
c =
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ' ' Bool -> Bool -> Bool
||
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\t' Bool -> Bool -> Bool
||
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\n' Bool -> Bool -> Bool
||
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\r' Bool -> Bool -> Bool
||
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\f' Bool -> Bool -> Bool
||
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\v' Bool -> Bool -> Bool
||
Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\xa0'
{-# INLINE isSpaceChar8 #-}
overflowError :: String -> a
overflowError :: String -> a
overflowError fun :: String
fun = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ "Data.ByteString." String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
fun String -> ShowS
forall a. [a] -> [a] -> [a]
++ ": size overflow"
{-# INLINE accursedUnutterablePerformIO #-}
accursedUnutterablePerformIO :: IO a -> a
accursedUnutterablePerformIO :: IO a -> a
accursedUnutterablePerformIO (IO m :: State# RealWorld -> (# State# RealWorld, a #)
m) = case State# RealWorld -> (# State# RealWorld, a #)
m State# RealWorld
realWorld# of (# _, r :: a
r #) -> a
r
inlinePerformIO :: IO a -> a
inlinePerformIO :: IO a -> a
inlinePerformIO = IO a -> a
forall a. IO a -> a
accursedUnutterablePerformIO
{-# INLINE inlinePerformIO #-}
{-# DEPRECATED inlinePerformIO "If you think you know what you are doing, use 'unsafePerformIO'. If you are sure you know what you are doing, use 'unsafeDupablePerformIO'. If you enjoy sharing an address space with a malevolent agent of chaos, try 'accursedUnutterablePerformIO'." #-}
foreign import ccall unsafe "string.h strlen" c_strlen
:: CString -> IO CSize
foreign import ccall unsafe "static stdlib.h &free" c_free_finalizer
:: FunPtr (Ptr Word8 -> IO ())
foreign import ccall unsafe "string.h memchr" c_memchr
:: Ptr Word8 -> CInt -> CSize -> IO (Ptr Word8)
memchr :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8)
memchr :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8)
memchr p :: Ptr Word8
p w :: Word8
w s :: CSize
s = Ptr Word8 -> CInt -> CSize -> IO (Ptr Word8)
c_memchr Ptr Word8
p (Word8 -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w) CSize
s
foreign import ccall unsafe "string.h memcmp" c_memcmp
:: Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt
memcmp :: Ptr Word8 -> Ptr Word8 -> Int -> IO CInt
memcmp :: Ptr Word8 -> Ptr Word8 -> Int -> IO CInt
memcmp p :: Ptr Word8
p q :: Ptr Word8
q s :: Int
s = Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt
c_memcmp Ptr Word8
p Ptr Word8
q (Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s)
foreign import ccall unsafe "string.h memcpy" c_memcpy
:: Ptr Word8 -> Ptr Word8 -> CSize -> IO (Ptr Word8)
memcpy :: Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy :: Ptr Word8 -> Ptr Word8 -> Int -> IO ()
memcpy p :: Ptr Word8
p q :: Ptr Word8
q s :: Int
s = Ptr Word8 -> Ptr Word8 -> CSize -> IO (Ptr Word8)
c_memcpy Ptr Word8
p Ptr Word8
q (Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s) IO (Ptr Word8) -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
foreign import ccall unsafe "string.h memset" c_memset
:: Ptr Word8 -> CInt -> CSize -> IO (Ptr Word8)
memset :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8)
memset :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8)
memset p :: Ptr Word8
p w :: Word8
w s :: CSize
s = Ptr Word8 -> CInt -> CSize -> IO (Ptr Word8)
c_memset Ptr Word8
p (Word8 -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w) CSize
s
foreign import ccall unsafe "static fpstring.h fps_reverse" c_reverse
:: Ptr Word8 -> Ptr Word8 -> CULong -> IO ()
foreign import ccall unsafe "static fpstring.h fps_intersperse" c_intersperse
:: Ptr Word8 -> Ptr Word8 -> CULong -> Word8 -> IO ()
foreign import ccall unsafe "static fpstring.h fps_maximum" c_maximum
:: Ptr Word8 -> CULong -> IO Word8
foreign import ccall unsafe "static fpstring.h fps_minimum" c_minimum
:: Ptr Word8 -> CULong -> IO Word8
foreign import ccall unsafe "static fpstring.h fps_count" c_count
:: Ptr Word8 -> CULong -> Word8 -> IO CULong