Support GHC 9.12
[cabal.git] / Cabal / src / Distribution / Compat / FilePath.hs
blob6e1c7961313269d186d7f8c3c3993f1f745579b2
1 {-# LANGUAGE CPP #-}
2 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
4 module Distribution.Compat.FilePath
5 ( isExtensionOf
6 , stripExtension
7 ) where
9 import Data.List (isSuffixOf, stripPrefix)
10 import System.FilePath
12 #if !MIN_VERSION_filepath(1,4,2)
13 isExtensionOf :: String -> FilePath -> Bool
14 isExtensionOf ext@('.':_) = isSuffixOf ext . takeExtensions
15 isExtensionOf ext = isSuffixOf ('.':ext) . takeExtensions
16 #endif
18 #if !MIN_VERSION_filepath(1,4,1)
19 stripExtension :: String -> FilePath -> Maybe FilePath
20 stripExtension [] path = Just path
21 stripExtension ext@(x:_) path = stripSuffix dotExt path
22 where
23 dotExt = if isExtSeparator x then ext else '.':ext
24 stripSuffix :: Eq a => [a] -> [a] -> Maybe [a]
25 stripSuffix xs ys = fmap reverse $ stripPrefix (reverse xs) (reverse ys)
26 #endif