123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(*
* BatBuffer - Additional buffer operations
* Copyright (C) 1999 Pierre Weis, Xavier Leroy
* 2009 David Teller, LIFO, Universite d'Orleans
* 2009 Dawid Toton
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version,
* with the special exception on linking described in file LICENSE.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)includeBuffer(** The underlying buffer type. *)typebuffer={mutablebuffer:string;(** Contents of the buffer *)mutableposition:int;(** The end of the buffer *)mutablelength:int;(** The size of the buffer *)initial_buffer:string(** For resetting to the original size **)}externalbuffer_of_t:t->buffer="%identity"externalt_of_buffer:buffer->t="%identity"letprintoutt=BatString.print out(contentst)(*$Q print
(Q.string) (fun s -> let b = create 5 in add_string b "foo"; add_string b s; add_string b "bar"; BatIO.to_string print b = "foo" ^ s ^ "bar")
*)letenumt=BatString.enum(contentst)(*$Q enum
(Q.string) (fun s -> let b = create 10 in add_string b s; BatEnum.equal Char.equal (enum b) (BatString.enum s))
*)letof_enume=letbuf=ifBatEnum.fast_countethencreate(BatEnum.counte)elsecreate128inadd_stringbuf(BatString.of_enume);buf(*$Q of_enum (Q.string) (fun s -> let b = of_enum (BatString.enum s) in contents b = s)
(Q.string) (fun s -> let e = BatString.enum s in \
let e = BatEnum.from (fun () -> BatEnum.get_exn e) in \
contents (of_enum e) = s)
*)letadd_inputtinpn=add_stringt(BatInnerIO.really_nreadinpn)(*$Q add_input (Q.string) (fun s -> let b = create 10 in add_input b (BatIO.input_string s) (String.length s); contents b = s)
*)letadd_channel=add_input##V<4.2##letadd_bytes=add_string##V<4.2##letadd_subbytes=add_substring##V<4.2##letto_bytes=contentslet output_buffer buf=BatInnerIO.create_out~write:(add_charbuf)~output:(funspl->add_subbytesbufspl;l)~close:(fun()->contentsbuf)~flush:BatInnerIO.noop(*$Q output_buffer
(Q.string) (fun s -> let b = create 10 in let oc = output_buffer b in IO.nwrite oc s; IO.close_out oc = s)
*)##V>=4.07##letto_seq=to_seq##V>=4.07##letto_seqi=to_seqi##V>=4.07##letadd_seq =add_seq##V>=4.07##letof_seq=of_seq##V>=4.08##letadd_uint8=add_uint8##V>=4.08##letadd_int8=add_int8##V>=4.08##letadd_uint16_ne=add_uint16_ne##V>=4.08##letadd_uint16_be =add_uint16_be##V>=4.08##letadd_uint16_le=add_uint16_le##V>=4.08##letadd_int16_ne=add_int16_ne##V>=4.08##letadd_int16_be=add_int16_be##V>=4.08##letadd_int16_le=add_int16_le##V>=4.08##letadd_int32_ne=add_int32_ne##V>=4.08##letadd_int32_be=add_int32_be##V>=4.08##letadd_int32_le=add_int32_le##V>=4.08##letadd_int64_ne=add_int64_ne##V>=4.08##letadd_int64_be=add_int64_be##V>=4.08##letadd_int64_le=add_int64_le