[commit: packages/filepath] master: #9, add -<.> as an alias for replaceExtension (d4a47fb)
git at git.haskell.org
git at git.haskell.org
Thu Mar 19 11:37:22 UTC 2015
Repository : ssh://git@git.haskell.org/filepath
On branch : master
Link : http://git.haskell.org/packages/filepath.git/commitdiff/d4a47fb1b28e5fd23388e05f12633eca0b36f519
>---------------------------------------------------------------
commit d4a47fb1b28e5fd23388e05f12633eca0b36f519
Author: Neil Mitchell <ndmitchell at gmail.com>
Date: Mon Nov 10 07:33:44 2014 +0000
#9, add -<.> as an alias for replaceExtension
>---------------------------------------------------------------
d4a47fb1b28e5fd23388e05f12633eca0b36f519
Generate.hs | 2 +-
System/FilePath/Internal.hs | 10 ++++++++--
changelog.md | 2 ++
tests/TestGen.hs | 2 ++
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/Generate.hs b/Generate.hs
index 573866a..649f510 100755
--- a/Generate.hs
+++ b/Generate.hs
@@ -84,7 +84,7 @@ qualify pw str
where
prelude = ["elem","uncurry","snd","fst","not","null","if","then","else"
,"True","False","concat","isPrefixOf","isSuffixOf"]
- fpops = ["</>","<.>"]
+ fpops = ["</>","<.>","-<.>"]
---------------------------------------------------------------------
diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index af20ad6..e97bba5 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -58,7 +58,7 @@ module System.FilePath.MODULE_NAME
-- * Extension methods
splitExtension,
- takeExtension, replaceExtension, dropExtension, addExtension, hasExtension, (<.>),
+ takeExtension, replaceExtension, (-<.>), dropExtension, addExtension, hasExtension, (<.>),
splitExtensions, dropExtensions, takeExtensions,
-- * Drive methods
@@ -92,7 +92,7 @@ import Data.Maybe(isJust, fromJust)
import System.Environment(getEnv)
-infixr 7 <.>
+infixr 7 <.>, -<.>
infixr 5 </>
@@ -228,6 +228,12 @@ splitExtension x = case nameDot of
takeExtension :: FilePath -> String
takeExtension = snd . splitExtension
+-- | Remove the current extension and add another, an alias for 'replaceExtension'.
+--
+-- > "foo.o" -<.> "c" == "foo.c"
+(-<.>) :: FilePath -> String -> FilePath
+(-<.>) = replaceExtension
+
-- | Set the extension of a file, overwriting one if already present.
--
-- > replaceExtension "file.txt" ".bob" == "file.bob"
diff --git a/changelog.md b/changelog.md
index 807c652..f8e14f1 100644
--- a/changelog.md
+++ b/changelog.md
@@ -6,6 +6,8 @@ _Note: below all `FilePath` values are unquoted, so `\\` really means two backsl
* Bundled with GHC 7.10.1
+ * New function: Add `-<.>` as an alias for `replaceExtension`.
+
* Semantic change: `joinDrive /foo bar` now returns `/foo/bar`, instead of `/foobar`
* Semantic change: on Windows, `splitSearchPath File1;\"File 2\"` now returns `[File1,File2]` instead of `[File1,\"File2\"]`
diff --git a/tests/TestGen.hs b/tests/TestGen.hs
index 7bae497..014275f 100755
--- a/tests/TestGen.hs
+++ b/tests/TestGen.hs
@@ -52,6 +52,8 @@ tests =
,("W.takeExtension (W.addExtension x \"ext\") == \".ext\"", test $ \(QFilePathValidW x) -> W.takeExtension (W.addExtension x "ext") == ".ext")
,("P.takeExtension (P.replaceExtension x \"ext\") == \".ext\"", test $ \(QFilePathValidP x) -> P.takeExtension (P.replaceExtension x "ext") == ".ext")
,("W.takeExtension (W.replaceExtension x \"ext\") == \".ext\"", test $ \(QFilePathValidW x) -> W.takeExtension (W.replaceExtension x "ext") == ".ext")
+ ,("\"foo.o\" P.-<.> \"c\" == \"foo.c\"", test $ "foo.o" P.-<.> "c" == "foo.c")
+ ,("\"foo.o\" W.-<.> \"c\" == \"foo.c\"", test $ "foo.o" W.-<.> "c" == "foo.c")
,("P.replaceExtension \"file.txt\" \".bob\" == \"file.bob\"", test $ P.replaceExtension "file.txt" ".bob" == "file.bob")
,("W.replaceExtension \"file.txt\" \".bob\" == \"file.bob\"", test $ W.replaceExtension "file.txt" ".bob" == "file.bob")
,("P.replaceExtension \"file.txt\" \"bob\" == \"file.bob\"", test $ P.replaceExtension "file.txt" "bob" == "file.bob")
More information about the ghc-commits
mailing list