[commit: packages/filepath] master: Refactor: introduce function hasLeadingPathSeparator for clarity (df3f13e)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:33:55 UTC 2015


Repository : ssh://git@git.haskell.org/filepath

On branch  : master
Link       : http://git.haskell.org/packages/filepath.git/commitdiff/df3f13e7353cdd9ee15e91b475c29aeb72c61c4d

>---------------------------------------------------------------

commit df3f13e7353cdd9ee15e91b475c29aeb72c61c4d
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Sun Sep 14 17:46:28 2014 +0200

    Refactor: introduce function hasLeadingPathSeparator for clarity
    
    Also fix the comment to reflect the code. This fixes #8752.


>---------------------------------------------------------------

df3f13e7353cdd9ee15e91b475c29aeb72c61c4d
 System/FilePath/Internal.hs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index 977eae9..7db6c04 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -511,6 +511,11 @@ hasTrailingPathSeparator "" = False
 hasTrailingPathSeparator x = isPathSeparator (last x)
 
 
+hasLeadingPathSeparator :: FilePath -> Bool
+hasLeadingPathSeparator "" = False
+hasLeadingPathSeparator x = isPathSeparator (head x)
+
+
 -- | Add a trailing file path separator if one is not already present.
 --
 -- > hasTrailingPathSeparator (addTrailingPathSeparator x)
@@ -560,7 +565,8 @@ replaceDirectory :: FilePath -> String -> FilePath
 replaceDirectory x dir = combineAlways dir (takeFileName x)
 
 
--- | Combine two paths, if the second path 'isAbsolute', then it returns the second.
+-- | Combine two paths, if the second path starts with a path separator or a
+-- drive letter, then it returns the second.
 --
 -- > Valid x => combine (takeDirectory x) (takeFileName x) `equalFilePath` x
 --
@@ -593,7 +599,7 @@ replaceDirectory x dir = combineAlways dir (takeFileName x)
 -- > Windows: combine "D:\\foo" "C:bar" == "C:bar"
 -- > Windows: combine "C:\\foo" "C:bar" == "C:bar"
 combine :: FilePath -> FilePath -> FilePath
-combine a b | hasDrive b || (not (null b) && isPathSeparator (head b)) = b
+combine a b | hasLeadingPathSeparator b || hasDrive b = b
             | otherwise = combineAlways a b
 
 -- | Combine two paths, assuming rhs is NOT absolute.



More information about the ghc-commits mailing list