<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Bigarray.html"> <link rel="next" href="Callback.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Arg" rel="Chapter" href="Arg.html"> <link title="Arith_status" rel="Chapter" href="Arith_status.html"> <link title="Array" rel="Chapter" href="Array.html"> <link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html"> <link title="Big_int" rel="Chapter" href="Big_int.html"> <link title="Bigarray" rel="Chapter" href="Bigarray.html"> <link title="Buffer" rel="Chapter" href="Buffer.html"> <link title="Callback" rel="Chapter" href="Callback.html"> <link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html"> <link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html"> <link title="Char" rel="Chapter" href="Char.html"> <link title="Complex" rel="Chapter" href="Complex.html"> <link title="Condition" rel="Chapter" href="Condition.html"> <link title="Dbm" rel="Chapter" href="Dbm.html"> <link title="Digest" rel="Chapter" href="Digest.html"> <link title="Dynlink" rel="Chapter" href="Dynlink.html"> <link title="Event" rel="Chapter" href="Event.html"> <link title="Filename" rel="Chapter" href="Filename.html"> <link title="Format" rel="Chapter" href="Format.html"> <link title="Gc" rel="Chapter" href="Gc.html"> <link title="Genlex" rel="Chapter" href="Genlex.html"> <link title="Graphics" rel="Chapter" href="Graphics.html"> <link title="GraphicsX11" rel="Chapter" href="GraphicsX11.html"> <link title="Hashtbl" rel="Chapter" href="Hashtbl.html"> <link title="Int32" rel="Chapter" href="Int32.html"> <link title="Int64" rel="Chapter" href="Int64.html"> <link title="Lazy" rel="Chapter" href="Lazy.html"> <link title="Lexing" rel="Chapter" href="Lexing.html"> <link title="List" rel="Chapter" href="List.html"> <link title="ListLabels" rel="Chapter" href="ListLabels.html"> <link title="Map" rel="Chapter" href="Map.html"> <link title="Marshal" rel="Chapter" href="Marshal.html"> <link title="MoreLabels" rel="Chapter" href="MoreLabels.html"> <link title="Mutex" rel="Chapter" href="Mutex.html"> <link title="Nativeint" rel="Chapter" href="Nativeint.html"> <link title="Num" rel="Chapter" href="Num.html"> <link title="Obj" rel="Chapter" href="Obj.html"> <link title="Oo" rel="Chapter" href="Oo.html"> <link title="Parsing" rel="Chapter" href="Parsing.html"> <link title="Pervasives" rel="Chapter" href="Pervasives.html"> <link title="Printexc" rel="Chapter" href="Printexc.html"> <link title="Printf" rel="Chapter" href="Printf.html"> <link title="Queue" rel="Chapter" href="Queue.html"> <link title="Random" rel="Chapter" href="Random.html"> <link title="Scanf" rel="Chapter" href="Scanf.html"> <link title="Set" rel="Chapter" href="Set.html"> <link title="Sort" rel="Chapter" href="Sort.html"> <link title="Stack" rel="Chapter" href="Stack.html"> <link title="StdLabels" rel="Chapter" href="StdLabels.html"> <link title="Str" rel="Chapter" href="Str.html"> <link title="Stream" rel="Chapter" href="Stream.html"> <link title="String" rel="Chapter" href="String.html"> <link title="StringLabels" rel="Chapter" href="StringLabels.html"> <link title="Sys" rel="Chapter" href="Sys.html"> <link title="Thread" rel="Chapter" href="Thread.html"> <link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html"> <link title="Tk" rel="Chapter" href="Tk.html"> <link title="Unix" rel="Chapter" href="Unix.html"> <link title="UnixLabels" rel="Chapter" href="UnixLabels.html"> <link title="Weak" rel="Chapter" href="Weak.html"><title>Buffer</title> </head> <body> <div class="navbar"><a href="Bigarray.html">Previous</a> <a href="index.html">Up</a> <a href="Callback.html">Next</a> </div> <center><h1>Module <a href="type_Buffer.html">Buffer</a></h1></center> <br> <pre><span class="keyword">module</span> Buffer: <code class="code"><span class="keyword">sig</span></code> <a href="Buffer.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>Extensible string buffers. <p> This module implements string buffers that automatically expand as necessary. It provides accumulative concatenation of strings in quasi-linear time (instead of quadratic time when strings are concatenated pairwise).<br> <hr width="100%"> <pre><span class="keyword">type</span> <a name="TYPEt"></a><code class="type"></code>t </pre> <div class="info"> The abstract type of buffers.<br> </div> <pre><span class="keyword">val</span> <a name="VALcreate"></a>create : <code class="type">int -> <a href="Buffer.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">create n</code> returns a fresh buffer, initially empty. The <code class="code">n</code> parameter is the initial size of the internal string that holds the buffer contents. That string is automatically reallocated when more than <code class="code">n</code> characters are stored in the buffer, but shrinks back to <code class="code">n</code> characters when <code class="code">reset</code> is called. For best performance, <code class="code">n</code> should be of the same order of magnitude as the number of characters that are expected to be stored in the buffer (for instance, 80 for a buffer that holds one output line). Nothing bad will happen if the buffer grows beyond that limit, however. In doubt, take <code class="code">n = 16</code> for instance. If <code class="code">n</code> is not between 1 and <a href="Sys.html#VALmax_string_length"><code class="code"><span class="constructor">Sys</span>.max_string_length</code></a>, it will be clipped to that interval.<br> </div> <pre><span class="keyword">val</span> <a name="VALcontents"></a>contents : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> string</code></pre><div class="info"> Return a copy of the current contents of the buffer. The buffer itself is unchanged.<br> </div> <pre><span class="keyword">val</span> <a name="VALsub"></a>sub : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> int -> int -> string</code></pre><div class="info"> <code class="code"><span class="constructor">Buffer</span>.sub b off len</code> returns (a copy of) the substring of the current contents of the buffer <code class="code">b</code> starting at offset <code class="code">off</code> of length <code class="code">len</code> bytes. May raise <code class="code"><span class="constructor">Invalid_argument</span></code> if out of bounds request. The buffer itself is unaffected.<br> </div> <pre><span class="keyword">val</span> <a name="VALnth"></a>nth : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> int -> char</code></pre><div class="info"> get the n-th character of the buffer. Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if index out of bounds<br> </div> <pre><span class="keyword">val</span> <a name="VALlength"></a>length : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> int</code></pre><div class="info"> Return the number of characters currently contained in the buffer.<br> </div> <pre><span class="keyword">val</span> <a name="VALclear"></a>clear : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> unit</code></pre><div class="info"> Empty the buffer.<br> </div> <pre><span class="keyword">val</span> <a name="VALreset"></a>reset : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> unit</code></pre><div class="info"> Empty the buffer and deallocate the internal string holding the buffer contents, replacing it with the initial internal string of length <code class="code">n</code> that was allocated by <a href="Buffer.html#VALcreate"><code class="code"><span class="constructor">Buffer</span>.create</code></a> <code class="code">n</code>. For long-lived buffers that may have grown a lot, <code class="code">reset</code> allows faster reclamation of the space used by the buffer.<br> </div> <pre><span class="keyword">val</span> <a name="VALadd_char"></a>add_char : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> char -> unit</code></pre><div class="info"> <code class="code">add_char b c</code> appends the character <code class="code">c</code> at the end of the buffer <code class="code">b</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALadd_string"></a>add_string : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> string -> unit</code></pre><div class="info"> <code class="code">add_string b s</code> appends the string <code class="code">s</code> at the end of the buffer <code class="code">b</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALadd_substring"></a>add_substring : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> string -> int -> int -> unit</code></pre><div class="info"> <code class="code">add_substring b s ofs len</code> takes <code class="code">len</code> characters from offset <code class="code">ofs</code> in string <code class="code">s</code> and appends them at the end of the buffer <code class="code">b</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALadd_substitute"></a>add_substitute : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> (string -> string) -> string -> unit</code></pre><div class="info"> <code class="code">add_substitute b f s</code> appends the string pattern <code class="code">s</code> at the end of the buffer <code class="code">b</code> with substitution. The substitution process looks for variables into the pattern and substitutes each variable name by its value, as obtained by applying the mapping <code class="code">f</code> to the variable name. Inside the string pattern, a variable name immediately follows a non-escaped <code class="code">$</code> character and is one of the following:<ul> <li>a non empty sequence of alphanumeric or <code class="code">_</code> characters,</li> <li>an arbitrary sequence of characters enclosed by a pair of matching parentheses or curly brackets. An escaped <code class="code">$</code> character is a <code class="code">$</code> that immediately follows a backslash character; it then stands for a plain <code class="code">$</code>. Raise <code class="code"><span class="constructor">Not_found</span></code> if the closing character of a parenthesized variable cannot be found.</li> </ul> <br> </div> <pre><span class="keyword">val</span> <a name="VALadd_buffer"></a>add_buffer : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> <a href="Buffer.html#TYPEt">t</a> -> unit</code></pre><div class="info"> <code class="code">add_buffer b1 b2</code> appends the current contents of buffer <code class="code">b2</code> at the end of buffer <code class="code">b1</code>. <code class="code">b2</code> is not modified.<br> </div> <pre><span class="keyword">val</span> <a name="VALadd_channel"></a>add_channel : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> <a href="Pervasives.html#TYPEin_channel">in_channel</a> -> int -> unit</code></pre><div class="info"> <code class="code">add_channel b ic n</code> reads exactly <code class="code">n</code> character from the input channel <code class="code">ic</code> and stores them at the end of buffer <code class="code">b</code>. Raise <code class="code"><span class="constructor">End_of_file</span></code> if the channel contains fewer than <code class="code">n</code> characters.<br> </div> <pre><span class="keyword">val</span> <a name="VALoutput_buffer"></a>output_buffer : <code class="type"><a href="Pervasives.html#TYPEout_channel">out_channel</a> -> <a href="Buffer.html#TYPEt">t</a> -> unit</code></pre><div class="info"> <code class="code">output_buffer oc b</code> writes the current contents of buffer <code class="code">b</code> on the output channel <code class="code">oc</code>.<br> </div> </body></html>