On Tue, 25 Jan 2005 13:32:29 +0200, Krasimir Angelov
<[EMAIL PROTECTED]> wrote:
> >> 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").
> 
> I will take a look at this. I also don't know which case is more natural.

("foo.bar.", "") is more natural for me because it eleminates the
special case for "." and "..". The original definition of splitFileExt
is:

splitFileExt :: FilePath -> (String, String)
splitFileExt p =
  case pre of
        []      -> (p, [])
        (_:pre) -> (reverse (pre++path), reverse suf)
  where
    (fname,path) = break isPathSeparator (reverse p)
    (suf,pre) | fname == "." || fname == ".." = (fname,"")
              | otherwise                     = break (== '.') fname

The definition can be changed to:

splitFileExt :: FilePath -> (String, String)
splitFileExt p =
  case break (== '.') fname of
        (suf@(_:_),_:pre) -> (reverse (pre++path), reverse suf)
        _                 -> (p, [])
  where
    (fname,path) = break isPathSeparator (reverse p)

The letter is simplier, it doesn't treat "." and ".." as special cases
and for it
splitFileExt "foo.bar." == ("foo.bar.", "")

Cheers,
  Krasimir
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to