-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Support for well-typed paths -- -- Support for well-typed paths, utilizing ByteString under the hood. @package hpath @version 0.12.1 -- | Support for well-typed paths. module HPath -- | The main Path type. -- -- The type variable b is either: -- -- -- -- Internally it is a ByteString. The path is guaranteed to be normalised -- and contain no trailing Path separators, except for the "/" -- root path. -- -- There are no duplicate path separators "//", no -- "..", no "./", etc. -- -- Two special paths exist: -- -- -- -- The constructor is not exposed. Instead, use the smart constructors -- parseAbs, parseRel and parseAny. data Path b -- | An absolute path. data Abs -- | A relative path; one without a root. data Rel -- | Exception when parsing a location. data PathParseException data PathException pattern Path :: ByteString -> Path a -- | Get a location for an absolute path. Produces a normalised path. -- -- Throws: PathParseException -- --
--   >>> parseAbs "/abc"
--   "/abc"
--   
--   >>> parseAbs "/"
--   "/"
--   
--   >>> parseAbs "/abc/def"
--   "/abc/def"
--   
--   >>> parseAbs "/abc/def/.///"
--   "/abc/def"
--   
--   >>> parseAbs "abc"
--   *** Exception: InvalidAbs "abc"
--   
--   >>> parseAbs ""
--   *** Exception: InvalidAbs ""
--   
--   >>> parseAbs "/abc/../foo"
--   *** Exception: InvalidAbs "/abc/../foo"
--   
parseAbs :: MonadThrow m => ByteString -> m (Path Abs) -- | Get a location for a relative path. Produces a normalised path. -- -- Note that filepath may contain any number of ./, but -- not a single .. anywhere. -- -- Throws: PathParseException -- --
--   >>> parseRel "abc"
--   "abc"
--   
--   >>> parseRel "def/"
--   "def"
--   
--   >>> parseRel "abc/def"
--   "abc/def"
--   
--   >>> parseRel "abc/def/."
--   "abc/def"
--   
--   >>> parseRel "/abc"
--   *** Exception: InvalidRel "/abc"
--   
--   >>> parseRel ""
--   *** Exception: InvalidRel ""
--   
--   >>> parseRel "abc/../foo"
--   *** Exception: InvalidRel "abc/../foo"
--   
--   >>> parseRel "."
--   "."
--   
--   >>> parseRel "././././."
--   "."
--   
--   >>> parseRel "./..."
--   "..."
--   
--   >>> parseRel ".."
--   *** Exception: InvalidRel ".."
--   
parseRel :: MonadThrow m => ByteString -> m (Path Rel) -- | Parses a path, whether it's relative or absolute. -- -- Throws: PathParseException -- --
--   >>> parseAny "/abc"
--   Left "/abc"
--   
--   >>> parseAny "..."
--   Right "..."
--   
--   >>> parseAny "abc/def"
--   Right "abc/def"
--   
--   >>> parseAny "abc/def/."
--   Right "abc/def"
--   
--   >>> parseAny "/abc"
--   Left "/abc"
--   
--   >>> parseAny ""
--   *** Exception: InvalidRel ""
--   
--   >>> parseAny "abc/../foo"
--   *** Exception: InvalidRel "abc/../foo"
--   
--   >>> parseAny "."
--   Right "."
--   
--   >>> parseAny ".."
--   *** Exception: InvalidRel ".."
--   
parseAny :: MonadThrow m => ByteString -> m (Either (Path Abs) (Path Rel)) -- | The "/" root path. rootPath :: Path Abs -- | The "." pwd path. pwdPath :: Path Rel -- | Convert an absolute Path to a ByteString type. fromAbs :: Path Abs -> ByteString -- | Convert a relative Path to a ByteString type. fromRel :: Path Rel -> ByteString -- | Convert any Path to a ByteString type. toFilePath :: Path b -> ByteString fromAny :: Either (Path Abs) (Path Rel) -> ByteString -- | Append two paths. -- -- The second argument must always be a relative path, which ensures that -- undefinable things like `"abc" <> "/def"` cannot happen. -- -- Technically, the first argument can be a path that points to a -- non-directory, because this library is IO-agnostic and makes no -- assumptions about file types. -- --
--   >>> [abs|/|] </> [rel|file|]
--   "/file"
--   
--   >>> [abs|/path/to|] </> [rel|file|]
--   "/path/to/file"
--   
--   >>> [abs|/|] </> [rel|file/lal|]
--   "/file/lal"
--   
--   >>> [abs|/|] </> [rel|.|]
--   "/"
--   
--   >>> [rel|.|] </> [rel|.|]
--   "."
--   
() :: Path b -> Path Rel -> Path b -- | Extract the file part of a path. -- -- The following properties hold: -- --
--   basename (p </> a) == basename a
--   
-- -- Throws: PathException if given the root path "/" -- --
--   >>> basename [abs|/abc/def/dod|]
--   "dod"
--   
--   >>> basename [rel|abc/def/dod|]
--   "dod"
--   
--   >>> basename [rel|dod|]
--   "dod"
--   
--   >>> basename [rel|.|]
--   "."
--   
--   >>> basename [abs|/|]
--   *** Exception: RootDirHasNoBasename
--   
basename :: MonadThrow m => Path b -> m (Path Rel) -- | Extract the file part of a relative path. -- -- The following properties hold: -- --
--   basename' (p </> a) == basename' a
--   
-- --
--   >>> basename' [rel|abc/def/dod|]
--   "dod"
--   
--   >>> basename' [rel|dod|]
--   "dod"
--   
--   >>> basename' [rel|.|]
--   "."
--   
basename' :: Path Rel -> Path Rel -- | Extract the directory name of a path. -- --
--   >>> dirname [abs|/abc/def/dod|]
--   "/abc/def"
--   
--   >>> dirname [abs|/|]
--   "/"
--   
dirname :: Path Abs -> Path Abs -- | Get all parents of a path. -- --
--   >>> getAllParents [abs|/abs/def/dod|]
--   ["/abs/def","/abs","/"]
--   
--   >>> getAllParents [abs|/foo|]
--   ["/"]
--   
--   >>> getAllParents [abs|/|]
--   []
--   
getAllParents :: Path Abs -> [Path Abs] -- | Gets all path components. -- --
--   >>> getAllComponents [rel|abs/def/dod|]
--   ["abs","def","dod"]
--   
--   >>> getAllComponents [rel|abs|]
--   ["abs"]
--   
--   >>> getAllComponents [rel|.|]
--   ["."]
--   
getAllComponents :: Path Rel -> [Path Rel] -- | Gets all path components after the "/" root directory. -- --
--   >>> getAllComponentsAfterRoot [abs|/abs/def/dod|]
--   ["abs","def","dod"]
--   
--   >>> getAllComponentsAfterRoot [abs|/abs|]
--   ["abs"]
--   
getAllComponentsAfterRoot :: Path Abs -> [Path Rel] -- | Strip directory from path, making it relative to that directory. -- Throws Couldn'tStripPrefixDir if directory is not a parent of -- the path. -- -- The bases must match. -- --
--   >>> [abs|/lal/lad|]     `stripDir` [abs|/lal/lad/fad|]
--   "fad"
--   
--   >>> [rel|lal/lad|]      `stripDir` [rel|lal/lad/fad|]
--   "fad"
--   
--   >>> [abs|/|]            `stripDir` [abs|/|]
--   "."
--   
--   >>> [abs|/lal/lad/fad|] `stripDir` [abs|/lal/lad|]
--   *** Exception: Couldn'tStripPrefixTPS "/lal/lad/fad" "/lal/lad"
--   
--   >>> [abs|/abs|]         `stripDir` [abs|/lal/lad|]
--   *** Exception: Couldn'tStripPrefixTPS "/abs" "/lal/lad"
--   
--   >>> [rel|fad|]          `stripDir` [rel|fad|]
--   "."
--   
--   >>> [rel|.|]            `stripDir` [rel|.|]
--   "."
--   
--   >>> [rel|.|]            `stripDir` [rel|.foo|]
--   *** Exception: Couldn'tStripPrefixTPS "." ".foo"
--   
stripDir :: MonadThrow m => Path b -> Path b -> m (Path Rel) -- | Is p a parent of the given location? Implemented in terms of -- stripDir. The bases must match. -- --
--   >>> [abs|/lal/lad|]     `isParentOf` [abs|/lal/lad/fad|]
--   True
--   
--   >>> [rel|lal/lad|]      `isParentOf` [rel|lal/lad/fad|]
--   True
--   
--   >>> [abs|/|]            `isParentOf` [abs|/|]
--   False
--   
--   >>> [abs|/lal/lad/fad|] `isParentOf` [abs|/lal/lad|]
--   False
--   
--   >>> [rel|fad|]          `isParentOf` [rel|fad|]
--   False
--   
--   >>> [rel|.|]            `isParentOf` [rel|.foo|]
--   False
--   
isParentOf :: Path b -> Path b -> Bool -- | Check whether the given Path is the root "/" path. -- --
--   >>> isRootPath [abs|/lal/lad|]
--   False
--   
--   >>> isRootPath [abs|/|]
--   True
--   
isRootPath :: Path Abs -> Bool -- | Check whether the given Path is the pwd "." path. -- --
--   >>> isPwdPath [rel|lal/lad|]
--   False
--   
--   >>> isPwdPath [rel|.|]
--   True
--   
isPwdPath :: Path Rel -> Bool withAbsPath :: Path Abs -> (ByteString -> IO a) -> IO a withRelPath :: Path Rel -> (ByteString -> IO a) -> IO a -- | Quasiquote an absolute Path. This accepts Unicode Chars and will -- encode as UTF-8. -- --
--   >>> [abs|/etc/profile|] :: Path Abs
--   "/etc/profile"
--   
--   >>> [abs|/|] :: Path Abs
--   "/"
--   
--   >>> [abs|/|] :: Path Abs
--   "/\239\131\144"
--   
abs :: QuasiQuoter -- | Quasiquote a relative Path. This accepts Unicode Chars and will encode -- as UTF-8. -- --
--   >>> [rel|etc|] :: Path Rel
--   "etc"
--   
--   >>> [rel|bar/baz|] :: Path Rel
--   "bar/baz"
--   
--   >>> [rel||] :: Path Rel
--   "\239\131\144"
--   
rel :: QuasiQuoter instance GHC.Show.Show HPath.PathParseException instance GHC.Show.Show HPath.PathException instance GHC.Exception.Type.Exception HPath.PathException instance GHC.Exception.Type.Exception HPath.PathParseException instance Data.Typeable.Internal.Typeable a => Language.Haskell.TH.Syntax.Lift (HPath.Internal.Path a)