{-# LANGUAGE CPP #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UnliftedFFITypes #-}
module System.OsPath.Internal where
import {-# SOURCE #-} System.OsPath
( isValid )
import System.OsPath.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.OsPath.Encoding ( EncodingException(..) )
toOsPathUtf :: MonadThrow m => String -> m OsPath
toOsPathUtf :: String -> m OsPath
toOsPathUtf = String -> m OsPath
forall (m :: * -> *). MonadThrow m => String -> m OsPath
toOsStringUtf
toOsPathEnc :: TextEncoding
-> TextEncoding
-> String
-> Either EncodingException OsPath
toOsPathEnc :: TextEncoding
-> TextEncoding -> String -> Either EncodingException OsPath
toOsPathEnc = TextEncoding
-> TextEncoding -> String -> Either EncodingException OsPath
toOsStringEnc
toOsPathFS :: String -> IO OsPath
toOsPathFS :: String -> IO OsPath
toOsPathFS = String -> IO OsPath
toOsStringFS
fromOsPathUtf :: MonadThrow m => OsPath -> m String
fromOsPathUtf :: OsPath -> m String
fromOsPathUtf = OsPath -> m String
forall (m :: * -> *). MonadThrow m => OsPath -> m String
fromOsStringUtf
fromOsPathEnc :: TextEncoding
-> TextEncoding
-> OsPath
-> Either EncodingException String
fromOsPathEnc :: TextEncoding
-> TextEncoding -> OsPath -> Either EncodingException String
fromOsPathEnc = TextEncoding
-> TextEncoding -> OsPath -> Either EncodingException String
fromOsStringEnc
fromOsPathFS :: OsPath -> IO String
fromOsPathFS :: OsPath -> IO String
fromOsPathFS = OsPath -> IO String
fromOsStringFS
bytesToAFP :: MonadThrow m
=> ByteString
-> m OsPath
bytesToAFP :: ByteString -> m OsPath
bytesToAFP = ByteString -> m OsPath
forall (m :: * -> *). MonadThrow m => ByteString -> m OsPath
OS.bytesToOsString
mkOsPath :: ByteString -> Q Exp
mkOsPath :: ByteString -> Q Exp
mkOsPath ByteString
bs =
case ByteString -> Maybe OsPath
forall (m :: * -> *). MonadThrow m => ByteString -> m OsPath
bytesToAFP ByteString
bs of
Just OsPath
afp' ->
if OsPath -> Bool
isValid OsPath
afp'
then OsPath -> Q Exp
forall t. Lift t => t -> Q Exp
lift OsPath
afp'
else String -> Q Exp
forall a. HasCallStack => String -> a
error String
"invalid filepath"
Maybe OsPath
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
mkOsPath
unpackAFP :: OsPath -> [OsChar]
unpackAFP :: OsPath -> [OsChar]
unpackAFP = OsPath -> [OsChar]
unpackOsString
packAFP :: [OsChar] -> OsPath
packAFP :: [OsChar] -> OsPath
packAFP = [OsChar] -> OsPath
packOsString