Skip to content

Commit

Permalink
use List.*_opt instead of functions raising Not_found in a couple o…
Browse files Browse the repository at this point in the history
…f places
  • Loading branch information
v-gb committed Dec 18, 2024
1 parent d686cce commit 4a6b874
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion markup.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
25 changes: 10 additions & 15 deletions src/namespace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,8 +32,6 @@ struct
in
prefix, suffix

with Not_found -> ("", qualified_name)

let init top_level =
let f = function
| "xml" -> Some xml_ns
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 4a6b874

Please sign in to comment.