Octachron / codept

Contextual Ocaml DEPendencies Tool: alternative ocaml dependency analyzer
Other
59 stars 10 forks source link

Issue with `Support.remove_extension` #16

Closed dinosaure closed 1 year ago

dinosaure commented 1 year ago

I think it's not really expected but the current implementation of Support.remove_extension does not have the same behavior as Filename.remove_extension (on OCaml 4.14).

extension_pos name =
    let n = String.length name in
  let r = try String.rindex name '.' with Not_found -> n-1 in
    if r = 0 then
      try String.rindex name '.' with Not_found -> n-1
    else r

let extension name =
  let n = String.length name in
  let r = extension_pos name in
  String.sub name (r+1) (n-r-1)

let remove_extension name =
  let r = extension_pos name in
  String.sub name 0 r

let () = print_endline (remove_extension "foo")
let () = assert (remove_extension "foo" = Filename.remove_extension "foo")