Module Rope.Buffer

This is similar to the Buffer module in the standard library except that it constructs ropes. It is recommended to use this module instead of repeatedly concatenating chars.

type t

Mutable buffer to construct ropes.

val create : int -> t

create n returns a fresh buffer, initially empty. The n parameter is the initial size of the internal rope that holds the buffer contents. The buffer will grow dynamically to accomodate new inputs.

val clear : t -> unit

Empty the buffer.

val reset : t -> unit

Empty the buffer.

val length : t -> int

Return the number of characters currently contained in the buffer.

val add_char : t -> char -> unit

add_char b c appends the character c at the end of the buffer b.

raises Failure

if the length if the buffer exceeds max_int.

val add_string : t -> string -> unit

add_string b s appends the string s at the end of the buffer b.

raises Failure

if the length if the buffer exceeds max_int.

val add_substring : t -> string -> int -> int -> unit

add_substring b s ofs len takes len characters from offset ofs in string s and appends them at the end of the buffer b.

raises Invalid_argument

if ofs and len do not designate a valid substring of s.

raises Failure

if the length if the buffer exceeds max_int.

val add_rope : t -> rope -> unit

add_rope b r add the rope r to the buffer b.

val add_channel : t -> Pervasives.in_channel -> int -> unit

add_channel b ic n reads exactly n characters from the input channel ic and stores them at the end of buffer b.

raises End_of_file

if the channel contains fewer than n characters.

val add_buffer : t -> t -> unit

add_buffer b1 b2 appends the current contents of buffer b2 at the end of buffer b1. b2 is not modified.

val contents : t -> rope

Return a copy of the current contents of the buffer. The buffer itself is unchanged.

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

sub b off len returns a rope of the current contents of the buffer b starting at offset off of length len bytes. The buffer itself is unaffected.

raises Invalid_argument

if out of bounds request.

val nth : t -> int -> char

nth b i returns the ith character if the buffer.

raises Out_of_bounds

if i < 0 or i >= length b. Time: O(log(length b)).