From 4a6b874f5f6dc8e418a1c754338e73a5dba0e6cd Mon Sep 17 00:00:00 2001 From: Valentin Gatien-Baron Date: Wed, 18 Dec 2024 22:14:37 +0100 Subject: [PATCH] use `List.*_opt` instead of functions raising Not_found in a couple of places --- .github/workflows/test.yml | 2 -- markup.opam | 2 +- src/namespace.ml | 25 ++++++++++--------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f078aa..49f024f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,8 +17,6 @@ jobs: - 4.07.1 - 4.06.1 - 4.05.0 - - 4.04.2 - - 4.03.0 steps: - uses: actions/checkout@v2 diff --git a/markup.opam b/markup.opam index 073f164..b0473f2 100644 --- a/markup.opam +++ b/markup.opam @@ -13,7 +13,7 @@ dev-repo: "git+https://github.com/aantron/markup.ml.git" depends: [ "dune" {>= "2.7.0"} - "ocaml" {>= "4.03.0"} + "ocaml" {>= "4.05.0"} "uchar" "uutf" {>= "1.0.0"} diff --git a/src/namespace.ml b/src/namespace.ml index 5286757..395db2f 100644 --- a/src/namespace.ml +++ b/src/namespace.ml @@ -21,10 +21,9 @@ struct type context = context_entry ref let parse qualified_name = - try - let colon_index = String.index qualified_name ':' in - if colon_index = 0 then - raise Not_found; + match String.index_opt qualified_name ':' with + | None | Some 0 -> ("", qualified_name) + | Some colon_index -> let prefix = String.sub qualified_name 0 colon_index in let suffix = String.sub qualified_name @@ -33,8 +32,6 @@ struct in prefix, suffix - with Not_found -> ("", qualified_name) - let init top_level = let f = function | "xml" -> Some xml_ns @@ -127,15 +124,13 @@ struct in let prefix = - try - Some (candidate_prefixes |> List.find (fun prefix -> - (allow_default || prefix <> "") && - begin - try StringMap.find prefix !(fst context).prefix_to_namespace = - namespace - with Not_found -> false - end)) - with Not_found -> None + candidate_prefixes |> List.find_opt (fun prefix -> + (allow_default || prefix <> "") && + begin + try StringMap.find prefix !(fst context).prefix_to_namespace = + namespace + with Not_found -> false + end) in let prefix =