File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,24 @@ open Base
2
2
3
3
let f = Printf. sprintf
4
4
5
- let string_match ~regexp string =
5
+ let string_match ~regexp ?( pos = 0 ) string =
6
6
try
7
- let _ = Str. search_forward (Str. regexp regexp) string 0 in
7
+ let (_ : int ) = Str. search_forward (Str. regexp regexp) string pos in
8
8
true
9
9
with Stdlib. Not_found -> false
10
10
11
+ let rec fold_string_matches ~regexp ~f ~init ?(pos = 0 ) string =
12
+ if string_match ~regexp ~pos string then
13
+ let pos = Str. match_end () in
14
+ f (fun () -> fold_string_matches ~regexp ~f ~init ~pos string )
15
+ else init
16
+
17
+ let map_string_matches ~regexp ~f string =
18
+ fold_string_matches ~regexp ~f: (fun rest -> let v = f () in v :: rest () ) ~init: [] string
19
+
20
+ let iter_string_matches ~regexp ~f string =
21
+ fold_string_matches ~regexp ~f: (fun rest -> f () ; rest () ) ~init: () string
22
+
11
23
let pr_from_branch branch =
12
24
if string_match ~regexp: " ^pr-\\ ([0-9]*\\ )$" branch then
13
25
(Some (Str. matched_group 1 branch |> Int. of_string), " pull request" )
Original file line number Diff line number Diff line change 1
1
val f : ('a , unit , string ) format -> 'a
2
2
3
- val string_match : regexp :string -> string -> bool
3
+ val string_match : regexp :string -> ?pos : int -> string -> bool
4
+
5
+ val fold_string_matches :
6
+ regexp :string -> f :((unit -> 'a ) -> 'a ) -> init :'a -> ?pos : int -> string -> 'a
7
+
8
+ val map_string_matches : regexp :string -> f :(unit -> 'a ) -> string -> 'a list
9
+
10
+ val iter_string_matches : regexp :string -> f :(unit -> unit ) -> string -> unit
4
11
5
12
val pr_from_branch : string -> int option * string
6
13
You can’t perform that action at this time.
0 commit comments