module Haskus.Utils.Text
( module Data.Text
, bufferDecodeUtf8
, textEncodeUtf8
, stringEncodeUtf8
, textFormat
, F.Format
, (F.%)
, (F.%.)
, module Formatting.Formatters
, textParseHexadecimal
, putTextUtf8
, getTextUtf8
, getTextUtf8Nul
, tshow
, T.putStrLn
)
where
import Data.Text hiding (center)
import qualified Data.Text.Encoding as T
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Formatting as F
import Formatting.Formatters
import Data.Text.Read as T
import Haskus.Binary.Buffer
import Haskus.Binary.Put
import Haskus.Binary.Get
bufferDecodeUtf8 :: Buffer -> Text
bufferDecodeUtf8 (Buffer bs) = T.decodeUtf8 bs
textEncodeUtf8 :: Text -> Buffer
textEncodeUtf8 = Buffer . T.encodeUtf8
stringEncodeUtf8 :: String -> Buffer
stringEncodeUtf8 = textEncodeUtf8 . T.pack
textFormat :: Format Text a -> a
textFormat = F.sformat
textParseHexadecimal :: Integral a => Text -> Either String a
textParseHexadecimal s = fst <$> T.hexadecimal s
putTextUtf8 :: Text -> Put
putTextUtf8 = putBuffer . textEncodeUtf8
getTextUtf8 :: Word -> Get Text
getTextUtf8 sz = bufferDecodeUtf8 <$> getBuffer sz
getTextUtf8Nul :: Get Text
getTextUtf8Nul = bufferDecodeUtf8 <$> getBufferNul
tshow :: Show a => a -> Text
tshow = pack . show