• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ocaml / odoc / 1525

27 Sep 2023 11:12PM UTC coverage: 63.256%. Remained the same
1525

push

github

jonludlam
Update CHANGES.md

Co-authored-by: panglesd <peada@free.fr>

3858 of 6099 relevant lines covered (63.26%)

1584.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.11
/src/html/utils.ml
1
(* Shared utility functions *)
2

3
(* = Option.fold *)
4
let fold_option ~none ~some = function Some x -> some x | None -> none
×
5

6
let rec list_concat_map ?sep ~f = function
7
  | [] -> []
18✔
8
  | [ x ] -> f x
68,350✔
9
  | x :: xs -> (
56,592✔
10
      let hd = f x in
11
      let tl = list_concat_map ?sep ~f xs in
56,592✔
12
      match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))
534✔
13

14
let optional_elt f ?a = function [] -> [] | l -> [ f ?a l ]
86✔
15

16
module Json = struct
17
  type json =
18
    [ `Null
19
    | `Bool of bool
20
    | `Float of float
21
    | `String of string
22
    | `Array of json list
23
    | `Object of (string * json) list ]
24

25
  let rec buffer_add_json b = function
26
    | `Null -> Buffer.add_string b "null"
×
27
    | `Bool bool -> Buffer.add_string b (if bool then "true" else "false")
×
28
    | `Float f -> Buffer.add_string b (Printf.sprintf "%.16g" f)
×
29
    | `String s -> buffer_add_json_string b s
×
30
    | `Array els -> (
×
31
        match els with
32
        | [] -> Buffer.add_string b "[]"
×
33
        | el :: els ->
×
34
            let add_sep_el b e =
35
              Buffer.add_char b ',';
×
36
              buffer_add_json b e
×
37
            in
38
            Buffer.add_char b '[';
39
            buffer_add_json b el;
×
40
            List.iter (add_sep_el b) els;
×
41
            Buffer.add_char b ']')
×
42
    | `Object mems -> (
×
43
        match mems with
44
        | [] -> Buffer.add_string b "{}"
×
45
        | mem :: mems ->
×
46
            let add_mem b (k, v) =
47
              buffer_add_json_string b k;
×
48
              Buffer.add_char b ':';
×
49
              buffer_add_json b v
×
50
            in
51
            let add_sep_mem b mem =
52
              Buffer.add_char b ',';
×
53
              add_mem b mem
×
54
            in
55
            Buffer.add_char b '{';
56
            add_mem b mem;
×
57
            List.iter (add_sep_mem b) mems;
×
58
            Buffer.add_char b '}')
×
59

60
  and buffer_add_json_string b s =
61
    let is_control = function
×
62
      | '\x00' .. '\x1F' | '\x7F' -> true
×
63
      | _ -> false
×
64
    in
65
    let len = String.length s in
66
    let max_idx = len - 1 in
×
67
    let flush b start i =
68
      if start < len then Buffer.add_substring b s start (i - start)
×
69
    in
70
    let rec loop start i =
71
      match i > max_idx with
×
72
      | true -> flush b start i
×
73
      | false -> (
×
74
          let next = i + 1 in
75
          match String.get s i with
76
          | '"' ->
×
77
              flush b start i;
78
              Buffer.add_string b "\\\"";
×
79
              loop next next
×
80
          | '\\' ->
×
81
              flush b start i;
82
              Buffer.add_string b "\\\\";
×
83
              loop next next
×
84
          | c when is_control c ->
×
85
              flush b start i;
×
86
              Buffer.add_string b (Printf.sprintf "\\u%04X" (Char.code c));
×
87
              loop next next
×
88
          | _c -> loop start next)
×
89
    in
90
    Buffer.add_char b '"';
91
    loop 0 0;
×
92
    Buffer.add_char b '"'
×
93

94
  let to_string json =
95
    let b = Buffer.create 1024 in
×
96
    buffer_add_json b json;
×
97
    Buffer.contents b
×
98
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc