uniform-fileio-0.1.5.2: Uniform/Filenames.hs
-------------------------------------------------------------------
--
-- Module : Filenames
-- Copyright : andrew u frank -
--
----------------------------------------------------------------------
-- {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
-- {-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
-- {-# LANGUAGE TypeSynonymInstances #-}
-- {-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
-- {-# OPTIONS_GHC -Wno-deprecations #-}
-- | the operations on filenames and extensions
-- uses the Path library, but wraps it in Path (to construct a read)
-- is a class except for the make
-- todo : there is too much slack in overloading FilePath and Path
-- remove unPath
-- check with the Path module from Shake!
module Uniform.Filenames
( module Uniform.Filenames,
module Uniform.Error,
)
where
import Uniform.Error(ErrIO, callIO)
-- import Uniform.Zero(Zeros(..))
import Uniform.Strings
-- (Text, fromJustNote, t2s)
-- import Uniform.PathShowCase ()
import Uniform.FilenameAlgebra
import qualified System.FilePath as S
takeBaseName' :: FilePath -> FilePath
takeBaseName' = S.takeBaseName
newtype Extension = Extension FilePath deriving (Show, Read, Eq, Ord)
unExtension :: Extension -> FilePath
unExtension (Extension e) = e
makeExtension :: FilePath -> Extension
makeExtension = Extension
-- extension does not include a leading "."
-- would need a makeExtension in IO to catch errors here
makeExtensionT :: Text -> Extension
makeExtensionT = Extension . t2s
instance Filenames FilePath FilePath where
getFileName = snd . S.splitFileName
instance Filenames1 FilePath where
getNakedFileName = removeExtension . getFileName
getImmediateParentDir = (!! 1) . reverse . S.splitDirectories
getParentDir = S.takeDirectory
getNakedDir = (!! 0) . reverse . S.splitDirectories
-- instance Filenames2 FilePath FilePath FilePath where
-- (</>) = S.combine
-- instance Filenames3 FilePath FilePath where
-- type FileResultT FilePath FilePath = FilePath
-- addFileName = S.combine
-- instance Filenames4 FilePath FilePath where
-- type FileResultT4 FilePath FilePath = FilePath
-- addDir p d = if null' d then p else p </> d
instance Extensions FilePath where
type ExtensionType FilePath = FilePath
getExtension = removeChar '.' . snd . S.splitExtension
addExtension e fp = fp S.<.> e
removeExtension = fst . S.splitExtension
-- setExtension e = addExtension e . removeExtension
-- hasExtension e = (e ==) . getExtension