<!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="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.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="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="Ratio" rel="Chapter" href="Ratio.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 class="pre" href="Bigarray.html" title="Bigarray">Previous</a> <a class="up" href="index.html" title="Index">Up</a> <a class="post" href="Callback.html" title="Callback">Next</a> </div> <h1>Module <a href="type_Buffer.html">Buffer</a></h1> <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><div class="info module top"> 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> </div> <hr width="100%"> <pre><span id="TYPEt"><span class="keyword">type</span> <code class="type"></code>t</span> </pre> <div class="info "> The abstract type of buffers.<br> </div> <pre><span id="VALcreate"><span class="keyword">val</span> create</span> : <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 id="VALcontents"><span class="keyword">val</span> contents</span> : <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 id="VALsub"><span class="keyword">val</span> sub</span> : <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 id="VALblit"><span class="keyword">val</span> blit</span> : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> int -> string -> int -> int -> unit</code></pre><div class="info "> <code class="code"><span class="constructor">Buffer</span>.blit src srcoff dst dstoff len</code> copies <code class="code">len</code> characters from the current contents of the buffer <code class="code">src</code>, starting at offset <code class="code">srcoff</code> to string <code class="code">dst</code>, starting at character <code class="code">dstoff</code>. <p> Raise <code class="code"><span class="constructor">Invalid_argument</span></code> if <code class="code">srcoff</code> and <code class="code">len</code> do not designate a valid substring of <code class="code">src</code>, or if <code class="code">dstoff</code> and <code class="code">len</code> do not designate a valid substring of <code class="code">dst</code>.<br> <b>Since</b> 3.11.2<br> </div> <pre><span id="VALnth"><span class="keyword">val</span> nth</span> : <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 id="VALlength"><span class="keyword">val</span> length</span> : <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 id="VALclear"><span class="keyword">val</span> clear</span> : <code class="type"><a href="Buffer.html#TYPEt">t</a> -> unit</code></pre><div class="info "> Empty the buffer.<br> </div> <pre><span id="VALreset"><span class="keyword">val</span> reset</span> : <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 id="VALadd_char"><span class="keyword">val</span> add_char</span> : <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 id="VALadd_string"><span class="keyword">val</span> add_string</span> : <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 id="VALadd_substring"><span class="keyword">val</span> add_substring</span> : <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 id="VALadd_substitute"><span class="keyword">val</span> add_substitute</span> : <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 id="VALadd_buffer"><span class="keyword">val</span> add_buffer</span> : <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 id="VALadd_channel"><span class="keyword">val</span> add_channel</span> : <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 id="VALoutput_buffer"><span class="keyword">val</span> output_buffer</span> : <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>