{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Data.TypedEncoding.Common.Class.Util.StringConstraints where
import qualified Data.List as L
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.String
import Data.Proxy
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as BL8
class ToStrInj str from where
toString :: from -> str
prop_toStringFromString :: forall s . (IsString s, ToStrInj String s) => Proxy s -> String -> Bool
prop_toStringFromString :: Proxy @* s -> String -> Bool
prop_toStringFromString Proxy @* s
_ String
x = String
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== (ToStrInj String s => s -> String
forall str from. ToStrInj str from => from -> str
toString @String @s (s -> String) -> (String -> s) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> s
forall a. IsString a => String -> a
fromString (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String
x)
instance ToStrInj String T.Text where
toString :: Text -> String
toString = Text -> String
T.unpack
instance ToStrInj String TL.Text where
toString :: Text -> String
toString = Text -> String
TL.unpack
instance ToStrInj String String where
toString :: String -> String
toString = String -> String
forall a. a -> a
id
class ToStrInj str from => ToStrIso str from where
prop_fromStringToString :: forall s . (IsString s, ToStrIso String s, Eq s) => s -> Bool
prop_fromStringToString :: s -> Bool
prop_fromStringToString s
x = s
x s -> s -> Bool
forall a. Eq a => a -> a -> Bool
== (IsString s => String -> s
forall a. IsString a => String -> a
fromString @s (String -> s) -> (s -> String) -> s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> String
forall str from. ToStrInj str from => from -> str
toString (s -> s) -> s -> s
forall a b. (a -> b) -> a -> b
$ s
x)
instance ToStrIso String T.Text where
instance ToStrIso String TL.Text where
instance ToStrIso String String where
class Char8Find str where
find :: (Char -> Bool) -> str -> Maybe Char
instance Char8Find String where
find :: (Char -> Bool) -> String -> Maybe Char
find = (Char -> Bool) -> String -> Maybe Char
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
L.find
instance Char8Find T.Text where
find :: (Char -> Bool) -> Text -> Maybe Char
find = (Char -> Bool) -> Text -> Maybe Char
T.find
instance Char8Find TL.Text where
find :: (Char -> Bool) -> Text -> Maybe Char
find = (Char -> Bool) -> Text -> Maybe Char
TL.find
instance Char8Find B.ByteString where
find :: (Char -> Bool) -> ByteString -> Maybe Char
find = (Char -> Bool) -> ByteString -> Maybe Char
B8.find
instance Char8Find BL.ByteString where
find :: (Char -> Bool) -> ByteString -> Maybe Char
find = (Char -> Bool) -> ByteString -> Maybe Char
BL8.find