{-# LANGUAGE OverloadedStrings #-}
module Test.Tasty.AutoCollect.Utils.Text (
withoutPrefix,
withoutSuffix,
listify,
quoted,
) where
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import qualified Data.Text as Text
withoutPrefix :: Text -> Text -> Text
withoutPrefix :: Text -> Text -> Text
withoutPrefix Text
pre Text
s = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
s (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Maybe Text
Text.stripPrefix Text
pre Text
s
withoutSuffix :: Text -> Text -> Text
withoutSuffix :: Text -> Text -> Text
withoutSuffix Text
post Text
s = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
s (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Maybe Text
Text.stripSuffix Text
post Text
s
listify :: [Text] -> Text
listify :: [Text] -> Text
listify [Text]
xs = Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate Text
", " [Text]
xs Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
quoted :: Text -> Text
quoted :: Text -> Text
quoted Text
s = Text
"\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""