File: 50_named_pattern.ml

package info (click to toggle)
ocaml-bitstring 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,276 kB
  • ctags: 492
  • sloc: ml: 3,360; sh: 377; makefile: 324; ansic: 113
file content (20 lines) | stat: -rw-r--r-- 488 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(* Named pattern
 * $Id: 50_named_pattern.ml 142 2008-07-17 15:45:56Z richard.wm.jones $
 *)

open Printf
open Bitstring

(* A byte+length Pascal string. *)
let bitmatch pascal_string =
  { len : 8;
    str : len*8 : string }

let () =
  let bits = bitstring_of_string "\022Mary had a little lamb" in
  bitmatch bits with
  | { :pascal_string } ->
      () (*printf "it's a Pascal string, len = %d, string = %S\n" len str*)
  | { _ } ->
      eprintf "not matching error\n";
      exit 1