[Haskell-cafe] Re: File path programme

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Jan 23 17:05:04 EST 2005


Aaron Denney <wnoise at ofb.net> writes:

>> What about splitFileExt "foo.bar."? ("foo", "bar.") or ("foo.bar.", "")?
>
> The latter makes more sense to me, as an extension of the first case
> you give and splitting "foo.tar.gz" to ("foo.tar", "gz").

It's not that obvious: both choices are compatible with these.

The former is produced by rules:
- split the filename before the last dot *which is not the last
  character of the filename*, or at the end if there is no such dot
- remove the first character of the extension if it's non-empty
  (the character must have been a dot)

The latter is produced by rules:
- split the filename before the last dot, or at the end if there is
  no dot at all
- *if the extension is a sole dot, append a dot to the basename*
- remove the first character of the extension if it's non-empty
  (the character must have been a dot)

Special filenames of "." and ".." are treated separately, before these
rules apply.

Both choices are inverted by the same joinFileExt, which inserts a dot
between the name and extension unless the extension is empty.

These rules agree on "foo", "foo." and "foo.tar.gz", yet disagree on
"foo.bar."; I don't know which is more natural.

The difference influences the behavior of changeFileExt. These cases
are the same with both choices:
   changeFileExt "foo.bar" "" = "foo"
   changeFileExt "foo.tar.gz" "" = "foo.tar"
   changeFileExt "foo." "" = "foo."
   changeFileExt "foo." "baz" = "foo..baz"
but these differ - first choice:
   changeFileExt "foo.bar." "" = "foo"
   changeFileExt "foo.bar." "baz" = "foo.baz"
or the second:
   changeFileExt "foo.bar." "" = "foo.bar."
   changeFileExt "foo.bar." "baz" = "foo.bar..baz"
?

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Haskell-Cafe mailing list