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.
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
.
val add_string : t -> string -> unit
add_string b s
appends the string s
at the end of the buffer b
.
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
.
val add_channel : t -> Stdlib.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
.
add_buffer b1 b2
appends the current contents of buffer b2
at the end of buffer b1
. b2
is not modified.
Return a copy of the current contents of the buffer. The buffer itself is unchanged.
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.
val nth : t -> int -> char
nth b i
returns the i
th character if the buffer.