module YamlUnscrambler.Util.Text where

import qualified Attoparsec.Data as Atto
import qualified Data.Attoparsec.Text as Atto
import YamlUnscrambler.Prelude

deshowIfPossible :: Text -> Text
deshowIfPossible :: Text -> Text
deshowIfPossible Text
a =
  (Text -> Text) -> (Text -> Text) -> Either Text Text -> Text
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Text -> Text -> Text
forall a b. a -> b -> a
const Text
a) Text -> Text
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id (Text -> Either Text Text
deshow Text
a)

deshow :: Text -> Either Text Text
deshow :: Text -> Either Text Text
deshow =
  (String -> Text) -> Either String Text -> Either Text Text
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first String -> Text
forall a. IsString a => String -> a
fromString (Either String Text -> Either Text Text)
-> (Text -> Either String Text) -> Text -> Either Text Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Parser Text -> Text -> Either String Text
forall a. Parser a -> Text -> Either String a
Atto.parseOnly Parser Text
parser
  where
    parser :: Parser Text
parser =
      Parser Text
Atto.show Parser Text -> Parser Text () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text ()
forall t. Chunk t => Parser t ()
Atto.endOfInput