diff --git a/Generate.hs b/Generate.hs index 573866a7..649f510b 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 af20ad62..e97bba5b 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 807c6523..f8e14f15 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 7bae497b..014275f5 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")