@@ -120,7 +120,7 @@ import qualified Data.List as L
120
120
#ifndef OS_PATH
121
121
import Data.String (fromString )
122
122
import System.Environment (getEnv )
123
- import Prelude (String , map , FilePath , Eq , IO , id , last , init , reverse , dropWhile , null , break , takeWhile , take , all , elem , any , head , tail , span )
123
+ import Prelude (String , map , FilePath , Eq , IO , id , last , init , reverse , dropWhile , null , break , takeWhile , take , all , elem , any , span )
124
124
import Data.Char (toLower , toUpper , isAsciiLower , isAsciiUpper )
125
125
import Data.List (stripPrefix , isSuffixOf , uncons )
126
126
#define CHAR Char
@@ -672,9 +672,7 @@ hasTrailingPathSeparator x
672
672
673
673
674
674
hasLeadingPathSeparator :: FILEPATH -> Bool
675
- hasLeadingPathSeparator x
676
- | null x = False
677
- | otherwise = isPathSeparator $ head x
675
+ hasLeadingPathSeparator = maybe False (isPathSeparator . fst ) . uncons
678
676
679
677
680
678
-- | Add a trailing file path separator if one is not already present.
@@ -901,11 +899,21 @@ makeRelative root path
901
899
where (a, b) = break isPathSeparator $ dropWhile isPathSeparator x
902
900
903
901
-- on windows, need to drop '/' which is kind of absolute, but not a drive
904
- dropAbs x | not (null x) && isPathSeparator (head x) && not (hasDrive x) = tail x
905
- dropAbs x = dropDrive x
906
-
907
- takeAbs x | not (null x) && isPathSeparator (head x) && not (hasDrive x) = singleton pathSeparator
908
- takeAbs x = map (\ y -> if isPathSeparator y then pathSeparator else toLower y) $ takeDrive x
902
+ dropAbs x
903
+ | Just (hd, tl) <- uncons x
904
+ , isPathSeparator hd
905
+ , not (hasDrive x)
906
+ = tl
907
+ | otherwise
908
+ = dropDrive x
909
+
910
+ takeAbs x
911
+ | Just (hd, _) <- uncons x
912
+ , isPathSeparator hd
913
+ , not (hasDrive x)
914
+ = singleton pathSeparator
915
+ | otherwise
916
+ = map (\ y -> if isPathSeparator y then pathSeparator else toLower y) $ takeDrive x
909
917
910
918
-- | Normalise a file
911
919
--
0 commit comments