package zed

  1. Overview
  2. Docs

Unicode ropes

type t

Type of unicode ropes.

type rope = t

Alias.

exception Out_of_bounds

Exception raised when trying to access a character which is outside the bounds of a rope.

Construction
val empty : t

The empty rope.

val make : int -> CamomileLibrary.UChar.t -> t

make length char creates a rope of length length containing only char.

val init : int -> (int -> CamomileLibrary.UChar.t) -> t

init n f returns the contenation of singleton (f 0), singleton (f 1), ..., singleton (f (n - 1)).

val rev_init : int -> (int -> CamomileLibrary.UChar.t) -> t

rev_init n f returns the contenation of singleton (f (n - 1)), ..., singleton (f 1), singleton (f 0).

val singleton : CamomileLibrary.UChar.t -> t

singleton ch creates a rope of length 1 containing only ch.

Informations
val length : t -> int

Returns the length of the given rope.

val is_empty : t -> bool

is_empty rope returns whether str is the empty rope or not.

val compare : t -> t -> int

Compares two ropes (in code point order).

val equal : t -> t -> bool

equal r1 r2 retuns true iff r1 is equal to r2.

To/from strings
val of_string : string -> t

of_string str creates a rope from a string. The string must be UTF-8 encoded and is validated. Note that str must not be modified after this operation, if you intend to do so you must copy it before passing it to of_string.

val to_string : t -> string

to_string rope flatten a rope into a string encoded in UTF-8.

Random access
val get : t -> int -> CamomileLibrary.UChar.t

get str rope returns the character at index idx in rope.

Rope manipulation
val append : t -> t -> t

Concatenates the two given ropes.

val concat : t -> t list -> t

concat sep l concatenates all strings of l separating them by sep.

val sub : t -> int -> int -> t

sub rope ofs len Returns the sub-rope of rope starting at ofs and of length len.

val break : t -> int -> t * t

break rope pos returns the sub-ropes before and after pos in rope. It is more efficient than creating two sub-ropes with sub.

val before : t -> int -> t

before rope pos returns the sub-rope before pos in rope.

val after : t -> int -> t

after rope pos returns the sub-string after pos in rope.

val insert : t -> int -> t -> t

insert rope pos sub inserts sub in rope at position pos.

val remove : t -> int -> int -> t

remove rope pos len removes the len characters at position pos in rope

val replace : t -> int -> int -> t -> t

replace rope pos len repl replaces the len characters at position pos in rope by repl.

val lchop : t -> t

lchop rope returns rope without is first character. Returns empty if rope is empty.

val rchop : t -> t

rchop rope returns rope without is last character. Returns empty if rope is empty.

Iteration, folding and mapping
val iter : (CamomileLibrary.UChar.t -> unit) -> t -> unit

iter f rope applies f on all characters of rope starting from the left.

val rev_iter : (CamomileLibrary.UChar.t -> unit) -> t -> unit

rev_iter f rope applies f an all characters of rope starting from the right.

val fold : (CamomileLibrary.UChar.t -> 'a -> 'a) -> t -> 'a -> 'a

fold f rope acc applies f on all characters of rope starting from the left, accumulating a value.

val rev_fold : (CamomileLibrary.UChar.t -> 'a -> 'a) -> t -> 'a -> 'a

rev_fold f rope acc applies f on all characters of rope starting from the right, accumulating a value.

map f rope maps all characters of rope with f.

rev_map f str maps all characters of rope with f in reverse order.

Iteration and folding on leafs

Note: for all of the following functions, the leaves must absolutely not be modified.

val iter_leaf : (Zed_utf8.t -> unit) -> t -> unit

iter_leaf f rope applies f on all leaves of rope starting from the left.

val rev_iter_leaf : (Zed_utf8.t -> unit) -> t -> unit

iter_leaf f rope applies f on all leaves of rope starting from the right.

val fold_leaf : (Zed_utf8.t -> 'a -> 'a) -> t -> 'a -> 'a

fold f rope acc applies f on all leaves of rope starting from the left, accumulating a value.

val rev_fold_leaf : (Zed_utf8.t -> 'a -> 'a) -> t -> 'a -> 'a

rev_fold f rope acc applies f on all leaves of rope starting from the right, accumulating a value.

Zippers
module Zip : sig ... end
Buffers
module Buffer : sig ... end

This module is similar of the Buffer module of the standard library except that it works with rope.

module Text : CamomileLibrary.UnicodeString.Type with type t = rope and type index = Zip.t
OCaml

Innovation. Community. Security.