Deprecate Filename.chop_suffix in favor of check_and_chop_suffix.#1858
Deprecate Filename.chop_suffix in favor of check_and_chop_suffix.#1858whitequark wants to merge 2 commits intoocaml:trunkfrom
Conversation
stdlib/filename.mli
Outdated
| end with the suffix [suff]. *) | ||
| the filename [name]. | ||
|
|
||
| @since 4.08 If [name] does not end with the suffix [suff], |
There was a problem hiding this comment.
If one wants to fully specify the behavior, one should explain what "ending with the suffix" means (also for other existing functions). This is not straightforward: for Windows ports, the comparison is case-insensitive on ASCII characters; but not, for instance on macOS (whose file-system is also usually case-insensitive, I believe).
There was a problem hiding this comment.
I've specified chop_suffix in terms of check_suffix. Your suggestion could be done as a separate patch if there is desire to do so.
5a258a5 to
6c5369c
Compare
What do you mean? Earlier versions fails only when the suffix is longer than the filename. Since chop_suffix is likely to always be used in conjunction with check_suffix, I'm wondering whether it wouldn't be better to deprecate this function and expose: val chop_suffix_opt: string -> string -> string optionor even, using labels to avoid the confusion between the two string arguments: val chop_suffix_opt: suffix:string -> string -> string option |
Yes, that's what I meant--we should not change the behavior when the suffix is longer than the filename. If we changed
I have no opinion on this. I will implement whichever variant there is consensus for. |
|
I would expect a name like |
…7812) Filename.chop_suffix is currently documented as having undefined behavior on inputs that don't end with the suffix. The replacement does not have this drawback.
6c5369c to
a758c65
Compare
Filename.chop_suffix n s if n does not end with s|
Updated. |
val check_and_chop_suffix : suffix:string -> string -> string option |
alainfrisch
left a comment
There was a problem hiding this comment.
See previous comments.
|
See also https://caml.inria.fr/mantis/view.php?id=7867 for a bug that could have been avoided with the option-returning function. |
|
Superseded by #2125 |
See https://caml.inria.fr/mantis/view.php?id=7812.
The defined behavior on erroneous input is to always raise Invalid_argument. This is chosen as opposed to e.g. doing nothing because it matches the de-facto behavior on earlier versions (which would be to raise a different exception) and avoids surprises when developing code for 4.08+ and running it on an earlier version.See the PR discussion for details.