Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sometimes use List.*_opt instead of functions raising Not_found #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading