{-# language CPP #-}
{-# language BangPatterns #-}
module Data.Bytes.Text.Utf8
( fromShortText
, toShortText
#if MIN_VERSION_text(2,0,0)
, fromText
#endif
) where
import Data.Bytes.Types (Bytes(Bytes))
import Data.Text.Short (ShortText)
import Data.Text (Text)
import Data.Primitive (ByteArray(ByteArray))
import qualified Data.Text.Short as TS
import qualified Data.Bytes as Bytes
import qualified Data.Text.Internal as I
import qualified Data.Text.Array as A
fromShortText :: ShortText -> Bytes
{-# inline fromShortText #-}
fromShortText :: ShortText -> Bytes
fromShortText = ShortByteString -> Bytes
Bytes.fromShortByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> ShortByteString
TS.toShortByteString
toShortText :: Bytes -> Maybe ShortText
{-# inline toShortText #-}
toShortText :: Bytes -> Maybe ShortText
toShortText !Bytes
b = ShortByteString -> Maybe ShortText
TS.fromShortByteString (Bytes -> ShortByteString
Bytes.toShortByteString Bytes
b)
#if MIN_VERSION_text(2,0,0)
fromText :: Text -> Bytes
{-# inline fromText #-}
fromText (I.Text (A.ByteArray b) off len) = Bytes (ByteArray b) off len
#endif