package lambdapi

All checked builds pass
  1. Overview
  2. Docs
Proof assistant for the λΠ-calculus modulo rewriting

Install

dune-project
 Dependency

Authors

Maintainers

Sources

lambdapi-4.0.0.tbz
sha256=0e2e73e0ea0c674f1263bf85ed3453ed3d6084d38eea29974a03ba9e382d29d7
sha512=2831db57fcd09206687a92fc9ee7d363e87bcec5167949e9c8161d41c63d5887b9f3556bfd63a7a9a0c12e5a5dc61a397baf4f496ebdb2a2fce122142c05e7a1

doc/src/lambdapi.lplib/string.ml.html

Source file string.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module S = Stdlib.String
include S

let to_list : string -> char list =
 fun s ->
  let l = ref [] in
  S.iter (fun c -> l := c :: !l) s;
  List.rev !l

let of_list : char list -> string =
 fun l ->
  let b = Buffer.create 37 in
  List.iter (Buffer.add_char b) l;
  Buffer.contents b

let is_substring : string -> string -> bool =
 fun e s ->
  let len_e = S.length e in
  let len_s = S.length s in
  let rec is_sub i =
    if len_s - i < len_e then false
    else if S.sub s i len_e = e then true
    else is_sub (i + 1)
  in
  is_sub 0

let is_prefix : string -> string -> bool =
 fun p s ->
  let len_p = S.length p in
  let len_s = S.length s in
  len_p <= len_s && S.sub s 0 len_p = p

let remove_prefix (prefix:string) (s:string): string =
  if is_prefix prefix s then
    let len_p = S.length prefix in
    S.sub s len_p (S.length s - len_p)
  else s

let _ =
  assert (remove_prefix "" "a" = "a");
  assert (remove_prefix "a" "ba" = "ba");
  assert (remove_prefix "a" "ab" = "b")

let for_all : (char -> bool) -> string -> bool =
 fun p s ->
  let len_s = S.length s in
  let rec for_all i = i >= len_s || (p (S.get s i) && for_all (i + 1)) in
  for_all 0

(* Taken from string.ml in OCaml 4.14.1. *)
module B = Bytes
let bos = B.unsafe_of_string
let get_utf_8_uchar s i = B.get_utf_8_uchar (bos s) i
let is_valid_utf_8 s = B.is_valid_utf_8 (bos s)

(* [string_of_file f] puts the contents of file [f] in a string. *)
let string_of_file f =
  let ic = open_in f in
  let n = in_channel_length ic in
  let s = B.create n in
  really_input ic s 0 n;
  close_in ic;
  B.to_string s

let is_string_literal (s:string): bool =
  let n = S.length s in n >= 2 && S.get s 0 = '"' && S.get s (n-1) = '"'

let add_quotes (n:string): string = "\""^n^"\""

let remove_quotes (n:string): string = S.sub n 1 (S.length n - 2)

let _ =
  let f s = remove_quotes (add_quotes s) = s in
  assert (f "");
  assert (f "ab")