[m-rev.] for review: improve dir./
Zoltan Somogyi
zoltan.somogyi at runbox.com
Mon Sep 11 12:11:41 AEST 2023
On 2023-09-11 11:42 +10:00 AEST, "Peter Wang" <novalazy at gmail.com> wrote:
>> +:- pred is_path_string_canonical_loop(string::in, int::in, canon_prev_char::in)
>> + is semidet.
>> +
>> +is_path_string_canonical_loop(Path, CurIndex, PrevChar) :-
>> + ( if string.index_next(Path, CurIndex, NextIndex, Char) then
>
> The problem is string.index_next incurs a call to string.length for each
> call, unlike string.unsafe_index_next.
I forgot about that. We don't want those duplicated calls.
> It's quite easy to use
> unsafe_index_next safely, though.
Do you mean code like what the calls to index_next replaced,
or something else?
>> + else if dir.path_name_is_cur_drive_relative(FileName) then
>> unexpected($pred, "second argument is a current drive relative path")
>
> Simon Taylor called these types of paths "current drive relative paths"
> or "drive current paths" in commit 89a4d190c, but that terminology is
> confusing.
Agreed.
>> + % Is FileName a relative path of the form "C:foo"?
>> + %
>> +:- pred path_name_is_cur_drive_relative(string::in) is semidet.
>> +
>
> These kinds of paths are not relative to the *current* drive,
> but relative to the current directory on the specified drive.
> On Windows, each process has a current drive, and also a current
> directory per drive.
>
> I'm not sure there is a short, standard name for these kind of paths.
> I suggest "drive relative path" or "drive-letter relative path".
I prefer the last one: drive-letter relative path.
>> +path_name_is_cur_drive_relative(FileName) :-
>> + % In the following, C stands for any drive letter, and xyz for
>> + % non-special characters that can occur in filenames.
>> + ( if path_name_names_drive_letter(FileName, ThirdCharIndex) then
>> + ( if string.index_next(FileName, ThirdCharIndex, _, ThirdChar) then
>> + ( if is_directory_separator(ThirdChar) then
>> + % FileName is "C:/xyz", which is a cur drive path,
>> + % but an absolute one.
>> + fail
>
> Write the example the canonical way, i.e. "C:\xyz".
Julien now has custody of dir.m while he does his review.
I will make the changes above once he says he is done.
Zoltan.
More information about the reviews
mailing list