Skip to content

Commit

Permalink
#49, move the docs from combine to </>, which is the one most people use
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed Dec 22, 2015
1 parent a479073 commit a5518ec
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions System/FilePath/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,23 @@ replaceDirectory :: FilePath -> String -> FilePath
replaceDirectory x dir = combineAlways dir (takeFileName x)


-- | Combine two paths, if the second path starts with a path separator or a
-- drive letter, then it returns the second.
-- | An alias for '</>'.
combine :: FilePath -> FilePath -> FilePath
combine a b | hasLeadingPathSeparator b || hasDrive b = b
| otherwise = combineAlways a b

-- | Combine two paths, assuming rhs is NOT absolute.
combineAlways :: FilePath -> FilePath -> FilePath
combineAlways a b | null a = b
| null b = a
| hasTrailingPathSeparator a = a ++ b
| otherwise = case a of
[a1,':'] | isWindows && isLetter a1 -> a ++ b
_ -> a ++ [pathSeparator] ++ b


-- | Combine two paths with a path separator.
-- If the second path starts with a path separator or a drive letter, then it returns the second.
--
-- > Posix: "/directory" </> "file.ext" == "/directory/file.ext"
-- > Windows: "/directory" </> "file.ext" == "/directory\\file.ext"
Expand Down Expand Up @@ -641,21 +656,6 @@ 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 | hasLeadingPathSeparator b || hasDrive b = b
| otherwise = combineAlways a b

-- | Combine two paths, assuming rhs is NOT absolute.
combineAlways :: FilePath -> FilePath -> FilePath
combineAlways a b | null a = b
| null b = a
| hasTrailingPathSeparator a = a ++ b
| otherwise = case a of
[a1,':'] | isWindows && isLetter a1 -> a ++ b
_ -> a ++ [pathSeparator] ++ b


-- | Join two values with a path separator. For examples and caveats see the equivalent function 'combine'.
(</>) :: FilePath -> FilePath -> FilePath
(</>) = combine

Expand Down

0 comments on commit a5518ec

Please sign in to comment.