bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57102: 29.0.50; Peculiar file-name-split edge case


From: Mattias Engdegård
Subject: bug#57102: 29.0.50; Peculiar file-name-split edge case
Date: Sat, 13 Aug 2022 19:08:00 +0200

The current behaviour of file-name-split is based on a purely textual splitting 
on "/" which isn't as useful as basing it on actual file name components. For 
instance, the root component of a Posix file name is "/", not "". Looking at 
other languages and libraries is very much encouraged; they vary a lot in the 
amount of thought that has gone into their design.

Ideally we'd have a split function (the name is a placeholder for now) where:

(split "/a/b/c") -> ("/" "a" "b" "c")
(split "a/b/c/") -> ("a" "b" "c" "")
(split "/") -> ("/" "")

and, because repeated slashes mean the same thing as a single one in Posix 
except at the beginning,
(split "//a//b//") -> ("//" "a" "b" "")

An accompanying join operation would be the inverse, sort of:
(join "/" "a" "b" "c") -> "/a/b/c"
(join "a" "b" "") -> "a/b/"

where empty strings are ignored except at the end:
(join "" "a" "" "" "b") -> "a/b"
(join "a" "b" "" "") -> "a/b/"

Pre-joined chunks can be joined too:
(join "/a/b" "c/d/" "e") -> "/a/b/c/d/e"

Maybe components with a leading slash start over from the root:
(join "/" "a" "/b" "c") -> "/a/b/c" ?
(join "/" "a" "/b" "c") -> "/b/c" ?

Python's os.path.join does the latter; it's probably a good idea.

Now `file-name-concat` almost works like `join` above but not quite. Adding a 
new function is likely better than making compromises.

On Windows I'd expect that

(split "c:\\a\\b") -> ("c:\\" "a" "b")
(split "c:\\") -> ("c:\\" "")

but it's a bit complicated and then we have all the UNC path variants to deal 
with; a platform expert should be consulted.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]