package metadb

  1. Overview
  2. Docs

A minimal library for manipulating typed representations of paths

exception InvalidRootType of string
exception InvalidRelType of string
exception InvalidNameType of string
type root

A root path has the form "/some/.../path"

type rel

A relative path has the form "some/.../path"

type name

A name is the name of a file or directory, which cannot contain the character '/'

val debug : bool ref

Debugging mode. Debugging mode is set to false by default.

val mk_root : string -> root

Constructor for creating a root path, if debug is set to true, mk_root will check that input is well-formed. Raise InvalidRootType otherwise

val mk_rel : string -> rel

Constructor for creating a relative path, if debug is set to true, mk_rel will check that input is well-formed. Raise InvalidRelType otherwise

val mk_name : string -> name

Constructor for creating a name, if debug is set to true, mk_name will check that input is well-formed. Raise InvalidNameType otherwise

val string_of_root : root -> string

Convert a root path to a string

val string_of_rel : rel -> string

Convert a relative path to a string

val string_of_name : name -> string

Convert a name to a string

val split : rel -> name list

split path splits a relative path into a list of names

val merge : root -> rel -> root

merge root path produces the path root'/'path

val merge_lst : root -> name list -> root

merge root names is the same as merge but a relative path is given as a list of names

val unroot : root -> root * rel

unroot "/some/.../path" will return ("/", "some/.../path")

val add_file_ext : string -> root -> root

add_file_ext ext path wiil add the file extension ext to the leaf of path, that is path'.'ext

val remove_file_ext : string -> root -> root

remove_file_ext ext path removes the file extension from the file name

val remove_file_ext_rel : string -> rel -> rel

Same as remove_file_ext, but for relative paths

val strip_root : root -> root -> rel

strip_root root path will drop the initial substring root from path, thus inversing merge

val get_leaf : root -> name

get_leaf "/some/.../path/leaf" returns the leaf of a path, that is leaf

val get_leaf_rel : rel -> name

Same as get_leaf but for relative paths

val drop_leaf : root -> root

drop_leaf "/some/.../path/leaf" will return "/some/.../path"

val hidden : root -> bool

hidden path will return true if the leaf of path is a hidden file, that is starts with '.'

val pp_root : Format.formatter -> root -> unit

Pretty print path

val pp_rel : Format.formatter -> rel -> unit
OCaml

Innovation. Community. Security.