]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/pxp/netstring/netbuffer.mli
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / pxp / netstring / netbuffer.mli
1 (* $Id$
2  * ----------------------------------------------------------------------
3  *
4  *)
5
6
7 (* A Netbuffer.t is a buffer that can grow and shrink dynamically. *)
8
9 type t
10
11 val create : int -> t
12     (* Creates a netbuffer which allocates initially this number of bytes. 
13      * The logical length is zero.
14      *)
15
16 val contents : t -> string
17     (* Returns the contents of the buffer as fresh string. *)
18
19 val sub : t -> pos:int -> len:int -> string
20     (* sub nb k n: returns the n characters starting at position n from 
21      * netbuffer nb as fresh string
22      *)
23
24 val length : t -> int
25     (* Returns the logical length of the buffer *)
26
27 val add_string : t -> string -> unit
28     (* add_string nb s: Adds a copy of the string s to the logical end of
29      * the netbuffer nb. If necessary, the nb grows.
30      *)
31
32 val add_sub_string : t -> string -> pos:int -> len:int -> unit
33     (* add_sub_string nb s k n: Adds the substring of s starting at position
34      * k with length n to the logical end of the netbuffer nb. If necessary,
35      * the nb grows.
36      * This is semantically the same as
37      * add_string nb (String.sub s k n), but the extra copy is avoided.
38      *)
39
40 val delete : t -> pos:int -> len:int -> unit
41     (* delete nb k n: Deletes the n bytes at position k of netbuffer nb
42      * in-place.
43      * The netbuffer does not shrink!
44      *)
45
46 val clear : t -> unit
47     (* deletes all contents from the buffer. As 'delete', the netbuffer does
48      * not shrink.
49      *)
50
51 val try_shrinking : t -> unit
52     (* try_shrinking nb: If the length of the buffer is less than half of
53      * the allocated space, the netbuffer is reallocated in order to save
54      * memory.
55      *)
56
57 val index_from : t -> int -> char -> int
58     (* index_from nb k c: Searches the character c in the netbuffer beginning
59      * at position k. If found, the position of the left-most occurence is
60      * returned. Otherwise, Not_found is raised.
61      *)
62
63 val unsafe_buffer : t -> string
64     (* WARNING! This is a low-level function!
65      * Returns the current string that internally holds the buffer.
66      * The byte positions 0 to length - 1 actually store the contents of
67      * the buffer. You can directly read and modify the buffer. Note that
68      * there is no protection if you read or write positions beyond the
69      * length of the buffer.
70      *)
71
72 val print_buffer : t -> unit
73     (* For the toploop *)
74
75
76 (* ======================================================================
77  * History:
78  * 
79  * $Log$
80  * Revision 1.1  2000/11/17 09:57:27  lpadovan
81  * Initial revision
82  *
83  * Revision 1.3  2000/06/25 22:34:43  gerd
84  *      Added labels to arguments.
85  *
86  * Revision 1.2  2000/06/24 20:20:33  gerd
87  *      Added the toploop printer.
88  *
89  * Revision 1.1  2000/04/15 13:07:48  gerd
90  *      Initial revision.
91  *
92  * 
93  *)