-isAbsolutePath _ = False\r
-\r
--- | Gets this path and all its parents.\r
--- The function is useful in case if you want to create \r
--- some file but you aren\'t sure whether all directories \r
--- in the path exists or if you want to search upward for some file.\r
--- \r
--- Some examples:\r
---\r
--- \[Posix\]\r
---\r
--- > pathParents "/" == ["/"]\r
--- > pathParents "/dir1" == ["/", "/dir1"]\r
--- > pathParents "/dir1/dir2" == ["/", "/dir1", "/dir1/dir2"]\r
--- > pathParents "dir1" == [".", "dir1"]\r
--- > pathParents "dir1/dir2" == [".", "dir1", "dir1/dir2"]\r
---\r
--- In the above examples \"\/\" isn\'t included in the list \r
--- because you can\'t create root directory.\r
---\r
--- \[Windows\]\r
---\r
--- > pathParents "c:" == ["c:."]\r
--- > pathParents "c:\\" == ["c:\\"]\r
--- > pathParents "c:\\dir1" == ["c:\\", "c:\\dir1"]\r
--- > pathParents "c:\\dir1\\dir2" == ["c:\\", "c:\\dir1", "c:\\dir1\\dir2"]\r
--- > pathParents "c:dir1" == ["c:.","c:dir1"]\r
--- > pathParents "dir1\\dir2" == [".", "dir1", "dir1\\dir2"]\r
---\r
--- Note that if the file is relative then the the current directory (\".\") \r
--- will be explicitly listed.\r
-pathParents :: FilePath -> [FilePath]\r
-pathParents p =\r
- root'' : map ((++) root') (dropEmptyPath $ inits path')\r
- where\r
-#ifdef mingw32_TARGET_OS\r
- (root,path) = case break (== ':') p of\r
- (path, "") -> ("",path)\r
- (root,_:path) -> (root++":",path)\r
-#else\r
- (root,path) = ("",p)\r
-#endif\r
- (root',root'',path') = case path of\r
- (c:path) | isPathSeparator c -> (root++[pathSeparator],root++[pathSeparator],path)\r
- _ -> (root ,root++"." ,path)\r
-\r
- dropEmptyPath ("":paths) = paths\r
- dropEmptyPath paths = paths\r
-\r
- inits :: String -> [String]\r
- inits [] = [""]\r
- inits cs = \r
- case pre of\r
- "." -> inits suf\r
- ".." -> map (joinFileName pre) (dropEmptyPath $ inits suf)\r
- _ -> "" : map (joinFileName pre) (inits suf)\r
- where\r
- (pre,suf) = case break isPathSeparator cs of\r
- (pre,"") -> (pre, "")\r
- (pre,_:suf) -> (pre,suf)\r
-\r
--- | Given a list of file paths, returns the longest common parent.\r
+isAbsolutePath _ = False
+
+-- | Gets this path and all its parents.
+-- The function is useful in case if you want to create
+-- some file but you aren\'t sure whether all directories
+-- in the path exists or if you want to search upward for some file.
+--
+-- Some examples:
+--
+-- \[Posix\]
+--
+-- > pathParents "/" == ["/"]
+-- > pathParents "/dir1" == ["/", "/dir1"]
+-- > pathParents "/dir1/dir2" == ["/", "/dir1", "/dir1/dir2"]
+-- > pathParents "dir1" == [".", "dir1"]
+-- > pathParents "dir1/dir2" == [".", "dir1", "dir1/dir2"]
+--
+-- In the above examples \"\/\" isn\'t included in the list
+-- because you can\'t create root directory.
+--
+-- \[Windows\]
+--
+-- > pathParents "c:" == ["c:."]
+-- > pathParents "c:\\" == ["c:\\"]
+-- > pathParents "c:\\dir1" == ["c:\\", "c:\\dir1"]
+-- > pathParents "c:\\dir1\\dir2" == ["c:\\", "c:\\dir1", "c:\\dir1\\dir2"]
+-- > pathParents "c:dir1" == ["c:.","c:dir1"]
+-- > pathParents "dir1\\dir2" == [".", "dir1", "dir1\\dir2"]
+--
+-- Note that if the file is relative then the the current directory (\".\")
+-- will be explicitly listed.
+pathParents :: FilePath -> [FilePath]
+pathParents p =
+ root'' : map ((++) root') (dropEmptyPath $ inits path')
+ where
+#ifdef mingw32_TARGET_OS
+ (root,path) = case break (== ':') p of
+ (path, "") -> ("",path)
+ (root,_:path) -> (root++":",path)
+#else
+ (root,path) = ("",p)
+#endif
+ (root',root'',path') = case path of
+ (c:path) | isPathSeparator c -> (root++[pathSeparator],root++[pathSeparator],path)
+ _ -> (root ,root++"." ,path)
+
+ dropEmptyPath ("":paths) = paths
+ dropEmptyPath paths = paths
+
+ inits :: String -> [String]
+ inits [] = [""]
+ inits cs =
+ case pre of
+ "." -> inits suf
+ ".." -> map (joinFileName pre) (dropEmptyPath $ inits suf)
+ _ -> "" : map (joinFileName pre) (inits suf)
+ where
+ (pre,suf) = case break isPathSeparator cs of
+ (pre,"") -> (pre, "")
+ (pre,_:suf) -> (pre,suf)
+
+-- | Given a list of file paths, returns the longest common parent.