{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Zenacy.HTML.Internal.BS
( BS
, bsEmpty
, bsOnly
, bsLen
, bsPack
, bsUnpack
, bsConcat
, bsIndex
, bsElemIndex
, bsLower
, bsPrefixCI
, bsPart
, bsLast
, bsTake
, bsDrop
, bsUncons
, bcPack
, bcUnpack
) where
import Zenacy.HTML.Internal.Char
import Data.ByteString
( ByteString
)
import qualified Data.ByteString as S
( concat
, drop
, elemIndex
, empty
, isPrefixOf
, index
, last
, length
, map
, pack
, singleton
, take
, uncons
, unpack
)
import qualified Data.ByteString.Char8 as C
( pack
, unpack
)
import Data.Word
( Word8
)
type BS = ByteString
bsEmpty :: BS
bsEmpty :: BS
bsEmpty = BS
S.empty
{-# INLINE bsEmpty #-}
bsOnly :: Word8 -> BS
bsOnly :: Word8 -> BS
bsOnly = Word8 -> BS
S.singleton
{-# INLINE bsOnly #-}
bsLen :: BS -> Int
bsLen :: BS -> Int
bsLen = BS -> Int
S.length
{-# INLINE bsLen #-}
bsPack :: [Word8] -> BS
bsPack :: [Word8] -> BS
bsPack = [Word8] -> BS
S.pack
{-# INLINE bsPack #-}
bsUnpack :: BS -> [Word8]
bsUnpack :: BS -> [Word8]
bsUnpack = BS -> [Word8]
S.unpack
{-# INLINE bsUnpack #-}
bsConcat :: [BS] -> BS
bsConcat :: [BS] -> BS
bsConcat = [BS] -> BS
S.concat
{-# INLINE bsConcat #-}
bsIndex :: BS -> Int -> Word8
bsIndex :: BS -> Int -> Word8
bsIndex = BS -> Int -> Word8
S.index
{-# INLINE bsIndex #-}
bsElemIndex :: Word8 -> BS -> Maybe Int
bsElemIndex :: Word8 -> BS -> Maybe Int
bsElemIndex = Word8 -> BS -> Maybe Int
S.elemIndex
{-# INLINE bsElemIndex #-}
bsLower :: BS -> BS
bsLower :: BS -> BS
bsLower = (Word8 -> Word8) -> BS -> BS
S.map Word8 -> Word8
chrToLower
bsPrefixCI :: BS -> BS -> Bool
bsPrefixCI :: BS -> BS -> Bool
bsPrefixCI BS
x BS
y = BS -> BS
bsLower BS
x BS -> BS -> Bool
`S.isPrefixOf` BS -> BS
bsLower BS
y
bsPart :: Int -> Int -> BS -> BS
bsPart :: Int -> Int -> BS -> BS
bsPart Int
offset Int
len = Int -> BS -> BS
S.take Int
len (BS -> BS) -> (BS -> BS) -> BS -> BS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> BS -> BS
S.drop Int
offset
bsLast :: BS -> Maybe Word8
bsLast :: BS -> Maybe Word8
bsLast BS
x
| BS -> Int
bsLen BS
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 = Word8 -> Maybe Word8
forall a. a -> Maybe a
Just (Word8 -> Maybe Word8) -> Word8 -> Maybe Word8
forall a b. (a -> b) -> a -> b
$ BS -> Word8
S.last BS
x
| Bool
otherwise = Maybe Word8
forall a. Maybe a
Nothing
bsTake :: Int -> BS -> BS
bsTake :: Int -> BS -> BS
bsTake = Int -> BS -> BS
S.take
{-# INLINE bsTake #-}
bsDrop :: Int -> BS -> BS
bsDrop :: Int -> BS -> BS
bsDrop = Int -> BS -> BS
S.drop
{-# INLINE bsDrop #-}
bsUncons :: BS -> Maybe (Word8, BS)
bsUncons :: BS -> Maybe (Word8, BS)
bsUncons = BS -> Maybe (Word8, BS)
S.uncons
{-# INLINE bsUncons #-}
bcPack :: String -> BS
bcPack :: String -> BS
bcPack = String -> BS
C.pack
{-# INLINE bcPack #-}
bcUnpack :: BS -> String
bcUnpack :: BS -> String
bcUnpack = BS -> String
C.unpack
{-# INLINE bcUnpack #-}