{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
module Data.Aeson.Internal.Text (
unsafeDecodeASCII,
) where
import Data.ByteString (ByteString)
import qualified Data.Text as T
#if MIN_VERSION_text(2,0,0)
import Data.Text.Array (Array (..))
import qualified Data.Text.Internal as T (Text (..))
import qualified Data.ByteString.Short.Internal as SBS
import Data.Aeson.Internal.ByteString
#else
import qualified Data.Text.Encoding as TE
#endif
unsafeDecodeASCII :: ByteString -> T.Text
#if MIN_VERSION_text(2,0,0)
unsafeDecodeASCII bs = withBS bs $ \_fp len -> if len == 0 then T.empty else
let !(SBS.SBS arr) = SBS.toShort bs in T.Text (ByteArray arr) 0 len
#else
unsafeDecodeASCII :: ByteString -> Text
unsafeDecodeASCII = ByteString -> Text
TE.decodeLatin1
#endif