Skip to content

Commit 80157ac

Browse files
committed
Expose/add combineAlways and (</>)
1 parent 4808d14 commit 80157ac

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

Generate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ qualify pw str
8787
where
8888
prelude = ["elem","uncurry","snd","fst","not","null","if","then","else"
8989
,"True","False","Just","Nothing","fromJust","concat","isPrefixOf","isSuffixOf","any","foldr"]
90-
fpops = ["</>","<.>","-<.>"]
90+
fpops = ["<\\>", "</>","<.>","-<.>"]
9191

9292

9393
---------------------------------------------------------------------

System/FilePath.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module System.FilePath(
8585
takeBaseName, replaceBaseName,
8686
takeDirectory, replaceDirectory,
8787
combine, (</>),
88+
combineAlways, (<\>),
8889
splitPath, joinPath, splitDirectories,
8990

9091
-- * Drive functions
@@ -131,6 +132,7 @@ module System.FilePath(
131132
takeBaseName, replaceBaseName,
132133
takeDirectory, replaceDirectory,
133134
combine, (</>),
135+
combineAlways, (<\>),
134136
splitPath, joinPath, splitDirectories,
135137

136138
-- * Drive functions

System/FilePath/Internal.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module System.FilePath.MODULE_NAME
8484
takeBaseName, replaceBaseName,
8585
takeDirectory, replaceDirectory,
8686
combine, (</>),
87+
combineAlways, (<\>),
8788
splitPath, joinPath, splitDirectories,
8889

8990
-- * Drive functions
@@ -117,6 +118,7 @@ import System.Environment(getEnv)
117118

118119
infixr 7 <.>, -<.>
119120
infixr 5 </>
121+
infixr 5 <\>
120122

121123

122124

@@ -744,6 +746,24 @@ combineAlways a b | null a = b
744746
(</>) = combine
745747

746748

749+
-- | Combine two paths, assuming rhs is NOT absolute.
750+
--
751+
-- > Posix: "/directory" <\> "file.ext" == "/directory/file.ext"
752+
-- > Windows: "/directory" <\> "file.ext" == "/directory\\file.ext"
753+
-- > Valid x => (takeDirectory x <\> takeFileName x) `equalFilePath` x
754+
-- > Posix: "/" <\> "test" == "/test"
755+
-- > Posix: "home" <\> "bob" == "home/bob"
756+
-- > Posix: "x:" <\> "foo" == "x:/foo"
757+
-- > Windows: "C:\\foo" <\> "bar" == "C:\\foo\\bar"
758+
-- > Windows: "home" <\> "bob" == "home\\bob"
759+
-- > Posix: "home" <\> "/bob" == "home//bob"
760+
-- > Windows: "home" <\> "C:\\bob" == "home\\C:\\bob"
761+
-- > Windows: "D:\\foo" <\> "C:bar" == "D:\\foo\\C:bar"
762+
-- > Windows: "C:\\foo" <\> "C:bar" == "C:\\foo\\C:bar"
763+
(<\>) :: FilePath -> FilePath -> FilePath
764+
(<\>) = combineAlways
765+
766+
747767
-- | Split a path by the directory separator.
748768
--
749769
-- > splitPath "/directory/file.ext" == ["/","directory/","file.ext"]

System/FilePath/Posix.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module System.FilePath.Posix
8484
takeBaseName, replaceBaseName,
8585
takeDirectory, replaceDirectory,
8686
combine, (</>),
87+
combineAlways, (<\>),
8788
splitPath, joinPath, splitDirectories,
8889

8990
-- * Drive functions
@@ -117,6 +118,7 @@ import System.Environment(getEnv)
117118

118119
infixr 7 <.>, -<.>
119120
infixr 5 </>
121+
infixr 5 <\>
120122

121123

122124

@@ -744,6 +746,24 @@ combineAlways a b | null a = b
744746
(</>) = combine
745747

746748

749+
-- | Combine two paths, assuming rhs is NOT absolute.
750+
--
751+
-- > Posix: "/directory" <\> "file.ext" == "/directory/file.ext"
752+
-- > Windows: "/directory" <\> "file.ext" == "/directory\\file.ext"
753+
-- > Valid x => (takeDirectory x <\> takeFileName x) `equalFilePath` x
754+
-- > Posix: "/" <\> "test" == "/test"
755+
-- > Posix: "home" <\> "bob" == "home/bob"
756+
-- > Posix: "x:" <\> "foo" == "x:/foo"
757+
-- > Windows: "C:\\foo" <\> "bar" == "C:\\foo\\bar"
758+
-- > Windows: "home" <\> "bob" == "home\\bob"
759+
-- > Posix: "home" <\> "/bob" == "home//bob"
760+
-- > Windows: "home" <\> "C:\\bob" == "home\\C:\\bob"
761+
-- > Windows: "D:\\foo" <\> "C:bar" == "D:\\foo\\C:bar"
762+
-- > Windows: "C:\\foo" <\> "C:bar" == "C:\\foo\\C:bar"
763+
(<\>) :: FilePath -> FilePath -> FilePath
764+
(<\>) = combineAlways
765+
766+
747767
-- | Split a path by the directory separator.
748768
--
749769
-- > splitPath "/directory/file.ext" == ["/","directory/","file.ext"]

System/FilePath/Windows.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module System.FilePath.Windows
8484
takeBaseName, replaceBaseName,
8585
takeDirectory, replaceDirectory,
8686
combine, (</>),
87+
combineAlways, (<\>),
8788
splitPath, joinPath, splitDirectories,
8889

8990
-- * Drive functions
@@ -117,6 +118,7 @@ import System.Environment(getEnv)
117118

118119
infixr 7 <.>, -<.>
119120
infixr 5 </>
121+
infixr 5 <\>
120122

121123

122124

@@ -744,6 +746,24 @@ combineAlways a b | null a = b
744746
(</>) = combine
745747

746748

749+
-- | Combine two paths, assuming rhs is NOT absolute.
750+
--
751+
-- > Posix: "/directory" <\> "file.ext" == "/directory/file.ext"
752+
-- > Windows: "/directory" <\> "file.ext" == "/directory\\file.ext"
753+
-- > Valid x => (takeDirectory x <\> takeFileName x) `equalFilePath` x
754+
-- > Posix: "/" <\> "test" == "/test"
755+
-- > Posix: "home" <\> "bob" == "home/bob"
756+
-- > Posix: "x:" <\> "foo" == "x:/foo"
757+
-- > Windows: "C:\\foo" <\> "bar" == "C:\\foo\\bar"
758+
-- > Windows: "home" <\> "bob" == "home\\bob"
759+
-- > Posix: "home" <\> "/bob" == "home//bob"
760+
-- > Windows: "home" <\> "C:\\bob" == "home\\C:\\bob"
761+
-- > Windows: "D:\\foo" <\> "C:bar" == "D:\\foo\\C:bar"
762+
-- > Windows: "C:\\foo" <\> "C:bar" == "C:\\foo\\C:bar"
763+
(<\>) :: FilePath -> FilePath -> FilePath
764+
(<\>) = combineAlways
765+
766+
747767
-- | Split a path by the directory separator.
748768
--
749769
-- > splitPath "/directory/file.ext" == ["/","directory/","file.ext"]

tests/TestGen.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ tests =
336336
,("\"C:\\\\home\" W.</> \"\\\\bob\" == \"\\\\bob\"", property $ "C:\\home" W.</> "\\bob" == "\\bob")
337337
,("\"D:\\\\foo\" W.</> \"C:bar\" == \"C:bar\"", property $ "D:\\foo" W.</> "C:bar" == "C:bar")
338338
,("\"C:\\\\foo\" W.</> \"C:bar\" == \"C:bar\"", property $ "C:\\foo" W.</> "C:bar" == "C:bar")
339+
,("\"/directory\" P.<\\> \"file.ext\" == \"/directory/file.ext\"", property $ "/directory" P.<\> "file.ext" == "/directory/file.ext")
340+
,("\"/directory\" W.<\\> \"file.ext\" == \"/directory\\\\file.ext\"", property $ "/directory" W.<\> "file.ext" == "/directory\\file.ext")
341+
,("(P.takeDirectory x P.<\\> P.takeFileName x) `P.equalFilePath` x", property $ \(QFilePathValidP x) -> (P.takeDirectory x P.<\> P.takeFileName x) `P.equalFilePath` x)
342+
,("(W.takeDirectory x W.<\\> W.takeFileName x) `W.equalFilePath` x", property $ \(QFilePathValidW x) -> (W.takeDirectory x W.<\> W.takeFileName x) `W.equalFilePath` x)
343+
,("\"/\" P.<\\> \"test\" == \"/test\"", property $ "/" P.<\> "test" == "/test")
344+
,("\"home\" P.<\\> \"bob\" == \"home/bob\"", property $ "home" P.<\> "bob" == "home/bob")
345+
,("\"x:\" P.<\\> \"foo\" == \"x:/foo\"", property $ "x:" P.<\> "foo" == "x:/foo")
346+
,("\"C:\\\\foo\" W.<\\> \"bar\" == \"C:\\\\foo\\\\bar\"", property $ "C:\\foo" W.<\> "bar" == "C:\\foo\\bar")
347+
,("\"home\" W.<\\> \"bob\" == \"home\\\\bob\"", property $ "home" W.<\> "bob" == "home\\bob")
348+
,("\"home\" P.<\\> \"/bob\" == \"home//bob\"", property $ "home" P.<\> "/bob" == "home//bob")
349+
,("\"home\" W.<\\> \"C:\\\\bob\" == \"home\\\\C:\\\\bob\"", property $ "home" W.<\> "C:\\bob" == "home\\C:\\bob")
350+
,("\"D:\\\\foo\" W.<\\> \"C:bar\" == \"D:\\\\foo\\\\C:bar\"", property $ "D:\\foo" W.<\> "C:bar" == "D:\\foo\\C:bar")
351+
,("\"C:\\\\foo\" W.<\\> \"C:bar\" == \"C:\\\\foo\\\\C:bar\"", property $ "C:\\foo" W.<\> "C:bar" == "C:\\foo\\C:bar")
339352
,("P.splitPath \"/directory/file.ext\" == [\"/\", \"directory/\", \"file.ext\"]", property $ P.splitPath "/directory/file.ext" == ["/", "directory/", "file.ext"])
340353
,("W.splitPath \"/directory/file.ext\" == [\"/\", \"directory/\", \"file.ext\"]", property $ W.splitPath "/directory/file.ext" == ["/", "directory/", "file.ext"])
341354
,("concat (P.splitPath x) == x", property $ \(QFilePath x) -> concat (P.splitPath x) == x)

0 commit comments

Comments
 (0)