this repo has no description
1open Brr
2
3type t = Jv.t
4
5include (Jv.Id : Jv.CONV with type t := t)
6
7let regexp = Jv.get (Window.to_jv G.window) "RegExp"
8
9type opts = Indices | Global | Ignore | Multiline | DotAll | Unicode | Sticky
10
11let opts_to_string = function
12 | Indices -> "d"
13 | Global -> "g"
14 | Ignore -> "i"
15 | Multiline -> "m"
16 | DotAll -> "s"
17 | Unicode -> "u"
18 | Sticky -> "y"
19
20let create ?(opts = []) s =
21 let opts =
22 match List.length opts with
23 | 0 -> Jv.undefined
24 | _ ->
25 let options = List.sort_uniq Stdlib.compare opts in
26 let opt_string =
27 List.fold_left (fun acc t -> acc ^ opts_to_string t) "" options
28 in
29 Jv.of_string opt_string
30 in
31 Jv.new' regexp [| Jv.of_string s; opts |]
32
33type result = Jv.t
34
35let get_full_string_match res =
36 let arr = Jv.to_jv_array res in
37 arr.(0) |> Jv.to_string
38
39let get_index res = Jv.Int.get res "index"
40
41let get_indices res =
42 let jv = Jv.get res "indices" in
43 match Jv.is_null jv with
44 | true -> []
45 | false ->
46 let conv arr =
47 let indices = Jv.to_array Jv.to_int arr in
48 (indices.(0), indices.(1))
49 in
50 Jv.to_list conv jv
51
52let get_substring_matches res =
53 let arr = Jv.to_jv_array res in
54 let length = Array.length arr in
55 Array.sub arr 1 length |> Array.to_list |> List.map Jv.to_string
56
57let exec' t s = Jv.to_option Jv.Id.to_jv @@ Jv.call t "exec" [| Jv.of_jstr s |]
58let exec t s = exec' t @@ Jstr.v s