X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=bitmatch.mli;h=cd59f95e7745f8c3a84fdcb1d3f1296a7823389c;hb=63a72ad59065a9b19bca1636a17098ad12c5e652;hp=4aa221dc40c5b2c1ee977127722516943d47f276;hpb=55199e34a1f377be0e91ad3feebae1191514a431;p=ocaml-bitstring.git diff --git a/bitmatch.mli b/bitmatch.mli index 4aa221d..cd59f95 100644 --- a/bitmatch.mli +++ b/bitmatch.mli @@ -4,7 +4,8 @@ * 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 of the License, or (at your option) any later version. + * version 2 of the License, or (at your option) any later version, + * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -453,7 +454,7 @@ bitmatch bits with {v ocamlc -I +bitmatch \ - -pp "camlp4o bitmatch.cma bitmatch_persistent.cma \ + -pp "camlp4of bitmatch.cma bitmatch_persistent.cma \ `ocamlc -where`/bitmatch/pa_bitmatch.cmo" \ unix.cma bitmatch.cma test.ml -o test v} @@ -599,7 +600,46 @@ exception Construct_failure of string * string * int * int location of the [BITSTRING] constructor that failed. *) -(** {3 Bitstrings} *) +(** {3 Bitstring manipulation} *) + +val bitstring_length : bitstring -> int +(** [bitstring_length bitstring] returns the length of + the bitstring in bits. + + Note this just returns the third field in the {!bitstring} tuple. *) + +val subbitstring : bitstring -> int -> int -> bitstring +(** [subbitstring bits off len] returns a sub-bitstring + of the bitstring, starting at offset [off] bits and + with length [len] bits. + + If the original bitstring is not long enough to do this + then the function raises [Invalid_argument "subbitstring"]. + + Note that this function just changes the offset and length + fields of the {!bitstring} tuple, so is very efficient. *) + +val dropbits : int -> bitstring -> bitstring +(** Drop the first n bits of the bitstring and return a new + bitstring which is shorter by n bits. + + If the length of the original bitstring is less than n bits, + this raises [Invalid_argument "dropbits"]. + + Note that this function just changes the offset and length + fields of the {!bitstring} tuple, so is very efficient. *) + +val takebits : int -> bitstring -> bitstring +(** Take the first n bits of the bitstring and return a new + bitstring which is exactly n bits long. + + If the length of the original bitstring is less than n bits, + this raises [Invalid_argument "takebits"]. + + Note that this function just changes the offset and length + fields of the {!bitstring} tuple, so is very efficient. *) + +(** {3 Constructing bitstrings} *) val empty_bitstring : bitstring (** [empty_bitstring] is the empty, zero-length bitstring. *) @@ -667,9 +707,7 @@ val bitstring_of_file_descr_max : Unix.file_descr -> int -> bitstring [max] bytes from the channel (or fewer if the end of input occurs before that). *) -val bitstring_length : bitstring -> int -(** [bitstring_length bitstring] returns the length of - the bitstring in bits. *) +(** {3 Converting bitstrings} *) val string_of_bitstring : bitstring -> string (** [string_of_bitstring bitstring] converts a bitstring to a string