module Foreign.Lua.Utf8
( toString
, toText
, fromString
, fromText
) where
import Data.ByteString (ByteString)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as TextEncoding
import qualified Data.Text.Encoding.Error as TextEncoding
toString :: ByteString -> String
toString = T.unpack . toText
{-# INLINABLE toString #-}
toText :: ByteString -> Text
toText = TextEncoding.decodeUtf8With TextEncoding.lenientDecode
{-# INLINABLE toText #-}
fromString :: String -> ByteString
fromString = TextEncoding.encodeUtf8 . T.pack
{-# INLINABLE fromString #-}
fromText :: Text -> ByteString
fromText = TextEncoding.encodeUtf8
{-# INLINABLE fromText #-}