LIB: add more useful pattern synonyms

This commit is contained in:
2015-12-26 20:28:00 +01:00
parent 464e65d574
commit 3bd201f1b6
2 changed files with 19 additions and 11 deletions

View File

@@ -96,6 +96,7 @@ import System.FilePath
, equalFilePath
, isAbsolute
, joinPath
, pathSeparator
, splitDirectories
, takeFileName
, (</>)
@@ -287,6 +288,19 @@ sfile f@(Socket {}) = (True, f)
sfile f = (False, f)
invalidFileName :: FileName -> (Bool, FileName)
invalidFileName "" = (True, "")
invalidFileName "." = (True, ".")
invalidFileName ".." = (True, "..")
invalidFileName fn = (elem pathSeparator fn, fn)
-- |Matches on invalid filesnames, such as ".", ".." and anything
-- that contains a path separator.
pattern InvFN <- (invalidFileName -> (True,_))
-- |Opposite of `InvFN`.
pattern ValFN f <- (invalidFileName -> (False, f))
-- |Matches on symlinks (pointing to anything) or regular files.
pattern SARegFile <- (saregfile -> (True, _))
pattern SRegFile <- (sregfile -> (True, _))