Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- type AbsPath = Path Absolute
- type RelPath = Path Relative
- data Path rel = Path {}
- data Absolute = Absolute
- data Relative = Relative
- newtype PathPiece = PathPiece Text
- newtype LastPathPiece = LastPathPiece Text
- newtype Extension = Extension Text
- pathSeparator :: Char
- pathSeparators :: [Char]
- isPathSeparator :: Char -> Bool
- extensionSeparator :: Char
- extensionSeparators :: [Char]
- isExtensionSeparator :: Char -> Bool
- containsSatisfied :: (Char -> Bool) -> Text -> Bool
- containsSeparator :: Text -> Bool
- containsExtension :: Text -> Bool
- relpath :: FilePath -> Maybe RelPath
- abspath :: FilePath -> Maybe AbsPath
- pathpiece :: String -> Maybe PathPiece
- lastpiece :: String -> Maybe LastPathPiece
- ext :: String -> Maybe Extension
- ground :: AbsPath -> FilePath -> Maybe AbsPath
- unsafeRelPathError :: FilePath -> RelPath
- unsafeAbsPathError :: FilePath -> AbsPath
- unsafePathPieceError :: String -> PathPiece
- unsafeLastPieceError :: String -> LastPathPiece
- unsafeExtError :: String -> Extension
- toRelFilePath :: RelPath -> FilePath
- toAbsFilePath :: AbsPath -> FilePath
- takeExtension :: Path rel -> Maybe Extension
- takeExtensions :: Path rel -> [Extension]
- replaceExtensionExact :: Path rel -> Extension -> Maybe (Path rel)
- replaceExtension :: Path rel -> Extension -> Path rel
- (-<.>) :: Path rel -> Extension -> Path rel
- replaceExtensions :: Path rel -> Extension -> Path rel
- replaceExtensionss :: Path rel -> [Extension] -> Path rel
- dropExtensionExact :: Path rel -> Maybe (Path rel)
- dropExtension :: Path rel -> Path rel
- dropExtensions :: Path rel -> Path rel
- addExtension :: Path rel -> Extension -> Path rel
- (<.>) :: Path rel -> Extension -> Path rel
- addExtensions :: Path rel -> [Extension] -> Path rel
- stripExtension :: Path rel -> Extension -> Maybe (Path rel)
- stripExtensions :: Path rel -> [Extension] -> Maybe (Path rel)
- splitExtension :: Path rel -> Maybe (Path rel, Extension)
- splitExtensions :: Path rel -> (Path rel, [Extension])
- hasExtension :: Path rel -> Bool
- splitFileName :: Path rel -> (Path rel, RelPath)
- takeFileNameExact :: Path rel -> Maybe RelPath
- takeFileName :: Path rel -> RelPath
- replaceFileNameExact :: Path rel -> PathPiece -> Maybe (Path rel)
- replaceFileName :: Path rel -> PathPiece -> Path rel
- dropFileNameExact :: Path rel -> Maybe (Path rel)
- dropFileName :: Path rel -> Path rel
- takeBaseNameExact :: Path rel -> Maybe LastPathPiece
- takeBaseName :: Path rel -> LastPathPiece
- replaceBaseNameExact :: Path rel -> LastPathPiece -> Maybe (Path rel)
- replaceBaseName :: Path rel -> LastPathPiece -> Path rel
- replaceDirectoryExact :: Path r -> Path s -> Maybe (Path s)
- replaceDirectory :: Path r -> Path s -> Path s
- combineExact :: Path rel -> RelPath -> Maybe (Path rel)
- combine :: Path rel -> RelPath -> Path rel
- (</>) :: Path rel -> RelPath -> Path rel
- splitPath :: Path rel -> [PathPiece]
- joinPath :: [PathPiece] -> Maybe (Path rel)
- initMay :: [a] -> Maybe [a]
- lastMay :: [a] -> Maybe a
- unsnoc :: [a] -> Maybe ([a], a)
- uncons :: [a] -> Maybe (a, [a])
- isEmptyLastPathPiece :: LastPathPiece -> Bool
- emptyLastPathPiece :: LastPathPiece
- emptyPath :: Path rel
- isEmptyPath :: Path rel -> Bool
- renderPiece :: PathPiece -> String
- renderLastPiece :: LastPathPiece -> String
- renderExtension :: Extension -> String
- renderExtensions :: [Extension] -> String
- combineLastAndExtensions :: LastPathPiece -> [Extension] -> PathPiece
- splitPiece :: PathPiece -> (LastPathPiece, [Extension])
- unsafePathTypeCoerse :: Path rel -> Path rel'
Documentation
Path | |
|
Eq (Path rel) Source # | |
Data rel => Data (Path rel) Source # | |
Show (Path rel) Source # | |
Show (Path Relative) Source # | |
Show (Path Absolute) Source # | |
IsString (Path Relative) Source # | ONLY for |
IsString (Path Absolute) Source # | ONLY for |
Generic (Path rel) Source # | |
Validity (Path rel) Source # | |
type Rep (Path rel) Source # | |
newtype LastPathPiece Source #
Eq LastPathPiece Source # | |
Data LastPathPiece Source # | |
Show LastPathPiece Source # | |
IsString LastPathPiece Source # | ONLY for |
Generic LastPathPiece Source # | |
Validity LastPathPiece Source # | |
type Rep LastPathPiece Source # | |
pathSeparator :: Char Source #
pathSeparators :: [Char] Source #
isPathSeparator :: Char -> Bool Source #
Check if a given character is a valid path separator
>>>
isPathSeparator pathSeparator
True>>>
all isPathSeparator pathSeparators
True
extensionSeparators :: [Char] Source #
isExtensionSeparator :: Char -> Bool Source #
Check if a given character is a valid extension separator
>>>
isExtensionSeparator extensionSeparator
True>>>
all isExtensionSeparator extensionSeparators
True
containsSeparator :: Text -> Bool Source #
containsExtension :: Text -> Bool Source #
pathpiece :: String -> Maybe PathPiece Source #
Construct a path piece safely
>>>
pathpiece "file"
Just file>>>
pathpiece "with.dot"
Just with.dot>>>
pathpiece "with/slash"
Nothing
lastpiece :: String -> Maybe LastPathPiece Source #
Construct a last path piece safely
>>>
lastpiece "file"
Just file>>>
lastpiece "with.dot"
Nothing
ext :: String -> Maybe Extension Source #
Construct an extension safely
>>>
ext "extension"
Just extension>>>
ext ".ext"
Nothing>>>
ext ""
Nothing
ground :: AbsPath -> FilePath -> Maybe AbsPath Source #
Ground a filepath on an absolute path.
This will try to parse the given FilePath
as an absolute path and take it
if that works. Otherwise it will try to parse it an a relative path and
append it to the given AbsPath
>>>
ground "/home/user" "relative/path"
Just /home/user/relative/path>>>
ground "/home/user" "/absolute/path"
Just /absolute/path>>>
ground "/home/user" "."
Just /home/user>>>
ground "/home/user" "/"
Just />>>
ground "/" "."
Just />>>
ground "/anything" ""
Nothing
unsafeRelPathError :: FilePath -> RelPath Source #
unsafeAbsPathError :: FilePath -> AbsPath Source #
unsafeExtError :: String -> Extension Source #
takeExtension :: Path rel -> Maybe Extension Source #
Take the last extension of a filepath
>>>
takeExtension ("/directory/path.ext" :: AbsPath)
Just ext>>>
takeExtension ("file.tar.gz" :: RelPath)
Just gz>>>
takeExtension ("file" :: RelPath)
Nothing
Replaces System.FilePath.takeExtension
takeExtensions :: Path rel -> [Extension] Source #
Take all extensions of a given path in the form of a list
>>>
takeExtensions ("/directory/path.ext" :: AbsPath)
[ext]>>>
takeExtensions ("file.tar.gz" :: RelPath)
[tar,gz]
Replaces System.FilePath.takeExtensions
replaceExtensionExact :: Path rel -> Extension -> Maybe (Path rel) Source #
Replace the last extension of a path, exactly
This will fail if the given path has no extension
>>>
replaceExtensionExact "dir/file.ext1.ext2" "ext3" :: Maybe RelPath
Just dir/file.ext1.ext3>>>
replaceExtensionExact "dir/file.ext1" "ext2" :: Maybe RelPath
Just dir/file.ext2>>>
replaceExtensionExact "dir/file" "ext" :: Maybe RelPath
Nothing>>>
replaceExtensionExact "/dir/file.ext1.ext2" "ext3" :: Maybe AbsPath
Just /dir/file.ext1.ext3>>>
replaceExtensionExact "/dir/file.ext1" "ext2" :: Maybe AbsPath
Just /dir/file.ext2>>>
replaceExtensionExact "/dir/file" "ext" :: Maybe AbsPath
Nothing>>>
replaceExtensionExact "." "ext" :: Maybe RelPath
Nothing>>>
replaceExtensionExact "/" "ext" :: Maybe AbsPath
Nothing
replaceExtension :: Path rel -> Extension -> Path rel Source #
Replace the last extension of a path
This will first remove one extension and then add the given extension.
replaceExtension path extension = dropExtension path <.> extension
>>>
replaceExtension "dir/file.ext1.ext2" "ext3" :: RelPath
dir/file.ext1.ext3>>>
replaceExtension "dir/file.ext1" "ext2" :: RelPath
dir/file.ext2>>>
replaceExtension "dir/file" "ext" :: RelPath
dir/file.ext>>>
replaceExtension "/dir/file.ext1.ext2" "ext3" :: AbsPath
/dir/file.ext1.ext3>>>
replaceExtension "/dir/file.ext1" "ext2" :: AbsPath
/dir/file.ext2>>>
replaceExtension "/dir/file" "ext" :: AbsPath
/dir/file.ext>>>
replaceExtension "." "ext" :: RelPath
.>>>
replaceExtension "/" "ext" :: AbsPath
/
Replaces System.FilePath.replaceExtension
(-<.>) :: Path rel -> Extension -> Path rel Source #
Replace the last extension of a path (equivalent to replaceExtension
)
>>>
"dir/file.ext1.ext2" -<.> "ext3" :: RelPath
dir/file.ext1.ext3>>>
"dir/file.ext1" -<.> "ext2" :: RelPath
dir/file.ext2>>>
"dir/file" -<.> "ext" :: RelPath
dir/file.ext>>>
"/dir/file.ext1.ext2" -<.> "ext3" :: AbsPath
/dir/file.ext1.ext3>>>
"/dir/file.ext1" -<.> "ext2" :: AbsPath
/dir/file.ext2>>>
"/dir/file" -<.> "ext" :: AbsPath
/dir/file.ext>>>
"." -<.> "ext" :: RelPath
.>>>
"/" -<.> "ext" :: AbsPath
/
Replaces System.FilePath.(-.)
replaceExtensions :: Path rel -> Extension -> Path rel Source #
Replace all the extensions of a path with the given extension
>>>
replaceExtensions "dir/file.ext1.ext2" "ext3" :: RelPath
dir/file.ext3>>>
replaceExtensions "dir/file.ext1" "ext3" :: RelPath
dir/file.ext3>>>
replaceExtensions "dir/file" "ext3" :: RelPath
dir/file.ext3>>>
replaceExtensions "/dir/file.ext1.ext2" "ext3" :: AbsPath
/dir/file.ext3>>>
replaceExtensions "/dir/file.ext1" "ext3" :: AbsPath
/dir/file.ext3>>>
replaceExtensions "/dir/file" "ext3" :: AbsPath
/dir/file.ext3>>>
replaceExtensions "." "ext" :: RelPath
.>>>
replaceExtensions "/" "ext" :: AbsPath
/
replaceExtensionss :: Path rel -> [Extension] -> Path rel Source #
Replace all the extensions of a path with the given list of extensions
>>>
replaceExtensionss "dir/file.ext1.ext2" ["ext3", "ext4"] :: RelPath
dir/file.ext3.ext4>>>
replaceExtensionss "dir/file.ext1" ["ext3", "ext4"] :: RelPath
dir/file.ext3.ext4>>>
replaceExtensionss "dir/file" ["ext3", "ext4"] :: RelPath
dir/file.ext3.ext4>>>
replaceExtensionss "/dir/file.ext1.ext2" ["ext3", "ext4"] :: AbsPath
/dir/file.ext3.ext4>>>
replaceExtensionss "/dir/file.ext1" ["ext3", "ext4"] :: AbsPath
/dir/file.ext3.ext4>>>
replaceExtensionss "/dir/file" ["ext3", "ext4"] :: AbsPath
/dir/file.ext3.ext4>>>
replaceExtensionss "." ["ext1", "ext2"] :: RelPath
.>>>
replaceExtensionss "/" ["ext1", "ext2"] :: AbsPath
/
dropExtensionExact :: Path rel -> Maybe (Path rel) Source #
Drop the last extension of a path, exactly
This will fail if the given path has no extensions
>>>
dropExtensionExact "dir/file.ext1.ext2" :: Maybe RelPath
Just dir/file.ext1>>>
dropExtensionExact "dir/file.ext" :: Maybe RelPath
Just dir/file>>>
dropExtensionExact "dir/file" :: Maybe RelPath
Nothing>>>
dropExtensionExact "/dir/file.ext1.ext2" :: Maybe AbsPath
Just /dir/file.ext1>>>
dropExtensionExact "/dir/file.ext" :: Maybe AbsPath
Just /dir/file>>>
dropExtensionExact "/dir/file" :: Maybe AbsPath
Nothing>>>
dropExtensionExact "." :: Maybe RelPath
Nothing>>>
dropExtensionExact "/" :: Maybe AbsPath
Nothing
dropExtension :: Path rel -> Path rel Source #
Drop the last extension of a path
>>>
dropExtension "dir/file.ext1.ext2" :: RelPath
dir/file.ext1>>>
dropExtension "dir/file.ext" :: RelPath
dir/file>>>
dropExtension "dir/file" :: RelPath
dir/file>>>
dropExtension "/dir/file.ext1.ext2" :: AbsPath
/dir/file.ext1>>>
dropExtension "/dir/file.ext" :: AbsPath
/dir/file>>>
dropExtension "/dir/file" :: AbsPath
/dir/file>>>
dropExtension "." :: RelPath
.>>>
dropExtension "/" :: AbsPath
/
Replaces System.FilePath.dropExtension
dropExtensions :: Path rel -> Path rel Source #
Drop all extensions of a path
>>>
dropExtensions "dir/file.ext1.ext2" :: RelPath
dir/file>>>
dropExtensions "dir/file.ext" :: RelPath
dir/file>>>
dropExtensions "dir/file" :: RelPath
dir/file>>>
dropExtensions "/dir/file.ext1.ext2" :: AbsPath
/dir/file>>>
dropExtensions "/dir/file.ext" :: AbsPath
/dir/file>>>
dropExtensions "/dir/file" :: AbsPath
/dir/file>>>
dropExtensions "." :: RelPath
.>>>
dropExtensions "/" :: AbsPath
/
Replaces System.FilePath.dropExtensions
addExtension :: Path rel -> Extension -> Path rel Source #
Add an extension to a path
>>>
addExtension "/directory/path" "ext" :: AbsPath
/directory/path.ext>>>
addExtension "directory/path" "ext" :: RelPath
directory/path.ext
This will not override the extension if there already is an extension. It will only add the given extension on top of it
>>>
addExtension "/directory/path.ext1" "ext2" :: AbsPath
/directory/path.ext1.ext2>>>
addExtension "directory/path.ext1" "ext2" :: RelPath
directory/path.ext1.ext2
This will not add an extension if the path is empty.
>>>
addExtension "." "ext" :: RelPath
.>>>
addExtension "/" "ext" :: AbsPath
/
Replaces System.FilePath.addExtension
(<.>) :: Path rel -> Extension -> Path rel Source #
Add an extension to a path (equivalent to addExtension
)
>>>
"/directory/path" <.> "ext" :: AbsPath
/directory/path.ext>>>
"directory/path" <.> "ext" :: RelPath
directory/path.ext>>>
"/directory/path.ext1" <.> "ext2" :: AbsPath
/directory/path.ext1.ext2>>>
"directory/path.ext1" <.> "ext2" :: RelPath
directory/path.ext1.ext2>>>
"." <.> "ext" :: RelPath
.>>>
"/" <.> "ext" :: AbsPath
/
Replaces System.FilePath.(.)
addExtensions :: Path rel -> [Extension] -> Path rel Source #
Add a list of extensions to a path
>>>
addExtensions "/directory/path" ["ext1", "ext2"] :: AbsPath
/directory/path.ext1.ext2>>>
addExtensions "directory/path" ["ext1", "ext2"] :: RelPath
directory/path.ext1.ext2
>>>
addExtensions "/directory/path.ext1" ["ext2", "ext3"] :: AbsPath
/directory/path.ext1.ext2.ext3>>>
addExtensions "directory/path.ext1" ["ext2", "ext3"] :: RelPath
directory/path.ext1.ext2.ext3
>>>
addExtensions "." ["ext1", "ext2"] :: RelPath
.>>>
addExtensions "/" ["ext1", "ext2"] :: AbsPath
/
This operation is an identity function if the given list of extensions is empty.
stripExtension :: Path rel -> Extension -> Maybe (Path rel) Source #
Drop the given extension from a FilePath. Fails if the FilePath does not have the given extension.
>>>
stripExtension "foo.x.hs.o" "o" :: Maybe RelPath
Just foo.x.hs>>>
stripExtension "foo.x.hs.o" "hs" :: Maybe RelPath
Nothing>>>
stripExtension "a.b.c.d" "d" :: Maybe RelPath
Just a.b.c>>>
stripExtension "foo.bar" "baz" :: Maybe RelPath
Nothing>>>
stripExtension "foobar" "bar" :: Maybe RelPath
Nothing
Replaces System.FilePath.stripExtension
stripExtensions :: Path rel -> [Extension] -> Maybe (Path rel) Source #
Drop the given extensions from a FilePath. Fails if the FilePath does not have all of the given extensions.
>>>
stripExtensions "foo.x.hs.o" ["hs", "o"] :: Maybe RelPath
Just foo.x>>>
stripExtensions "foo.x.hs.o" ["o", "hs"] :: Maybe RelPath
Nothing>>>
stripExtensions "a.b.c.d" ["c", "d"] :: Maybe RelPath
Just a.b>>>
stripExtensions "foo.bar" ["baz", "quux"] :: Maybe RelPath
Nothing>>>
stripExtensions "foobar" ["bar"] :: Maybe RelPath
Nothing
splitExtension :: Path rel -> Maybe (Path rel, Extension) Source #
Split off the extensions from a path
>>>
splitExtension ("dir/file.ext1.ext2" :: RelPath)
Just (dir/file.ext1,ext2)>>>
splitExtension ("dir/file.ext" :: RelPath)
Just (dir/file,ext)>>>
splitExtension ("dir/file" :: RelPath)
Nothing>>>
splitExtension ("/dir/file.ext1.ext2" :: AbsPath)
Just (/dir/file.ext1,ext2)>>>
splitExtension ("/dir/file.ext" :: AbsPath)
Just (/dir/file,ext)>>>
splitExtension ("/dir/file" :: AbsPath)
Nothing>>>
splitExtension ("." :: RelPath)
Nothing>>>
splitExtension ("/" :: AbsPath)
Nothing
Replaces System.FilePath.splitExtension
splitExtensions :: Path rel -> (Path rel, [Extension]) Source #
Split off the extensions from a path
>>>
splitExtensions ("dir/file.ext1.ext2" :: RelPath)
(dir/file,[ext1,ext2])>>>
splitExtensions ("dir/file.ext" :: RelPath)
(dir/file,[ext])>>>
splitExtensions ("dir/file" :: RelPath)
(dir/file,[])>>>
splitExtensions ("/dir/file.ext1.ext2" :: AbsPath)
(/dir/file,[ext1,ext2])>>>
splitExtensions ("/dir/file.ext" :: AbsPath)
(/dir/file,[ext])>>>
splitExtensions ("/dir/file" :: AbsPath)
(/dir/file,[])>>>
splitExtensions ("." :: RelPath)
(.,[])>>>
splitExtensions ("/" :: AbsPath)
(/,[])
hasExtension :: Path rel -> Bool Source #
Check whether the given filepath has any extensions
>>>
hasExtension ("/directory/path.ext" :: AbsPath)
True>>>
hasExtension ("/directory/path" :: AbsPath)
False
Replaces System.FilePath.hasExtension
splitFileName :: Path rel -> (Path rel, RelPath) Source #
Split a path into all but the last piece and the last piece and the extensions
>>>
splitFileName ("/directory/file.ext" :: AbsPath)
(/directory,file.ext)>>>
splitFileName ("file/bob.txt" :: RelPath)
(file,bob.txt)>>>
splitFileName ("file" :: RelPath)
(.,file)>>>
splitFileName ("dir.ext/file.ext" :: RelPath)
(dir.ext,file.ext)
takeFileNameExact :: Path rel -> Maybe RelPath Source #
Take the last piece and the extensions, exactly.
This will evaluate to Nothing
if the given path is empty
>>>
takeFileNameExact ("/directory/file.ext" :: AbsPath)
Just file.ext>>>
takeFileNameExact ("file/bob.txt" :: RelPath)
Just bob.txt>>>
takeFileNameExact ("file" :: RelPath)
Just file>>>
takeFileNameExact ("dir.ext/file.ext" :: RelPath)
Just file.ext>>>
takeFileNameExact ("." :: RelPath)
Nothing>>>
takeFileNameExact ("/" :: AbsPath)
Nothing
Replaces System.FilePath.takeFileName
takeFileName :: Path rel -> RelPath Source #
Take the last piece and the extensions.
This will evaluate to the empty (relative) path if the given path is empty.
>>>
takeFileName ("/directory/file.ext" :: AbsPath)
file.ext>>>
takeFileName ("file/bob.txt" :: RelPath)
bob.txt>>>
takeFileName ("file" :: RelPath)
file>>>
takeFileName ("dir.ext/file.ext" :: RelPath)
file.ext>>>
takeFileName ("." :: RelPath)
.>>>
takeFileName ("/" :: AbsPath)
.
Replaces System.FilePath.takeFileName
replaceFileNameExact :: Path rel -> PathPiece -> Maybe (Path rel) Source #
Replace the last piece of a path with the given last piece.
>>>
replaceFileNameExact "/directory/other.txt" "file.ext" :: Maybe AbsPath
Just /directory/file.ext>>>
replaceFileNameExact "." "file.ext" :: Maybe RelPath
Just file.ext>>>
replaceFileNameExact "/" "file.ext" :: Maybe AbsPath
Just /file.ext
If the given path piece is degenerate, this is what happens:
>>>
replaceFileNameExact "/directory/other.txt" "..." :: Maybe AbsPath
Nothing
replaceFileName :: Path rel -> PathPiece -> Path rel Source #
Replace the last piece of a path with the given last piece.
>>>
replaceFileName "/directory/other.txt" "file.ext" :: AbsPath
/directory/file.ext>>>
replaceFileName "." "file.ext" :: RelPath
file.ext>>>
replaceFileName "/" "file.ext" :: AbsPath
/file.ext
If the given path piece is degenerate, this is what happens:
>>>
replaceFileName "/directory/other.txt" "..." :: AbsPath
/directory
dropFileNameExact :: Path rel -> Maybe (Path rel) Source #
Drop the last piece of a path, exactly
>>>
dropFileNameExact ("directory/file.ext" :: RelPath)
Just directory>>>
dropFileNameExact ("/directory/file.ext" :: AbsPath)
Just /directory
This evaluates to Nothing when given an empty path
>>>
dropFileNameExact ("/" :: AbsPath)
Nothing>>>
dropFileNameExact ("." :: RelPath)
Nothing
dropFileName :: Path rel -> Path rel Source #
Drop the last piece of a path
>>>
dropFileName ("directory/file.ext" :: RelPath)
directory>>>
dropFileName ("/directory/file.ext" :: AbsPath)
/directory
This evaluates to an empty path when given an empty path
>>>
dropFileName ("/" :: AbsPath)
/>>>
dropFileName ("." :: RelPath)
.
Replaces System.FilePath.dropFileName
and System.FilePath.takeDirectory
takeBaseNameExact :: Path rel -> Maybe LastPathPiece Source #
Take the last piece (no extensions)
>>>
takeBaseNameExact ("file.ext" :: RelPath)
Just file>>>
takeBaseNameExact ("dir/and/file.ext" :: RelPath)
Just file
This will evaluate to Nothing when given an empty path:
>>>
takeBaseNameExact ("." :: RelPath)
Nothing>>>
takeBaseNameExact ("/" :: AbsPath)
Nothing
takeBaseName :: Path rel -> LastPathPiece Source #
Take the last piece (no extensions)
>>>
takeBaseName ("file.ext" :: RelPath)
file>>>
takeBaseName ("dir/and/file.ext" :: RelPath)
file
This will evaluate to an empty last path piece when given an empty path:
Replaces System.FilePath.takeBaseName
replaceBaseNameExact :: Path rel -> LastPathPiece -> Maybe (Path rel) Source #
Replace the last piece exactly: fails on empty last piece
>>>
replaceBaseNameExact "file.ext" "piece" :: Maybe RelPath
Just piece.ext>>>
replaceBaseNameExact "." "thing" :: Maybe RelPath
Just thing>>>
replaceBaseNameExact "/" "thing" :: Maybe AbsPath
Just /thing>>>
replaceBaseNameExact "/directory/file" "" :: Maybe AbsPath
Nothing
replaceBaseName :: Path rel -> LastPathPiece -> Path rel Source #
Replace the last piece
>>>
replaceBaseName "file.ext" "piece" :: RelPath
piece.ext>>>
replaceBaseName "." "thing" :: RelPath
thing>>>
replaceBaseName "/" "thing" :: AbsPath
/thing>>>
replaceBaseName "/directory/file" "" :: AbsPath
/directory
Replaces System.FilePath.replaceBaseName
replaceDirectoryExact :: Path r -> Path s -> Maybe (Path s) Source #
Replace everthing but the last piece, exactly
>>>
replaceDirectoryExact ("/dir/and/file" :: AbsPath) ("other/directory" :: RelPath)
Just other/directory/file
This will evaluate to Nothing
if the first argument is an empty path.
>>>
replaceDirectoryExact ("." :: RelPath) ("a/directory" :: RelPath)
Nothing>>>
replaceDirectoryExact ("/" :: AbsPath) ("a/directory" :: RelPath)
Nothing
This will evaluate to Nothing
if the second argument is an empty path.
>>>
replaceDirectoryExact ("dir/file" :: RelPath) ("." :: RelPath)
Nothing>>>
replaceDirectoryExact ("dir/file" :: RelPath) ("/" :: AbsPath)
Nothing
replaceDirectory :: Path r -> Path s -> Path s Source #
Replace everthing but the last piece
>>>
replaceDirectory ("/dir/and/file" :: AbsPath) ("other/directory" :: RelPath)
other/directory/file>>>
replaceDirectory ("." :: RelPath) ("a/directory" :: RelPath)
a/directory>>>
replaceDirectory ("/" :: AbsPath) ("a/directory" :: RelPath)
a/directory>>>
replaceDirectory ("dir/file" :: RelPath) ("." :: RelPath)
file>>>
replaceDirectory ("dir/file" :: RelPath) ("/" :: AbsPath)
/file
Replaces System.FilePath.replaceDirectory
combineExact :: Path rel -> RelPath -> Maybe (Path rel) Source #
Combine two paths, exactly
If the first path has extensions, they will be appended to the last pathpiece before concatenation
>>>
combineExact "/directory/path" "another/path.ext" :: Maybe AbsPath
Just /directory/path/another/path.ext>>>
combineExact "directory/path" "another/path.ext" :: Maybe RelPath
Just directory/path/another/path.ext>>>
combineExact "/file.ext1.ext2" "other/file.ext3" :: Maybe AbsPath
Just /file.ext1.ext2/other/file.ext3>>>
combineExact "file.ext1.ext2" "other/file.ext3" :: Maybe RelPath
Just file.ext1.ext2/other/file.ext3
This evaluates to Nothing
if any of the given paths are empty
>>>
combineExact "." "file.ext" :: Maybe RelPath
Nothing>>>
combineExact "/" "file.ext" :: Maybe AbsPath
Nothing
combine :: Path rel -> RelPath -> Path rel Source #
Combine two paths
If the first path has extensions, they will be appended to the last pathpiece before concatenation
>>>
combine "/directory/path" "another/path.ext" :: AbsPath
/directory/path/another/path.ext>>>
combine "directory/path" "another/path.ext" :: RelPath
directory/path/another/path.ext>>>
combine "/file.ext1.ext2" "other/file.ext3" :: AbsPath
/file.ext1.ext2/other/file.ext3>>>
combine "file.ext1.ext2" "other/file.ext3" :: RelPath
file.ext1.ext2/other/file.ext3
This treats empty paths as identities to the operation.
>>>
combine "file.ext" "." :: RelPath
file.ext>>>
combine "." "file.ext" :: RelPath
file.ext>>>
combine "/" "file.ext" :: AbsPath
/file.ext>>>
combine "." "." :: RelPath
.>>>
combine "/" "." :: AbsPath
/
Replaces System.FilePath.combine
(</>) :: Path rel -> RelPath -> Path rel Source #
Combine two paths
equivalent to combine
>>>
"/directory/path" </> "another/path.ext" :: AbsPath
/directory/path/another/path.ext>>>
"directory/path" </> "another/path.ext" :: RelPath
directory/path/another/path.ext>>>
"/file.ext1.ext2" </> "other/file.ext3" :: AbsPath
/file.ext1.ext2/other/file.ext3>>>
"file.ext1.ext2" </> "other/file.ext3" :: RelPath
file.ext1.ext2/other/file.ext3>>>
"." </> "file.ext" :: RelPath
file.ext>>>
"/" </> "file.ext" :: AbsPath
/file.ext
Replaces System.FilePath.(/)
splitPath :: Path rel -> [PathPiece] Source #
Split a path up into pieces
>>>
splitPath ("/a/full/absolute/directory/path" :: AbsPath)
[a,full,absolute,directory,path]
joinPath :: [PathPiece] -> Maybe (Path rel) Source #
Join path pieces back into a path
>>>
joinPath ["a", "full", "absolute", "directory", "path"] :: Maybe AbsPath
Just /a/full/absolute/directory/path>>>
joinPath [] :: Maybe RelPath
Just .>>>
joinPath [] :: Maybe AbsPath
Just />>>
joinPath [".", "."] :: Maybe RelPath
Nothing
isEmptyPath :: Path rel -> Bool Source #
renderPiece :: PathPiece -> String Source #
renderExtension :: Extension -> String Source #
renderExtensions :: [Extension] -> String Source #
combineLastAndExtensions :: LastPathPiece -> [Extension] -> PathPiece Source #
splitPiece :: PathPiece -> (LastPathPiece, [Extension]) Source #
unsafePathTypeCoerse :: Path rel -> Path rel' Source #