package fpath-base

  1. Overview
  2. Docs

Module Fpath_base.Relative_pathSource

include module type of Fpath_sexp0.Relative_path with type t := t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval seeded_hash : int -> t -> int
Sourceval to_fpath : t -> Fpath.t
Sourceval to_string : t -> string
Sourceval of_fpath : Fpath.t -> t option

of_fpath p returns p normalized via Fpath.normalize and classified as a relative path. Returns None if p is not a relative path.

Raises Invalid_argument if the normalized path contains leading ".." segments (escapes upward).

Sourceval of_string : string -> (t, [ `Msg of string ]) Result.t

This is a convenient wrapper to compose Fpath.of_string and of_fpath.

Sourceval v : string -> t

v str returns a t or raises Invalid_argument.

Sourceval empty : t

The empty relative path "./".

Sourceval append : t -> t -> t

append t1 t2 appends relative path t2 to relative path t1 and normalizes the result via Fpath.normalize.

Raises Invalid_argument if the normalized result would escape upward (contains leading ".." segments).

Sourceval extend : t -> Fpath_sexp0.Fsegment.t -> t

extend t seg appends filesystem segment seg to path t and normalizes the result via Fpath.normalize.

Raises Invalid_argument if the normalized result would escape upward (contains leading ".." segments).

For example, extend empty (Fsegment.v "..") raises because it would create "../" which escapes upward.

Sourceval parent : t -> t option

parent t returns the parent directory of path t, or None if t has no parent.

Returns None when t is the empty relative path "./".

Raises Invalid_argument if t is an escaping path (contains leading ".." segments) (this should not occur for paths constructed through this module's API).

Sourceval of_list : Fpath_sexp0.Fsegment.t list -> t

of_list segments constructs a path from a list of filesystem segments by folding extend over the list starting from empty.

Raises Invalid_argument if any intermediate step during the fold would produce a path that escapes upward.

For example:

  of_list [ Fsegment.v "a"; Fsegment.v ".."; Fsegment.v ".." ]

raises because the second ".." would require going from "./" to "../". See extend for details.

Sourceval chop_prefix : t -> prefix:t -> t option

chop_prefix t ~prefix removes prefix prefix from path t.

Returns Some result where result is t with prefix removed, or None if prefix is not actually a prefix of t. When prefix is empty ("./"), returns Some t unchanged.

Sourceval chop_suffix : t -> suffix:t -> t option

chop_suffix t ~suffix removes suffix suffix from path t.

Returns Some result where result is t with suffix removed, or None if suffix is not actually a suffix of t. When suffix is empty ("./"), returns Some t unchanged.

When a non-empty suffix is successfully removed, the result is a directory path.

Sourceval is_dir_path : t -> bool
Sourceval to_dir_path : t -> t
Sourceval rem_empty_seg : t -> t
include Base.Comparable.S with type t := t
include Base.Comparisons.S with type t := t
include Base.Comparisons.Infix with type t := t
Sourceval (>=) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (<) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval equal : t -> t -> bool
Sourceval compare : t -> t -> int

compare t1 t2 returns 0 if t1 is equal to t2, a negative integer if t1 is less than t2, and a positive integer if t1 is greater than t2.

Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval ascending : t -> t -> int

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~compare:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

Sourceval descending : t -> t -> int
Sourceval between : t -> low:t -> high:t -> bool

between t ~low ~high means low <= t <= high

Sourceval clamp_exn : t -> min:t -> max:t -> t

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

Sourceval clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
Sourcetype comparator_witness
Sourceval hash : t -> Base.int
Sourceval hash_fold_t : Base.Hash.state -> t -> Base.Hash.state