path-0.9.6: Support for well-typed paths

Safe Haskell | None
Language | Haskell2010

OsPath.Internal.Windows

Contents

- The Path type
- Validation functions
- Normalizing functions
- Other helper functions

Description

Internal types and functions.

Synopsis

- newtype Path b t = Path WindowsPath
- toOsPath :: Path b t -> WindowsPath
- isValidAbsDir :: WindowsPath -> Bool
- isValidAbsFile :: WindowsPath -> Bool
- isValidRelDir :: WindowsPath -> Bool
- isValidRelFile :: WindowsPath -> Bool
- hasParentDir :: WindowsPath -> Bool
- normalizeLeadingSeps :: WindowsPath -> WindowsPath
- normalizeTrailingSeps :: WindowsPath -> WindowsPath
- normalizeAllSeps :: WindowsPath -> WindowsPath
- normalizeWindowsSeps :: WindowsPath -> WindowsPath
- normalizeDrive :: WindowsPath -> WindowsPath
- normalizeDir :: WindowsPath -> WindowsPath
- normalizeFile :: WindowsPath -> WindowsPath
- extSep :: WindowsString
- pathSep :: WindowsString
- relRoot :: WindowsPath
- isWindows :: Bool

# The Path type

newtype Path b t Source #

Path of some base and type.

The type variables are:

- `b` — base, the base location of the path; absolute or relative.
- `t` — type, whether file or directory.

Internally it is a `WindowsPath`, which can be of two formats only:

1. File format: `file.txt`, `foo/bar.txt`, `/foo/bar.txt`
2. Directory format: `foo/`, `/foo/bar/`

All directories end in a trailing separator. There are no duplicate path separators `//`, no `..`, no `./`, no `~/`, etc.

Constructors

Path WindowsPath |

#### Instances

Instances details

(Typeable b, Typeable t) => Lift (Path b t :: Type) Source # |
Instance details Defined in OsPath.Internal.Windows Methods lift :: Quote m => Path b t -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Path b t -> Code m (Path b t) Source #
NFData (Path b t) Source # |
Instance details Defined in OsPath.Internal.Windows Methods rnf :: Path b t -> () Source #
(Data b, Data t) => Data (Path b t) Source # |

Instance details

Defined in OsPath.Internal.Windows

Methods

gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Path b t -> c (Path b t) Source #

gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Path b t) Source #

toConstr :: Path b t -> Constr Source #

dataTypeOf :: Path b t -> DataType Source #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Path b t)) Source #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Path b t)) Source #

gmapT :: (forall b0. Data b0 => b0 -> b0) -> Path b t -> Path b t Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Path b t -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Path b t -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Path b t -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Path b t -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Path b t -> m (Path b t) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Path b t -> m (Path b t) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Path b t -> m (Path b t) Source #

Generic (Path b t) Source # |

Instance details

Defined in OsPath.Internal.Windows

Associated Types

type Rep (Path b t) |
Instance details Defined in OsPath.Internal.Windows type Rep (Path b t) = D1 ('MetaData "Path" "OsPath.Internal.Windows" "path-0.9.6-JHZF5ciOIdr1UcXeHGVHFt" 'True) (C1 ('MetaCons "Path" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 WindowsPath)))

Methods

from :: Path b t -> Rep (Path b t) x Source #

to :: Rep (Path b t) x -> Path b t Source #

Show (Path b t) Source #

Same as 'show . OsPath.toOsPath'.

The following property holds:

    x == y ≡ show x == show y

Instance details Defined in OsPath.Internal.Windows Methods showsPrec :: Int -> Path b t -> ShowS Source # show :: Path b t -> String Source # showList :: [Path b t] -> ShowS Source #

Eq (Path b t) Source #

String equality.

The following property holds:

    show x == show y ≡ x == y

Instance details Defined in OsPath.Internal.Windows Methods (==) :: Path b t -> Path b t -> Bool Source # (/=) :: Path b t -> Path b t -> Bool Source #

Ord (Path b t) Source #

String ordering.

The following property holds:

    show x `compare` show y ≡ x `compare` y

Instance details Defined in OsPath.Internal.Windows Methods compare :: Path b t -> Path b t -> Ordering Source # (<) :: Path b t -> Path b t -> Bool Source # (<=) :: Path b t -> Path b t -> Bool Source # (>) :: Path b t -> Path b t -> Bool Source # (>=) :: Path b t -> Path b t -> Bool Source # max :: Path b t -> Path b t -> Path b t Source # min :: Path b t -> Path b t -> Path b t Source #
Hashable (Path b t) Source # |
Instance details Defined in OsPath.Internal.Windows Methods hashWithSalt :: Int -> Path b t -> Int Source # hash :: Path b t -> Int Source #
type Rep (Path b t) Source # |
Instance details Defined in OsPath.Internal.Windows type Rep (Path b t) = D1 ('MetaData "Path" "OsPath.Internal.Windows" "path-0.9.6-JHZF5ciOIdr1UcXeHGVHFt" 'True) (C1 ('MetaCons "Path" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 WindowsPath)))

toOsPath :: Path b t -> WindowsPath Source #

Convert to a WindowsPath type.

All directories have a trailing slash, so if you want no trailing slash, you can use `dropTrailingPathSeparator` from the filepath package.

# Validation functions

isValidAbsDir :: WindowsPath -> Bool Source #

Is the `WindowsPath` a valid absolute dir?

isValidAbsFile :: WindowsPath -> Bool Source #

Is the `WindowsPath` a valid absolute file?

isValidRelDir :: WindowsPath -> Bool Source #

Is the `WindowsPath` a valid relative dir?

isValidRelFile :: WindowsPath -> Bool Source #

Is the `WindowsPath` a valid relative file?

hasParentDir :: WindowsPath -> Bool Source #

Helper function: check if the filepath has any parent directories in it. This handles the logic of checking for different path separators on Windows.

# Normalizing functions

normalizeLeadingSeps :: WindowsPath -> WindowsPath Source #

Normalizes seps only at the beginning of a path.

normalizeTrailingSeps :: WindowsPath -> WindowsPath Source #

Normalizes seps only at the end of a path.

normalizeAllSeps :: WindowsPath -> WindowsPath Source #

Replaces consecutive path seps with single sep and replaces alt sep with standard sep.

normalizeWindowsSeps :: WindowsPath -> WindowsPath Source #

Normalizes seps in whole path, but if there are 2+ seps at the beginning, they are normalized to exactly 2 to preserve UNC and Unicode prefixed paths.

normalizeDrive :: WindowsPath -> WindowsPath Source #

Normalizes the drive of a `WindowsPath`.

normalizeDir :: WindowsPath -> WindowsPath Source #

Normalizes directory path with platform-specific rules.

normalizeFile :: WindowsPath -> WindowsPath Source #

Applies platform-specific sep normalization following `OsPath.normalise`.

# Other helper functions

extSep :: WindowsString Source #

pathSep :: WindowsString Source #

relRoot :: WindowsPath Source #

Normalized file path representation for the relative path root

isWindows :: Bool Source #