package pacomb

  1. Overview
  2. Docs

A module providing efficient character sets.

Type

type charset

The abstract type for a character set.

type t = charset

Synonym of charset.

Charset construction

val empty : charset

The empty character set.

val full : charset

The full character set.

val singleton : char -> charset

singleton c returns a charset containing only c.

val range : char -> char -> charset

range cmin cmax returns the charset containing all the characters between cmin and cmax.

val from_string : string -> charset

from_string s returns the charset corresponding to the description string s, which may contain standalone characters (different from '-', which is only allowed as first character) or ranges. They are build of start and end characters, separated by '-'. An example of a valid description is "-_a-zA-Z0-9". Note that Invalid_argument is raised in case of ill-formed description.

val union : charset -> charset -> charset

union cs1 cs2 builds a new charset that contins the union of the characters of cs1 and cs2.

val complement : charset -> charset

complement cs returns a new charset containing exactly characters that are not in cs.

val add : charset -> char -> charset

add cs c returns a new charset containing the characters of cs and the character c.

val del : charset -> char -> charset

del cs c returns a new charset containing the characters of cs but not the character c.

Membership test

val mem : charset -> char -> bool

mem cs c tests whether the charset cs contains c.

Printing and string representation

val pp : Format.formatter -> charset -> unit

pp ff cs prints the charset cs to output formatter ff. Compact format is used for printing: ranges, full and empty charsets are not given in full, but abbreviated.

val pp_full : Format.formatter -> charset -> unit

pp_full ff cs is similar to pp ff cs, but it does not abbreviate ranges, full and empty charsets.

val show : charset -> string

show oc cs builds a string representing the charset cs using the same compact format as print.

val show_full : charset -> string

show_full oc cs is the same as show oc cs but it does not use abreviations (i.e. all characters appear).

Manipulating charsets imperatively

val copy : charset -> charset

copy cs make a copy of the charset cs.

val addq : charset -> char -> unit

addq cs c adds the character c to the charset cs. Users must be particularly careful when using this function. In particular, it should not be used directly on empty, full or the result of the singleton function as it would change their value permanently. It is advisable to prefer the use of add or to work on a copy.

val delq : charset -> char -> unit

delq cs c deletes the character c from the charset cs. Similar recomendatiosn as for addq apply.

Comparison and equality test

val compare : charset -> charset -> int

compare cs1 cs2 compares the charsets cs1 and cs2 according to some (unspecified) total order.

val equal : charset -> charset -> bool

equal cs1 cs2 tests the equality of charsets cs1 and cs2.

OCaml

Innovation. Community. Security.