Skip to content

Commit ac7d140

Browse files
EmileTrotignonrr0gi
authored andcommitted
switch from pcre to pcre2
1 parent 74d4988 commit ac7d140

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

devkit.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ depends: [
1818
"camlzip"
1919
"libevent" {>= "0.8.0"}
2020
"ocurl" {>= "0.7.2"}
21-
"pcre" {>= "7.4.6"}
21+
"pcre2" {>= "8.0.3"}
2222
"trace" {>= "0.4"}
2323
"extunix" {>= "0.1.4"}
2424
"lwt" {>= "5.7.0"}

dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
lwt
1818
lwt.unix
1919
ocamlnet_lite
20-
pcre
20+
pcre2
2121
stdlib-shims
2222
str
2323
trace.core

exn.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ let to_string exn =
1616
match exn with
1717
| Unix.Unix_error (e,f,s) -> sprintf "Unix_error %s(%s) %s" f s (Unix.error_message e)
1818
| Curl.CurlException (_,n,s) -> sprintf "Curl.CurlException(%u,%s)" n s
19-
| Pcre.Error err -> sprintf "Pcre.Error(%s)"
19+
| Pcre2.Error err -> sprintf "Pcre2.Error(%s)"
2020
begin match err with
2121
| Partial -> "Partial"
22-
| BadPartial -> "BadPartial"
2322
| BadPattern(m,p) -> sprintf "BadPattern(%s,%i)" m p
24-
| BadUTF8 -> "BadUTF8"
25-
| BadUTF8Offset -> "BadUTF8Offset"
23+
| BadUTF -> "BadUTF"
24+
| BadUTFOffset -> "BadUTFOffset"
2625
| MatchLimit -> "MatchLimit"
27-
| RecursionLimit -> "RecursionLimit"
26+
| DepthLimit -> "DepthLimit"
2827
| InternalError s -> sprintf "InternalError(%s)" s
2928
| _ -> Printexc.to_string exn
3029
end

httpev.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ let show_client c =
163163

164164
type ('a,'b) result = [ `Ok of 'a | `Error of 'b ]
165165

166-
let space = Pcre.regexp "[ \t]+"
166+
let space = Pcre2.regexp "[ \t]+"
167167

168168
type reason = Url | Version | Method | Header | RequestLine | Split | Extra | NotAcceptable
169169
exception Parse of reason * string
@@ -209,7 +209,7 @@ let acceptable_encoding headers =
209209
| None -> Identity
210210

211211
let make_request_exn ~line1 ~headers ~body c =
212-
match Pcre.split ~rex:space line1 with
212+
match Pcre2.split ~rex:space line1 with
213213
| [meth;url;version] ->
214214
if url.[0] <> '/' then (* abs_path *)
215215
failed Url url;

ocamlnet_lite/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
(public_name devkit.ocamlnet_lite)
44
(libraries
55
extlib ; just for Array.create
6-
pcre
6+
pcre2
77
str))

ocamlnet_lite/netstring_str.ml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ type re_term =
5656
(**********************************************************************)
5757
(* Final types *)
5858

59-
type regexp = Pcre.regexp
59+
type regexp = Pcre2.regexp
6060
type split_result = Str.split_result = Text of string | Delim of string
61-
type result = Pcre.substrings
61+
type result = Pcre2.substrings
6262

6363
(**********************************************************************)
6464
(* Parse Str-style regexps, and convert to Pcre-style regexps *)
@@ -268,9 +268,9 @@ let pcre_safe_quote c =
268268

269269
let rec print_pcre_regexp ret =
270270
match ret with
271-
| Texact s -> Pcre.quote s
271+
| Texact s -> Pcre2.quote s
272272
| Tnullchar ->
273-
(* Pcre.quote "\000" returns nonsense *)
273+
(* Pcre2.quote "\000" returns nonsense *)
274274
"[\\000]"
275275
| Tany -> "."
276276
| Tnull -> "(?:)"
@@ -315,42 +315,42 @@ and print_set s =
315315
let regexp s =
316316
let ret = scan_str_regexp s in
317317
let s' = print_pcre_regexp ret in
318-
Pcre.regexp ~flags:[ `MULTILINE ] s'
318+
Pcre2.regexp ~flags:[ `MULTILINE ] s'
319319

320320
let search_forward pat s pos =
321-
let result = Pcre.exec ~rex:pat ~pos s in
322-
(fst (Pcre.get_substring_ofs result 0), result)
321+
let result = Pcre2.exec ~rex:pat ~pos s in
322+
(fst (Pcre2.get_substring_ofs result 0), result)
323323

324324
let matched_string result _ =
325-
(* Unfortunately, Pcre.get_substring will not raise Not_found if there is
325+
(* Unfortunately, Pcre2.get_substring will not raise Not_found if there is
326326
* no matched string. Instead, it returns "", but this value cannot be
327327
* distinguished from an empty match.
328-
* The workaround is to call Pcre.get_substring_ofs first. This function
328+
* The workaround is to call Pcre2.get_substring_ofs first. This function
329329
* will raise Not_found if there is not any matched string.
330330
*
331331
* NOTE: Current versions of Pcre do return Not_found!
332332
*)
333-
ignore (Pcre.get_substring_ofs result 0);
334-
Pcre.get_substring result 0
333+
ignore (Pcre2.get_substring_ofs result 0);
334+
Pcre2.get_substring result 0
335335

336-
let match_beginning result = fst (Pcre.get_substring_ofs result 0)
337-
let match_end result = snd (Pcre.get_substring_ofs result 0)
336+
let match_beginning result = fst (Pcre2.get_substring_ofs result 0)
337+
let match_end result = snd (Pcre2.get_substring_ofs result 0)
338338

339339
let matched_group result n _ =
340340
(* See also the comment for [matched_string] *)
341-
if n < 0 || n >= Pcre.num_of_subs result then raise Not_found;
342-
ignore (Pcre.get_substring_ofs result n);
343-
Pcre.get_substring result n
341+
if n < 0 || n >= Pcre2.num_of_subs result then raise Not_found;
342+
ignore (Pcre2.get_substring_ofs result n);
343+
Pcre2.get_substring result n
344344

345345
let global_substitute pat subst s =
346-
Pcre.substitute_substrings ~rex:pat ~subst:(fun r -> subst r s) s
346+
Pcre2.substitute_substrings ~rex:pat ~subst:(fun r -> subst r s) s
347347

348348
let tr_split_result r =
349349
List.map
350350
(function
351-
| Pcre.Text t -> Text t | Pcre.Delim d -> Delim d | _ -> assert false)
351+
| Pcre2.Text t -> Text t | Pcre2.Delim d -> Delim d | _ -> assert false)
352352
(List.filter
353-
(function Pcre.Group (_, _) | Pcre.NoGroup -> false | _ -> true)
353+
(function Pcre2.Group (_, _) | Pcre2.NoGroup -> false | _ -> true)
354354
r)
355355

356-
let full_split sep s = tr_split_result (Pcre.full_split ~rex:sep ~max:(-1) s)
356+
let full_split sep s = tr_split_result (Pcre2.full_split ~rex:sep ~max:(-1) s)

stre.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ open Printf
44
open ExtLib
55
open Prelude
66

7-
let by_words = Pcre.regexp ~flags:[`UTF8] "[^\\pL\\pN.]+"
8-
let by_space = Pcre.regexp "\\s+"
9-
let by_lines = Pcre.regexp "\\r?\\n"
10-
let split rex str = match Pcre.split ~rex str with ""::l -> l | l -> l
7+
let by_words = Pcre2.regexp ~flags:[`UTF] "[^\\pL\\pN.]+"
8+
let by_space = Pcre2.regexp "\\s+"
9+
let by_lines = Pcre2.regexp "\\r?\\n"
10+
let split rex str = match Pcre2.split ~rex str with ""::l -> l | l -> l
1111

1212
let nsplitc_enum str sep =
1313
let p = ref 0 in
@@ -100,14 +100,14 @@ let divide s sep = try String.split s sep with Invalid_string -> s, ""
100100
let dividec s sep = try splitc s sep with Not_found -> s, ""
101101

102102
let qreplace str sub by =
103-
Pcre.qreplace ~rex:(Pcre.regexp @@ Pcre.quote sub) ~templ:by str
103+
Pcre2.qreplace ~rex:(Pcre2.regexp @@ Pcre2.quote sub) ~templ:by str
104104

105105
let replace_all ~str ~sub ~by = qreplace str sub by
106106

107107
(** contents of the first submatch *)
108108
let extract rex str =
109109
try
110-
Some (Pcre.extract ~rex ~full_match:false str).(0)
110+
Some (Pcre2.extract ~rex ~full_match:false str).(0)
111111
with
112112
_ -> None
113113

@@ -158,11 +158,11 @@ let iexists s sub =
158158
(** sequence of matches *)
159159
let enum_matches rex s =
160160
try
161-
Pcre.exec_all ~rex s |> Array.enum
161+
Pcre2.exec_all ~rex s |> Array.enum
162162
with
163163
_ -> Enum.empty ()
164164

165-
let enum_extract rex s = enum_matches rex s |> Enum.map (flip Pcre.get_substring 1)
165+
let enum_extract rex s = enum_matches rex s |> Enum.map (flip Pcre2.get_substring 1)
166166

167167
module ASCII = struct
168168
let is_alpha = function

0 commit comments

Comments
 (0)