package ctypes

  1. Overview
  2. Docs
Combinators for binding to C libraries without writing any C

Install

Dune Dependency

Authors

Maintainers

Sources

0.23.0.tar.gz
sha256=cae47d815b27dd4c824a007f1145856044542fe2588d23a443ef4eefec360bf1
md5=b1af973ec9cf7867a63714e92df82f2a

doc/src/ctypes.stubs/ctypes_path.ml.html

Source file ctypes_path.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(*
 * Copyright (c) 2014 Jeremy Yallop.
 *
 * This file is distributed under the terms of the MIT License.
 * See the file LICENSE for details.
 *)

(* Paths (long identifiers) *)

type path = string list

let is_uident s =
  Str.(string_match (regexp "[A-Z][a-zA-Z0-9_]*") s 0);;

let is_ident s =
  Str.(string_match (regexp "[A-Za-z_][a-zA-Z0-9_]*") s 0);;

let rec is_valid_path = function
  | [] -> false
  | [l] -> is_ident l
  | u :: p -> is_uident u && is_valid_path p

let path_of_string s = 
  let p = Str.(split (regexp_string ".") s) in
  if is_valid_path p then p
  else invalid_arg "Ctypes_ident.path_of_string"

let format_path fmt p =
  Format.pp_print_string fmt (String.concat "." p)
OCaml

Innovation. Community. Security.