{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_HADDOCK prune #-}
{-# LANGUAGE Trustworthy #-}
module Data.ByteString.Lazy.Char8 (
ByteString,
empty,
singleton,
pack,
unpack,
fromChunks,
toChunks,
fromStrict,
toStrict,
cons,
cons',
snoc,
append,
head,
uncons,
last,
tail,
unsnoc,
init,
null,
length,
map,
reverse,
intersperse,
intercalate,
transpose,
foldl,
foldl',
foldl1,
foldl1',
foldr,
foldr',
foldr1,
foldr1',
concat,
concatMap,
any,
all,
maximum,
minimum,
compareLength,
scanl,
scanl1,
scanr,
scanr1,
mapAccumL,
mapAccumR,
repeat,
replicate,
cycle,
iterate,
unfoldr,
take,
takeEnd,
drop,
dropEnd,
splitAt,
takeWhile,
takeWhileEnd,
dropWhile,
dropWhileEnd,
span,
spanEnd,
break,
breakEnd,
group,
groupBy,
inits,
tails,
stripPrefix,
stripSuffix,
split,
splitWith,
lines,
words,
unlines,
unwords,
isPrefixOf,
isSuffixOf,
elem,
notElem,
find,
filter,
partition,
index,
indexMaybe,
(!?),
elemIndex,
elemIndexEnd,
elemIndices,
findIndex,
findIndexEnd,
findIndices,
count,
zip,
zipWith,
packZipWith,
unzip,
copy,
readInt,
readInteger,
getContents,
putStr,
putStrLn,
interact,
readFile,
writeFile,
appendFile,
hGetContents,
hGet,
hGetNonBlocking,
hPut,
hPutNonBlocking,
hPutStr,
hPutStrLn,
) where
import Data.ByteString.Lazy
(fromChunks, toChunks
,empty,null,length,tail,init,append,reverse,transpose,cycle
,concat,take,takeEnd,drop,dropEnd,splitAt,intercalate
,isPrefixOf,isSuffixOf,group,inits,tails,copy
,stripPrefix,stripSuffix
,hGetContents, hGet, hPut, getContents
,hGetNonBlocking, hPutNonBlocking
,putStr, hPutStr, interact
,readFile,writeFile,appendFile,compareLength)
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString as S (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Unsafe as B
import Data.ByteString.Lazy.Internal
import Data.ByteString.Internal (w2c, c2w, isSpaceWord8)
import Data.Int (Int64)
import qualified Data.List as List
import Prelude hiding
(reverse,head,tail,last,init,null,length,map,lines,foldl,foldr,unlines
,concat,any,take,drop,splitAt,takeWhile,dropWhile,span,break,elem,filter
,unwords,words,maximum,minimum,all,concatMap,scanl,scanl1,scanr,scanr1,foldl1,foldr1
,readFile,writeFile,appendFile,replicate,getContents,getLine,putStr,putStrLn
,zip,zipWith,unzip,notElem,repeat,iterate,interact,cycle)
import System.IO (Handle, stdout)
singleton :: Char -> ByteString
singleton :: Char -> ByteString
singleton = Word8 -> ByteString
L.singleton (Word8 -> ByteString) -> (Char -> Word8) -> Char -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE singleton #-}
pack :: [Char] -> ByteString
pack :: [Char] -> ByteString
pack = [Char] -> ByteString
packChars
unpack :: ByteString -> [Char]
unpack :: ByteString -> [Char]
unpack = ByteString -> [Char]
unpackChars
infixr 5 `cons`, `cons'`
infixl 5 `snoc`
cons :: Char -> ByteString -> ByteString
cons :: Char -> ByteString -> ByteString
cons = Word8 -> ByteString -> ByteString
L.cons (Word8 -> ByteString -> ByteString)
-> (Char -> Word8) -> Char -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE cons #-}
cons' :: Char -> ByteString -> ByteString
cons' :: Char -> ByteString -> ByteString
cons' = Word8 -> ByteString -> ByteString
L.cons' (Word8 -> ByteString -> ByteString)
-> (Char -> Word8) -> Char -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE cons' #-}
snoc :: ByteString -> Char -> ByteString
snoc :: ByteString -> Char -> ByteString
snoc ByteString
p = ByteString -> Word8 -> ByteString
L.snoc ByteString
p (Word8 -> ByteString) -> (Char -> Word8) -> Char -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE snoc #-}
head :: ByteString -> Char
head :: ByteString -> Char
head = Word8 -> Char
w2c (Word8 -> Char) -> (ByteString -> Word8) -> ByteString -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => ByteString -> Word8
ByteString -> Word8
L.head
{-# INLINE head #-}
uncons :: ByteString -> Maybe (Char, ByteString)
uncons :: ByteString -> Maybe (Char, ByteString)
uncons ByteString
bs = case ByteString -> Maybe (Word8, ByteString)
L.uncons ByteString
bs of
Maybe (Word8, ByteString)
Nothing -> Maybe (Char, ByteString)
forall a. Maybe a
Nothing
Just (Word8
w, ByteString
bs') -> (Char, ByteString) -> Maybe (Char, ByteString)
forall a. a -> Maybe a
Just (Word8 -> Char
w2c Word8
w, ByteString
bs')
{-# INLINE uncons #-}
unsnoc :: ByteString -> Maybe (ByteString, Char)
unsnoc :: ByteString -> Maybe (ByteString, Char)
unsnoc ByteString
bs = case ByteString -> Maybe (ByteString, Word8)
L.unsnoc ByteString
bs of
Maybe (ByteString, Word8)
Nothing -> Maybe (ByteString, Char)
forall a. Maybe a
Nothing
Just (ByteString
bs', Word8
w) -> (ByteString, Char) -> Maybe (ByteString, Char)
forall a. a -> Maybe a
Just (ByteString
bs', Word8 -> Char
w2c Word8
w)
{-# INLINE unsnoc #-}
last :: ByteString -> Char
last :: ByteString -> Char
last = Word8 -> Char
w2c (Word8 -> Char) -> (ByteString -> Word8) -> ByteString -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => ByteString -> Word8
ByteString -> Word8
L.last
{-# INLINE last #-}
map :: (Char -> Char) -> ByteString -> ByteString
map :: (Char -> Char) -> ByteString -> ByteString
map Char -> Char
f = (Word8 -> Word8) -> ByteString -> ByteString
L.map (Char -> Word8
c2w (Char -> Word8) -> (Word8 -> Char) -> Word8 -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Char
f (Char -> Char) -> (Word8 -> Char) -> Word8 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE map #-}
intersperse :: Char -> ByteString -> ByteString
intersperse :: Char -> ByteString -> ByteString
intersperse = Word8 -> ByteString -> ByteString
L.intersperse (Word8 -> ByteString -> ByteString)
-> (Char -> Word8) -> Char -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE intersperse #-}
foldl :: (a -> Char -> a) -> a -> ByteString -> a
foldl :: forall a. (a -> Char -> a) -> a -> ByteString -> a
foldl a -> Char -> a
f = (a -> Word8 -> a) -> a -> ByteString -> a
forall a. (a -> Word8 -> a) -> a -> ByteString -> a
L.foldl (\a
a Word8
c -> a -> Char -> a
f a
a (Word8 -> Char
w2c Word8
c))
{-# INLINE foldl #-}
foldl' :: (a -> Char -> a) -> a -> ByteString -> a
foldl' :: forall a. (a -> Char -> a) -> a -> ByteString -> a
foldl' a -> Char -> a
f = (a -> Word8 -> a) -> a -> ByteString -> a
forall a. (a -> Word8 -> a) -> a -> ByteString -> a
L.foldl' (\a
a Word8
c -> a -> Char -> a
f a
a (Word8 -> Char
w2c Word8
c))
{-# INLINE foldl' #-}
foldr :: (Char -> a -> a) -> a -> ByteString -> a
foldr :: forall a. (Char -> a -> a) -> a -> ByteString -> a
foldr Char -> a -> a
f = (Word8 -> a -> a) -> a -> ByteString -> a
forall a. (Word8 -> a -> a) -> a -> ByteString -> a
L.foldr (Char -> a -> a
f (Char -> a -> a) -> (Word8 -> Char) -> Word8 -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE foldr #-}
foldr' :: (Char -> a -> a) -> a -> ByteString -> a
foldr' :: forall a. (Char -> a -> a) -> a -> ByteString -> a
foldr' Char -> a -> a
f = (Word8 -> a -> a) -> a -> ByteString -> a
forall a. (Word8 -> a -> a) -> a -> ByteString -> a
L.foldr' (Char -> a -> a
f (Char -> a -> a) -> (Word8 -> Char) -> Word8 -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
foldl1 :: (Char -> Char -> Char) -> ByteString -> Char
foldl1 :: (Char -> Char -> Char) -> ByteString -> Char
foldl1 Char -> Char -> Char
f ByteString
ps = Word8 -> Char
w2c (HasCallStack => (Word8 -> Word8 -> Word8) -> ByteString -> Word8
(Word8 -> Word8 -> Word8) -> ByteString -> Word8
L.foldl1 (\Word8
x Word8
y -> Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
x) (Word8 -> Char
w2c Word8
y))) ByteString
ps)
{-# INLINE foldl1 #-}
foldl1' :: (Char -> Char -> Char) -> ByteString -> Char
foldl1' :: (Char -> Char -> Char) -> ByteString -> Char
foldl1' Char -> Char -> Char
f ByteString
ps = Word8 -> Char
w2c (HasCallStack => (Word8 -> Word8 -> Word8) -> ByteString -> Word8
(Word8 -> Word8 -> Word8) -> ByteString -> Word8
L.foldl1' (\Word8
x Word8
y -> Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
x) (Word8 -> Char
w2c Word8
y))) ByteString
ps)
foldr1 :: (Char -> Char -> Char) -> ByteString -> Char
foldr1 :: (Char -> Char -> Char) -> ByteString -> Char
foldr1 Char -> Char -> Char
f ByteString
ps = Word8 -> Char
w2c (HasCallStack => (Word8 -> Word8 -> Word8) -> ByteString -> Word8
(Word8 -> Word8 -> Word8) -> ByteString -> Word8
L.foldr1 (\Word8
x Word8
y -> Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
x) (Word8 -> Char
w2c Word8
y))) ByteString
ps)
{-# INLINE foldr1 #-}
foldr1' :: (Char -> Char -> Char) -> ByteString -> Char
foldr1' :: (Char -> Char -> Char) -> ByteString -> Char
foldr1' Char -> Char -> Char
f ByteString
ps = Word8 -> Char
w2c (HasCallStack => (Word8 -> Word8 -> Word8) -> ByteString -> Word8
(Word8 -> Word8 -> Word8) -> ByteString -> Word8
L.foldr1' (\Word8
x Word8
y -> Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
x) (Word8 -> Char
w2c Word8
y))) ByteString
ps)
concatMap :: (Char -> ByteString) -> ByteString -> ByteString
concatMap :: (Char -> ByteString) -> ByteString -> ByteString
concatMap Char -> ByteString
f = (Word8 -> ByteString) -> ByteString -> ByteString
L.concatMap (Char -> ByteString
f (Char -> ByteString) -> (Word8 -> Char) -> Word8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE concatMap #-}
any :: (Char -> Bool) -> ByteString -> Bool
any :: (Char -> Bool) -> ByteString -> Bool
any Char -> Bool
f = (Word8 -> Bool) -> ByteString -> Bool
L.any (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE any #-}
all :: (Char -> Bool) -> ByteString -> Bool
all :: (Char -> Bool) -> ByteString -> Bool
all Char -> Bool
f = (Word8 -> Bool) -> ByteString -> Bool
L.all (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE all #-}
maximum :: ByteString -> Char
maximum :: ByteString -> Char
maximum = Word8 -> Char
w2c (Word8 -> Char) -> (ByteString -> Word8) -> ByteString -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => ByteString -> Word8
ByteString -> Word8
L.maximum
{-# INLINE maximum #-}
minimum :: ByteString -> Char
minimum :: ByteString -> Char
minimum = Word8 -> Char
w2c (Word8 -> Char) -> (ByteString -> Word8) -> ByteString -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => ByteString -> Word8
ByteString -> Word8
L.minimum
{-# INLINE minimum #-}
scanl :: (Char -> Char -> Char) -> Char -> ByteString -> ByteString
scanl :: (Char -> Char -> Char) -> Char -> ByteString -> ByteString
scanl Char -> Char -> Char
f Char
z = (Word8 -> Word8 -> Word8) -> Word8 -> ByteString -> ByteString
L.scanl (\Word8
a Word8
b -> Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
a) (Word8 -> Char
w2c Word8
b))) (Char -> Word8
c2w Char
z)
scanl1 :: (Char -> Char -> Char) -> ByteString -> ByteString
scanl1 :: (Char -> Char -> Char) -> ByteString -> ByteString
scanl1 Char -> Char -> Char
f = (Word8 -> Word8 -> Word8) -> ByteString -> ByteString
L.scanl1 Word8 -> Word8 -> Word8
f'
where f' :: Word8 -> Word8 -> Word8
f' Word8
accumulator Word8
value = Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
accumulator) (Word8 -> Char
w2c Word8
value))
scanr
:: (Char -> Char -> Char)
-> Char
-> ByteString
-> ByteString
scanr :: (Char -> Char -> Char) -> Char -> ByteString -> ByteString
scanr Char -> Char -> Char
f = (Word8 -> Word8 -> Word8) -> Word8 -> ByteString -> ByteString
L.scanr Word8 -> Word8 -> Word8
f' (Word8 -> ByteString -> ByteString)
-> (Char -> Word8) -> Char -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
where f' :: Word8 -> Word8 -> Word8
f' Word8
accumulator Word8
value = Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
accumulator) (Word8 -> Char
w2c Word8
value))
scanr1 :: (Char -> Char -> Char) -> ByteString -> ByteString
scanr1 :: (Char -> Char -> Char) -> ByteString -> ByteString
scanr1 Char -> Char -> Char
f = (Word8 -> Word8 -> Word8) -> ByteString -> ByteString
L.scanr1 Word8 -> Word8 -> Word8
f'
where f' :: Word8 -> Word8 -> Word8
f' Word8
accumulator Word8
value = Char -> Word8
c2w (Char -> Char -> Char
f (Word8 -> Char
w2c Word8
accumulator) (Word8 -> Char
w2c Word8
value))
mapAccumL :: (acc -> Char -> (acc, Char)) -> acc -> ByteString -> (acc, ByteString)
mapAccumL :: forall acc.
(acc -> Char -> (acc, Char))
-> acc -> ByteString -> (acc, ByteString)
mapAccumL acc -> Char -> (acc, Char)
f = (acc -> Word8 -> (acc, Word8))
-> acc -> ByteString -> (acc, ByteString)
forall acc.
(acc -> Word8 -> (acc, Word8))
-> acc -> ByteString -> (acc, ByteString)
L.mapAccumL (\acc
a Word8
w -> case acc -> Char -> (acc, Char)
f acc
a (Word8 -> Char
w2c Word8
w) of (acc
a',Char
c) -> (acc
a', Char -> Word8
c2w Char
c))
mapAccumR :: (acc -> Char -> (acc, Char)) -> acc -> ByteString -> (acc, ByteString)
mapAccumR :: forall acc.
(acc -> Char -> (acc, Char))
-> acc -> ByteString -> (acc, ByteString)
mapAccumR acc -> Char -> (acc, Char)
f = (acc -> Word8 -> (acc, Word8))
-> acc -> ByteString -> (acc, ByteString)
forall acc.
(acc -> Word8 -> (acc, Word8))
-> acc -> ByteString -> (acc, ByteString)
L.mapAccumR (\acc
acc Word8
w -> case acc -> Char -> (acc, Char)
f acc
acc (Word8 -> Char
w2c Word8
w) of (acc
acc', Char
c) -> (acc
acc', Char -> Word8
c2w Char
c))
iterate :: (Char -> Char) -> Char -> ByteString
iterate :: (Char -> Char) -> Char -> ByteString
iterate Char -> Char
f = (Word8 -> Word8) -> Word8 -> ByteString
L.iterate (Char -> Word8
c2w (Char -> Word8) -> (Word8 -> Char) -> Word8 -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Char
f (Char -> Char) -> (Word8 -> Char) -> Word8 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c) (Word8 -> ByteString) -> (Char -> Word8) -> Char -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
repeat :: Char -> ByteString
repeat :: Char -> ByteString
repeat = Word8 -> ByteString
L.repeat (Word8 -> ByteString) -> (Char -> Word8) -> Char -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
replicate :: Int64 -> Char -> ByteString
replicate :: Int64 -> Char -> ByteString
replicate Int64
w Char
c = Int64 -> Word8 -> ByteString
L.replicate Int64
w (Char -> Word8
c2w Char
c)
unfoldr :: (a -> Maybe (Char, a)) -> a -> ByteString
unfoldr :: forall a. (a -> Maybe (Char, a)) -> a -> ByteString
unfoldr a -> Maybe (Char, a)
f = (a -> Maybe (Word8, a)) -> a -> ByteString
forall a. (a -> Maybe (Word8, a)) -> a -> ByteString
L.unfoldr ((a -> Maybe (Word8, a)) -> a -> ByteString)
-> (a -> Maybe (Word8, a)) -> a -> ByteString
forall a b. (a -> b) -> a -> b
$ \a
a -> case a -> Maybe (Char, a)
f a
a of
Maybe (Char, a)
Nothing -> Maybe (Word8, a)
forall a. Maybe a
Nothing
Just (Char
c, a
a') -> (Word8, a) -> Maybe (Word8, a)
forall a. a -> Maybe a
Just (Char -> Word8
c2w Char
c, a
a')
takeWhile :: (Char -> Bool) -> ByteString -> ByteString
takeWhile :: (Char -> Bool) -> ByteString -> ByteString
takeWhile Char -> Bool
f = (Word8 -> Bool) -> ByteString -> ByteString
L.takeWhile (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE takeWhile #-}
takeWhileEnd :: (Char -> Bool) -> ByteString -> ByteString
takeWhileEnd :: (Char -> Bool) -> ByteString -> ByteString
takeWhileEnd Char -> Bool
f = (Word8 -> Bool) -> ByteString -> ByteString
L.takeWhileEnd (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE takeWhileEnd #-}
dropWhile :: (Char -> Bool) -> ByteString -> ByteString
dropWhile :: (Char -> Bool) -> ByteString -> ByteString
dropWhile Char -> Bool
f = (Word8 -> Bool) -> ByteString -> ByteString
L.dropWhile (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE dropWhile #-}
dropWhileEnd :: (Char -> Bool) -> ByteString -> ByteString
dropWhileEnd :: (Char -> Bool) -> ByteString -> ByteString
dropWhileEnd Char -> Bool
f = (Word8 -> Bool) -> ByteString -> ByteString
L.dropWhileEnd (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE dropWhileEnd #-}
break :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
break :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
break Char -> Bool
f = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
L.break (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE break #-}
breakEnd :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
breakEnd :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
breakEnd Char -> Bool
f = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
L.breakEnd (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE breakEnd #-}
span :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
span :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
span Char -> Bool
f = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
L.span (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE span #-}
spanEnd :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
spanEnd :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
spanEnd Char -> Bool
f = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
L.spanEnd (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE spanEnd #-}
split :: Char -> ByteString -> [ByteString]
split :: Char -> ByteString -> [ByteString]
split = Word8 -> ByteString -> [ByteString]
L.split (Word8 -> ByteString -> [ByteString])
-> (Char -> Word8) -> Char -> ByteString -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE split #-}
splitWith :: (Char -> Bool) -> ByteString -> [ByteString]
splitWith :: (Char -> Bool) -> ByteString -> [ByteString]
splitWith Char -> Bool
f = (Word8 -> Bool) -> ByteString -> [ByteString]
L.splitWith (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE splitWith #-}
groupBy :: (Char -> Char -> Bool) -> ByteString -> [ByteString]
groupBy :: (Char -> Char -> Bool) -> ByteString -> [ByteString]
groupBy Char -> Char -> Bool
k = (Word8 -> Word8 -> Bool) -> ByteString -> [ByteString]
L.groupBy (\Word8
a Word8
b -> Char -> Char -> Bool
k (Word8 -> Char
w2c Word8
a) (Word8 -> Char
w2c Word8
b))
index :: ByteString -> Int64 -> Char
index :: ByteString -> Int64 -> Char
index = (Word8 -> Char
w2c (Word8 -> Char) -> (Int64 -> Word8) -> Int64 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Int64 -> Word8) -> Int64 -> Char)
-> (ByteString -> Int64 -> Word8) -> ByteString -> Int64 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => ByteString -> Int64 -> Word8
ByteString -> Int64 -> Word8
L.index
{-# INLINE index #-}
indexMaybe :: ByteString -> Int64 -> Maybe Char
indexMaybe :: ByteString -> Int64 -> Maybe Char
indexMaybe = ((Word8 -> Char) -> Maybe Word8 -> Maybe Char
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word8 -> Char
w2c (Maybe Word8 -> Maybe Char)
-> (Int64 -> Maybe Word8) -> Int64 -> Maybe Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Int64 -> Maybe Word8) -> Int64 -> Maybe Char)
-> (ByteString -> Int64 -> Maybe Word8)
-> ByteString
-> Int64
-> Maybe Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64 -> Maybe Word8
L.indexMaybe
{-# INLINE indexMaybe #-}
(!?) :: ByteString -> Int64 -> Maybe Char
!? :: ByteString -> Int64 -> Maybe Char
(!?) = ByteString -> Int64 -> Maybe Char
indexMaybe
{-# INLINE (!?) #-}
elemIndex :: Char -> ByteString -> Maybe Int64
elemIndex :: Char -> ByteString -> Maybe Int64
elemIndex = Word8 -> ByteString -> Maybe Int64
L.elemIndex (Word8 -> ByteString -> Maybe Int64)
-> (Char -> Word8) -> Char -> ByteString -> Maybe Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE elemIndex #-}
elemIndexEnd :: Char -> ByteString -> Maybe Int64
elemIndexEnd :: Char -> ByteString -> Maybe Int64
elemIndexEnd = Word8 -> ByteString -> Maybe Int64
L.elemIndexEnd (Word8 -> ByteString -> Maybe Int64)
-> (Char -> Word8) -> Char -> ByteString -> Maybe Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE elemIndexEnd #-}
elemIndices :: Char -> ByteString -> [Int64]
elemIndices :: Char -> ByteString -> [Int64]
elemIndices = Word8 -> ByteString -> [Int64]
L.elemIndices (Word8 -> ByteString -> [Int64])
-> (Char -> Word8) -> Char -> ByteString -> [Int64]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
{-# INLINE elemIndices #-}
findIndex :: (Char -> Bool) -> ByteString -> Maybe Int64
findIndex :: (Char -> Bool) -> ByteString -> Maybe Int64
findIndex Char -> Bool
f = (Word8 -> Bool) -> ByteString -> Maybe Int64
L.findIndex (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE findIndex #-}
findIndexEnd :: (Char -> Bool) -> ByteString -> Maybe Int64
findIndexEnd :: (Char -> Bool) -> ByteString -> Maybe Int64
findIndexEnd Char -> Bool
f = (Word8 -> Bool) -> ByteString -> Maybe Int64
L.findIndexEnd (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE findIndexEnd #-}
findIndices :: (Char -> Bool) -> ByteString -> [Int64]
findIndices :: (Char -> Bool) -> ByteString -> [Int64]
findIndices Char -> Bool
f = (Word8 -> Bool) -> ByteString -> [Int64]
L.findIndices (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE findIndices #-}
count :: Char -> ByteString -> Int64
count :: Char -> ByteString -> Int64
count Char
c = Word8 -> ByteString -> Int64
L.count (Char -> Word8
c2w Char
c)
elem :: Char -> ByteString -> Bool
elem :: Char -> ByteString -> Bool
elem Char
c = Word8 -> ByteString -> Bool
L.elem (Char -> Word8
c2w Char
c)
{-# INLINE elem #-}
notElem :: Char -> ByteString -> Bool
notElem :: Char -> ByteString -> Bool
notElem Char
c = Word8 -> ByteString -> Bool
L.notElem (Char -> Word8
c2w Char
c)
{-# INLINE notElem #-}
filter :: (Char -> Bool) -> ByteString -> ByteString
filter :: (Char -> Bool) -> ByteString -> ByteString
filter Char -> Bool
f = (Word8 -> Bool) -> ByteString -> ByteString
L.filter (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE filter #-}
partition :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
partition :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
partition Char -> Bool
f = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
L.partition (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
{-# INLINE partition #-}
find :: (Char -> Bool) -> ByteString -> Maybe Char
find :: (Char -> Bool) -> ByteString -> Maybe Char
find Char -> Bool
f ByteString
ps = Word8 -> Char
w2c (Word8 -> Char) -> Maybe Word8 -> Maybe Char
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` (Word8 -> Bool) -> ByteString -> Maybe Word8
L.find (Char -> Bool
f (Char -> Bool) -> (Word8 -> Char) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c) ByteString
ps
{-# INLINE find #-}
zip :: ByteString -> ByteString -> [(Char,Char)]
zip :: ByteString -> ByteString -> [(Char, Char)]
zip ByteString
ps ByteString
qs
| ByteString -> Bool
L.null ByteString
ps Bool -> Bool -> Bool
|| ByteString -> Bool
L.null ByteString
qs = []
| Bool
otherwise = (ByteString -> Char
head ByteString
ps, ByteString -> Char
head ByteString
qs) (Char, Char) -> [(Char, Char)] -> [(Char, Char)]
forall a. a -> [a] -> [a]
: ByteString -> ByteString -> [(Char, Char)]
zip (HasCallStack => ByteString -> ByteString
ByteString -> ByteString
L.tail ByteString
ps) (HasCallStack => ByteString -> ByteString
ByteString -> ByteString
L.tail ByteString
qs)
zipWith :: (Char -> Char -> a) -> ByteString -> ByteString -> [a]
zipWith :: forall a. (Char -> Char -> a) -> ByteString -> ByteString -> [a]
zipWith Char -> Char -> a
f = (Word8 -> Word8 -> a) -> ByteString -> ByteString -> [a]
forall a. (Word8 -> Word8 -> a) -> ByteString -> ByteString -> [a]
L.zipWith (((Char -> a) -> (Word8 -> Char) -> Word8 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c) ((Char -> a) -> Word8 -> a)
-> (Word8 -> Char -> a) -> Word8 -> Word8 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Char -> a
f (Char -> Char -> a) -> (Word8 -> Char) -> Word8 -> Char -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Char
w2c)
packZipWith :: (Char -> Char -> Char) -> ByteString -> ByteString -> ByteString
packZipWith :: (Char -> Char -> Char) -> ByteString -> ByteString -> ByteString
packZipWith Char -> Char -> Char
f = (Word8 -> Word8 -> Word8) -> ByteString -> ByteString -> ByteString
L.packZipWith Word8 -> Word8 -> Word8
f'
where
f' :: Word8 -> Word8 -> Word8
f' Word8
c1 Word8
c2 = Char -> Word8
c2w (Char -> Word8) -> Char -> Word8
forall a b. (a -> b) -> a -> b
$ Char -> Char -> Char
f (Word8 -> Char
w2c Word8
c1) (Word8 -> Char
w2c Word8
c2)
{-# INLINE packZipWith #-}
unzip :: [(Char, Char)] -> (ByteString, ByteString)
unzip :: [(Char, Char)] -> (ByteString, ByteString)
unzip [(Char, Char)]
ls = ([Char] -> ByteString
pack (((Char, Char) -> Char) -> [(Char, Char)] -> [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Char, Char) -> Char
forall a b. (a, b) -> a
fst [(Char, Char)]
ls), [Char] -> ByteString
pack (((Char, Char) -> Char) -> [(Char, Char)] -> [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Char, Char) -> Char
forall a b. (a, b) -> b
snd [(Char, Char)]
ls))
{-# INLINE unzip #-}
lines :: ByteString -> [ByteString]
lines :: ByteString -> [ByteString]
lines ByteString
Empty = []
lines (Chunk ByteString
c0 ByteString
cs0) = ByteString -> ByteString -> [ByteString]
loop0 ByteString
c0 ByteString
cs0
where
loop0 :: S.ByteString -> ByteString -> [ByteString]
loop0 :: ByteString -> ByteString -> [ByteString]
loop0 ByteString
c ByteString
cs =
case Word8 -> ByteString -> Maybe Int
B.elemIndex (Char -> Word8
c2w Char
'\n') ByteString
c of
Maybe Int
Nothing -> case ByteString
cs of
ByteString
Empty | ByteString -> Bool
B.null ByteString
c -> []
| Bool
otherwise -> [ByteString -> ByteString -> ByteString
Chunk ByteString
c ByteString
Empty]
(Chunk ByteString
c' ByteString
cs')
| ByteString -> Bool
B.null ByteString
c -> ByteString -> ByteString -> [ByteString]
loop0 ByteString
c' ByteString
cs'
| Bool
otherwise -> ByteString -> [ByteString] -> ByteString -> [ByteString]
loop ByteString
c' [ByteString
c] ByteString
cs'
Just Int
n | Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0 -> ByteString -> ByteString -> ByteString
Chunk (Int -> ByteString -> ByteString
B.unsafeTake Int
n ByteString
c) ByteString
Empty
ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString -> ByteString -> [ByteString]
loop0 (Int -> ByteString -> ByteString
B.unsafeDrop (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) ByteString
c) ByteString
cs
| Bool
otherwise -> ByteString
Empty
ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString -> ByteString -> [ByteString]
loop0 (ByteString -> ByteString
B.unsafeTail ByteString
c) ByteString
cs
loop :: S.ByteString -> [S.ByteString] -> ByteString -> [ByteString]
loop :: ByteString -> [ByteString] -> ByteString -> [ByteString]
loop ByteString
c [ByteString]
line ByteString
cs =
case Word8 -> ByteString -> Maybe Int
B.elemIndex (Char -> Word8
c2w Char
'\n') ByteString
c of
Maybe Int
Nothing ->
case ByteString
cs of
ByteString
Empty -> let !c' :: ByteString
c' = [ByteString] -> ByteString
revChunks (ByteString
c ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
line)
in [ByteString
c']
(Chunk ByteString
c' ByteString
cs') -> ByteString -> [ByteString] -> ByteString -> [ByteString]
loop ByteString
c' (ByteString
c ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
line) ByteString
cs'
Just Int
n ->
let !c' :: ByteString
c' = [ByteString] -> ByteString
revChunks (Int -> ByteString -> ByteString
B.unsafeTake Int
n ByteString
c ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
line)
in ByteString
c' ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString -> ByteString -> [ByteString]
loop0 (Int -> ByteString -> ByteString
B.unsafeDrop (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) ByteString
c) ByteString
cs
unlines :: [ByteString] -> ByteString
unlines :: [ByteString] -> ByteString
unlines = (ByteString -> ByteString -> ByteString)
-> ByteString -> [ByteString] -> ByteString
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr (\ByteString
x ByteString
t -> ByteString
x ByteString -> ByteString -> ByteString
`append` Char -> ByteString -> ByteString
cons Char
'\n' ByteString
t) ByteString
Empty
words :: ByteString -> [ByteString]
words :: ByteString -> [ByteString]
words = (ByteString -> Bool) -> [ByteString] -> [ByteString]
forall a. (a -> Bool) -> [a] -> [a]
List.filter (Bool -> Bool
not (Bool -> Bool) -> (ByteString -> Bool) -> ByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Bool
L.null) ([ByteString] -> [ByteString])
-> (ByteString -> [ByteString]) -> ByteString -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word8 -> Bool) -> ByteString -> [ByteString]
L.splitWith Word8 -> Bool
isSpaceWord8
{-# INLINE words #-}
unwords :: [ByteString] -> ByteString
unwords :: [ByteString] -> ByteString
unwords = ByteString -> [ByteString] -> ByteString
intercalate (Char -> ByteString
singleton Char
' ')
{-# INLINE unwords #-}
readInt :: ByteString -> Maybe (Int, ByteString)
{-# INLINE readInt #-}
readInt :: ByteString -> Maybe (Int, ByteString)
readInt ByteString
Empty = Maybe (Int, ByteString)
forall a. Maybe a
Nothing
readInt (Chunk ByteString
x ByteString
xs) = case Word8 -> Char
w2c (ByteString -> Word8
B.unsafeHead ByteString
x) of
Char
'-' -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
loop Bool
True Int
0 Int
0 (ByteString -> ByteString
B.unsafeTail ByteString
x) ByteString
xs
Char
'+' -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
loop Bool
False Int
0 Int
0 (ByteString -> ByteString
B.unsafeTail ByteString
x) ByteString
xs
Char
_ -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
loop Bool
False Int
0 Int
0 ByteString
x ByteString
xs
where loop :: Bool -> Int -> Int
-> S.ByteString -> ByteString -> Maybe (Int, ByteString)
loop :: Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
loop Bool
neg !Int
i !Int
n !ByteString
c ByteString
cs
| ByteString -> Bool
B.null ByteString
c = case ByteString
cs of
ByteString
Empty -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
forall {a} {p}.
(Eq a, Num a, Num p) =>
Bool -> a -> p -> ByteString -> ByteString -> Maybe (p, ByteString)
end Bool
neg Int
i Int
n ByteString
c ByteString
cs
(Chunk ByteString
c' ByteString
cs') -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
loop Bool
neg Int
i Int
n ByteString
c' ByteString
cs'
| Bool
otherwise =
case ByteString -> Word8
B.unsafeHead ByteString
c of
Word8
w | Word8
w Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0x30
Bool -> Bool -> Bool
&& Word8
w Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0x39 -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
loop Bool
neg (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
(Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
0x30))
(ByteString -> ByteString
B.unsafeTail ByteString
c) ByteString
cs
| Bool
otherwise -> Bool
-> Int
-> Int
-> ByteString
-> ByteString
-> Maybe (Int, ByteString)
forall {a} {p}.
(Eq a, Num a, Num p) =>
Bool -> a -> p -> ByteString -> ByteString -> Maybe (p, ByteString)
end Bool
neg Int
i Int
n ByteString
c ByteString
cs
{-# INLINE end #-}
end :: Bool -> a -> p -> ByteString -> ByteString -> Maybe (p, ByteString)
end Bool
_ a
0 p
_ ByteString
_ ByteString
_ = Maybe (p, ByteString)
forall a. Maybe a
Nothing
end Bool
neg a
_ p
n ByteString
c ByteString
cs = Maybe (p, ByteString)
e
where n' :: p
n' = if Bool
neg then p -> p
forall a. Num a => a -> a
negate p
n else p
n
c' :: ByteString
c' = ByteString -> ByteString -> ByteString
chunk ByteString
c ByteString
cs
e :: Maybe (p, ByteString)
e = p
n' p -> Maybe (p, ByteString) -> Maybe (p, ByteString)
`seq` ByteString
c' ByteString -> Maybe (p, ByteString) -> Maybe (p, ByteString)
`seq` (p, ByteString) -> Maybe (p, ByteString)
forall a. a -> Maybe a
Just (p
n',ByteString
c')
readInteger :: ByteString -> Maybe (Integer, ByteString)
readInteger :: ByteString -> Maybe (Integer, ByteString)
readInteger ByteString
Empty = Maybe (Integer, ByteString)
forall a. Maybe a
Nothing
readInteger (Chunk ByteString
c0 ByteString
cs0) =
case Word8 -> Char
w2c (ByteString -> Word8
B.unsafeHead ByteString
c0) of
Char
'-' -> ByteString -> ByteString -> Maybe (Integer, ByteString)
first (ByteString -> ByteString
B.unsafeTail ByteString
c0) ByteString
cs0 Maybe (Integer, ByteString)
-> ((Integer, ByteString) -> Maybe (Integer, ByteString))
-> Maybe (Integer, ByteString)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Integer
n, ByteString
cs') -> (Integer, ByteString) -> Maybe (Integer, ByteString)
forall (m :: * -> *) a. Monad m => a -> m a
return (-Integer
n, ByteString
cs')
Char
'+' -> ByteString -> ByteString -> Maybe (Integer, ByteString)
first (ByteString -> ByteString
B.unsafeTail ByteString
c0) ByteString
cs0
Char
_ -> ByteString -> ByteString -> Maybe (Integer, ByteString)
first ByteString
c0 ByteString
cs0
where first :: ByteString -> ByteString -> Maybe (Integer, ByteString)
first ByteString
c ByteString
cs
| ByteString -> Bool
B.null ByteString
c = case ByteString
cs of
ByteString
Empty -> Maybe (Integer, ByteString)
forall a. Maybe a
Nothing
(Chunk ByteString
c' ByteString
cs') -> ByteString -> ByteString -> Maybe (Integer, ByteString)
first' ByteString
c' ByteString
cs'
| Bool
otherwise = ByteString -> ByteString -> Maybe (Integer, ByteString)
first' ByteString
c ByteString
cs
first' :: ByteString -> ByteString -> Maybe (Integer, ByteString)
first' ByteString
c ByteString
cs = case ByteString -> Word8
B.unsafeHead ByteString
c of
Word8
w | Word8
w Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0x30 Bool -> Bool -> Bool
&& Word8
w Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0x39 -> (Integer, ByteString) -> Maybe (Integer, ByteString)
forall a. a -> Maybe a
Just ((Integer, ByteString) -> Maybe (Integer, ByteString))
-> (Integer, ByteString) -> Maybe (Integer, ByteString)
forall a b. (a -> b) -> a -> b
$
Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
loop Int
1 (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
0x30) [] (ByteString -> ByteString
B.unsafeTail ByteString
c) ByteString
cs
| Bool
otherwise -> Maybe (Integer, ByteString)
forall a. Maybe a
Nothing
loop :: Int -> Int -> [Integer]
-> S.ByteString -> ByteString -> (Integer, ByteString)
loop :: Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
loop !Int
d !Int
acc [Integer]
ns !ByteString
c ByteString
cs
| ByteString -> Bool
B.null ByteString
c = case ByteString
cs of
ByteString
Empty -> Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
forall {a} {b} {a}.
(Integral a, Integral b, Num a) =>
b -> a -> [a] -> ByteString -> ByteString -> (a, ByteString)
combine Int
d Int
acc [Integer]
ns ByteString
c ByteString
cs
(Chunk ByteString
c' ByteString
cs') -> Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
loop Int
d Int
acc [Integer]
ns ByteString
c' ByteString
cs'
| Bool
otherwise =
case ByteString -> Word8
B.unsafeHead ByteString
c of
Word8
w | Word8
w Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0x30 Bool -> Bool -> Bool
&& Word8
w Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0x39 ->
if Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
9 then Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
loop (Int
dInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
(Int
10Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
acc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
0x30))
[Integer]
ns (ByteString -> ByteString
B.unsafeTail ByteString
c) ByteString
cs
else Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
loop Int
1 (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
0x30)
(Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
acc Integer -> [Integer] -> [Integer]
forall a. a -> [a] -> [a]
: [Integer]
ns)
(ByteString -> ByteString
B.unsafeTail ByteString
c) ByteString
cs
| Bool
otherwise -> Int
-> Int
-> [Integer]
-> ByteString
-> ByteString
-> (Integer, ByteString)
forall {a} {b} {a}.
(Integral a, Integral b, Num a) =>
b -> a -> [a] -> ByteString -> ByteString -> (a, ByteString)
combine Int
d Int
acc [Integer]
ns ByteString
c ByteString
cs
combine :: b -> a -> [a] -> ByteString -> ByteString -> (a, ByteString)
combine b
_ a
acc [] ByteString
c ByteString
cs = a -> ByteString -> ByteString -> (a, ByteString)
forall {a}. a -> ByteString -> ByteString -> (a, ByteString)
end (a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
acc) ByteString
c ByteString
cs
combine b
d a
acc [a]
ns ByteString
c ByteString
cs =
a -> ByteString -> ByteString -> (a, ByteString)
forall {a}. a -> ByteString -> ByteString -> (a, ByteString)
end (a
10a -> b -> a
forall a b. (Num a, Integral b) => a -> b -> a
^b
d a -> a -> a
forall a. Num a => a -> a -> a
* a -> [a] -> a
forall {t}. Num t => t -> [t] -> t
combine1 a
1000000000 [a]
ns a -> a -> a
forall a. Num a => a -> a -> a
+ a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
acc) ByteString
c ByteString
cs
combine1 :: t -> [t] -> t
combine1 t
_ [t
n] = t
n
combine1 t
b [t]
ns = t -> [t] -> t
combine1 (t
bt -> t -> t
forall a. Num a => a -> a -> a
*t
b) ([t] -> t) -> [t] -> t
forall a b. (a -> b) -> a -> b
$ t -> [t] -> [t]
forall {t}. Num t => t -> [t] -> [t]
combine2 t
b [t]
ns
combine2 :: t -> [t] -> [t]
combine2 t
b (t
n:t
m:[t]
ns) = let !t :: t
t = t
nt -> t -> t
forall a. Num a => a -> a -> a
+t
mt -> t -> t
forall a. Num a => a -> a -> a
*t
b in t
t t -> [t] -> [t]
forall a. a -> [a] -> [a]
: t -> [t] -> [t]
combine2 t
b [t]
ns
combine2 t
_ [t]
ns = [t]
ns
end :: a -> ByteString -> ByteString -> (a, ByteString)
end a
n ByteString
c ByteString
cs = let !c' :: ByteString
c' = ByteString -> ByteString -> ByteString
chunk ByteString
c ByteString
cs
in (a
n, ByteString
c')
hPutStrLn :: Handle -> ByteString -> IO ()
hPutStrLn :: Handle -> ByteString -> IO ()
hPutStrLn Handle
h ByteString
ps = Handle -> ByteString -> IO ()
hPut Handle
h ByteString
ps IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Handle -> ByteString -> IO ()
hPut Handle
h (Word8 -> ByteString
L.singleton Word8
0x0a)
putStrLn :: ByteString -> IO ()
putStrLn :: ByteString -> IO ()
putStrLn = Handle -> ByteString -> IO ()
hPutStrLn Handle
stdout
revChunks :: [S.ByteString] -> ByteString
revChunks :: [ByteString] -> ByteString
revChunks = (ByteString -> ByteString -> ByteString)
-> ByteString -> [ByteString] -> ByteString
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((ByteString -> ByteString -> ByteString)
-> ByteString -> ByteString -> ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip ByteString -> ByteString -> ByteString
chunk) ByteString
Empty