Write ‘isPrefixOf’ and friends in infix form

This commit is contained in:
mrkkrp 2015-11-21 16:14:54 +06:00
parent 339f7587a3
commit 733fa04ac3

View File

@ -81,7 +81,7 @@ parseAbsDir :: MonadThrow m
parseAbsDir filepath = parseAbsDir filepath =
if FilePath.isAbsolute filepath && if FilePath.isAbsolute filepath &&
not (null (normalizeDir filepath)) && not (null (normalizeDir filepath)) &&
not (isPrefixOf "~/" filepath) && not ("~/" `isPrefixOf` filepath) &&
not (hasParentDir filepath) not (hasParentDir filepath)
then return (Path (normalizeDir filepath)) then return (Path (normalizeDir filepath))
else throwM (InvalidAbsDir filepath) else throwM (InvalidAbsDir filepath)
@ -96,7 +96,7 @@ parseRelDir :: MonadThrow m
parseRelDir filepath = parseRelDir filepath =
if not (FilePath.isAbsolute filepath) && if not (FilePath.isAbsolute filepath) &&
not (null filepath) && not (null filepath) &&
not (isPrefixOf "~/" filepath) && not ("~/" `isPrefixOf` filepath) &&
not (hasParentDir filepath) && not (hasParentDir filepath) &&
not (null (normalizeDir filepath)) && not (null (normalizeDir filepath)) &&
filepath /= ".." filepath /= ".."
@ -112,7 +112,7 @@ parseAbsFile :: MonadThrow m
parseAbsFile filepath = parseAbsFile filepath =
if FilePath.isAbsolute filepath && if FilePath.isAbsolute filepath &&
not (FilePath.hasTrailingPathSeparator filepath) && not (FilePath.hasTrailingPathSeparator filepath) &&
not (isPrefixOf "~/" filepath) && not ("~/" `isPrefixOf` filepath) &&
not (hasParentDir filepath) && not (hasParentDir filepath) &&
not (null (normalizeFile filepath)) && not (null (normalizeFile filepath)) &&
filepath /= ".." filepath /= ".."
@ -129,7 +129,7 @@ parseRelFile filepath =
if not (FilePath.isAbsolute filepath || if not (FilePath.isAbsolute filepath ||
FilePath.hasTrailingPathSeparator filepath) && FilePath.hasTrailingPathSeparator filepath) &&
not (null filepath) && not (null filepath) &&
not (isPrefixOf "~/" filepath) && not ("~/" `isPrefixOf` filepath) &&
not (hasParentDir filepath) && not (hasParentDir filepath) &&
not (null (normalizeFile filepath)) && not (null (normalizeFile filepath)) &&
filepath /= ".." filepath /= ".."
@ -140,9 +140,9 @@ parseRelFile filepath =
-- This handles the logic of checking for different path separators on Windows. -- This handles the logic of checking for different path separators on Windows.
hasParentDir :: FilePath -> Bool hasParentDir :: FilePath -> Bool
hasParentDir filepath' = hasParentDir filepath' =
(isSuffixOf "/.." filepath) || ("/.." `isSuffixOf` filepath) ||
(isInfixOf "/../" filepath) || ("/../" `isInfixOf` filepath) ||
(isPrefixOf "../" filepath) ("../" `isPrefixOf` filepath)
where where
filepath = filepath =
case FilePath.pathSeparator of case FilePath.pathSeparator of