Skip to content

Commit

Permalink
haskell#9, add -<.> as an alias for replaceExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed Nov 10, 2014
1 parent 6854fc2 commit d4a47fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["</>","<.>","-<.>"]


---------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions System/FilePath/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +92,7 @@ import Data.Maybe(isJust, fromJust)
import System.Environment(getEnv)


infixr 7 <.>
infixr 7 <.>, -<.>
infixr 5 </>


Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]`
Expand Down
2 changes: 2 additions & 0 deletions tests/TestGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d4a47fb

Please sign in to comment.