module Data.Text.Aux where
import Control.Monad (liftM2)
import qualified Data.Text as T (Text, append, cons, intercalate, lines, pack, snoc, unlines, unwords, words)
import Language.C.Pretty (Pretty, pretty)
import Data.Text.Lazy (toStrict)
import Data.Text.Lazy.Builder (toLazyText)
import Data.Text.Lazy.Builder.Int (decimal)
import Text.PrettyPrint.HughesPJ.Ext
import TextShow (showt)
showInt :: Int -> T.Text
showInt = toStrict . toLazyText . decimal
textAp :: String -> T.Text -> T.Text
textAp ap = T.append (flip T.snoc ' ' . T.pack $ ap) . parens
wrapText :: Char -> T.Text -> T.Text
wrapText = liftM2 (.) T.cons (flip T.snoc)
addArrows :: [T.Text] -> T.Text
addArrows = T.intercalate (T.pack " -> ")
unwords2 :: T.Text -> T.Text -> T.Text
unwords2 = appendAfter (T.pack " ")
appendAfter :: T.Text -> T.Text -> T.Text -> T.Text
appendAfter = (T.append .) . T.append
parens :: T.Text -> T.Text
parens = (T.cons '(') . (flip T.snoc ')')
wordLines :: T.Text -> [[T.Text]]
wordLines = map T.words . T.lines
unWordLines :: [[T.Text]] -> T.Text
unWordLines = T.unlines . map T.unwords
packUnlines :: [String] -> T.Text
packUnlines = T.unlines . map T.pack
packUnwords :: [String] -> T.Text
packUnwords = T.unwords . map T.pack
prettyShowt :: Pretty p => p -> T.Text
prettyShowt = showt . pretty