{-# LANGUAGE CPP #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UnliftedFFITypes #-}
module System.AbstractFilePath.Internal where
import {-# SOURCE #-} System.AbstractFilePath
( isValid )
import System.AbstractFilePath.Types
import System.OsString.Internal
import qualified System.OsString.Internal as OS
import Control.Monad.Catch
( MonadThrow )
import Data.ByteString
( ByteString )
import Language.Haskell.TH
import Language.Haskell.TH.Quote
( QuasiQuoter (..) )
import Language.Haskell.TH.Syntax
( Lift (..), lift )
import System.IO
( TextEncoding )
import System.AbstractFilePath.Encoding ( EncodingException(..) )
toAbstractFilePathUtf :: MonadThrow m => String -> m AbstractFilePath
toAbstractFilePathUtf :: String -> m AbstractFilePath
toAbstractFilePathUtf = String -> m AbstractFilePath
forall (m :: * -> *). MonadThrow m => String -> m AbstractFilePath
toOsStringUtf
toAbstractFilePathEnc :: TextEncoding
-> TextEncoding
-> String
-> Either EncodingException AbstractFilePath
toAbstractFilePathEnc :: TextEncoding
-> TextEncoding
-> String
-> Either EncodingException AbstractFilePath
toAbstractFilePathEnc = TextEncoding
-> TextEncoding
-> String
-> Either EncodingException AbstractFilePath
toOsStringEnc
toAbstractFilePathFS :: String -> IO AbstractFilePath
toAbstractFilePathFS :: String -> IO AbstractFilePath
toAbstractFilePathFS = String -> IO AbstractFilePath
toOsStringFS
fromAbstractFilePathUtf :: MonadThrow m => AbstractFilePath -> m String
fromAbstractFilePathUtf :: AbstractFilePath -> m String
fromAbstractFilePathUtf = AbstractFilePath -> m String
forall (m :: * -> *). MonadThrow m => AbstractFilePath -> m String
fromOsStringUtf
fromAbstractFilePathEnc :: TextEncoding
-> TextEncoding
-> AbstractFilePath
-> Either EncodingException String
fromAbstractFilePathEnc :: TextEncoding
-> TextEncoding
-> AbstractFilePath
-> Either EncodingException String
fromAbstractFilePathEnc = TextEncoding
-> TextEncoding
-> AbstractFilePath
-> Either EncodingException String
fromOsStringEnc
fromAbstractFilePathFS :: AbstractFilePath -> IO String
fromAbstractFilePathFS :: AbstractFilePath -> IO String
fromAbstractFilePathFS = AbstractFilePath -> IO String
fromOsStringFS
bytesToAFP :: MonadThrow m
=> ByteString
-> m AbstractFilePath
bytesToAFP :: ByteString -> m AbstractFilePath
bytesToAFP = ByteString -> m AbstractFilePath
forall (m :: * -> *).
MonadThrow m =>
ByteString -> m AbstractFilePath
OS.bytesToOsString
mkAbstractFilePath :: ByteString -> Q Exp
mkAbstractFilePath :: ByteString -> Q Exp
mkAbstractFilePath ByteString
bs =
case ByteString -> Maybe AbstractFilePath
forall (m :: * -> *).
MonadThrow m =>
ByteString -> m AbstractFilePath
bytesToAFP ByteString
bs of
Just AbstractFilePath
afp' ->
if AbstractFilePath -> Bool
isValid AbstractFilePath
afp'
then AbstractFilePath -> Q Exp
forall t. Lift t => t -> Q Exp
lift AbstractFilePath
afp'
else String -> Q Exp
forall a. HasCallStack => String -> a
error String
"invalid filepath"
Maybe AbstractFilePath
Nothing -> String -> Q Exp
forall a. HasCallStack => String -> a
error String
"invalid encoding"
afp :: QuasiQuoter
afp :: QuasiQuoter
afp = (ByteString -> Q Exp) -> QuasiQuoter
qq ByteString -> Q Exp
mkAbstractFilePath
unpackAFP :: AbstractFilePath -> [OsChar]
unpackAFP :: AbstractFilePath -> [OsChar]
unpackAFP = AbstractFilePath -> [OsChar]
unpackOsString
packAFP :: [OsChar] -> AbstractFilePath
packAFP :: [OsChar] -> AbstractFilePath
packAFP = [OsChar] -> AbstractFilePath
packOsString