Boost logo

Boost :

From: mfdylan (dylan_at_[hidden])
Date: 2002-01-31 20:02:23


--- In boost_at_y..., Glen Knowles <gknowles_at_c...> wrote:
> I do like having a path class rather then a simple string so that I
can use
> member functions to access path components, get canonical name, etc.
> Policies could be used to implement some of this functionality with
prebuilt
> packages for windows and unix.
>

Or even within a particular platform. For instance Windows Explorer
generally treats anything after the *last* dot as the file
suffix/extension, but in a lot of cases it makes far more sense to
use everything after/including the *first* dot of the filename as the
suffix. There are a growing number of software packages around these
days that use multi-part suffixes, and it's often the first part of
the suffix that's more important, eg some CAD packages use
my_file.prt.1, my_file.prt.2 etc for different versions. In this
case the 'prt' is the important part, Windows Explorer however
thinks these are '1' and '2' files...
Likewise config. mgmt. software often added extra suffixies -
ClearCase uses .keep and .config plus versioning, so something like
my_file.cpp.keep.2 is not uncommon. In this case I would like to be
able to determine all the different "suffix" portions, with a way to
specifying as to what the "whole suffix" is.
And how are .config files in Unix with no basenames to be treated?
POSIX basename only strips the specified suffix iff there is
something before it, so

> basename file.cshrc .cshrc
file
> basename .cshrc .cshrc
.cshrc

On possibility would be for a suffix() call that took either no or
one argument:

pathname p("/home.dylan/file.cpp.keep.1");
assert(p.suffix() == ".cpp.keep.1");
assert(p.suffix(1) == ".cpp");
assert(p.suffix(2) == ".keep");
assert(p.suffix(3) == ".1");
assert(p.suffix(-1) == ".1");
assert(p.suffix(-2) == ".keep.1");
assert(p.suffix(-3) == ".cpp.keep.1");

Likewise for basename

p.basename() = "file.cpp.keep.1"
assert(p.basename(1) == "file");
assert(p.basename(2) == "file.cpp");
assert(p.basename(3) == "file.cpp.keep");
assert(p.basename(4) == "file.cpp.keep.1");

but also (in the tradition of POSIX basename)

assert(p.basename(".1") == "file.cpp.keep");
assert(p.basename(".cpp.keep.1") == "file");
assert(p.basename(p.suffix()) == "file");

Only then you need a separate function to modify the basename
(modify_basename?) which I don't think is a big deal (I've never
liked the policy of using a property name as a 'setting' function.
Unfortunately there's not always obvious verb choices in the manner
of capacity/reserve, size/resize etc).

Random ideas continue...

assert(p.dirname() == "/home.dylan");
assert(p.dirname().dirname() == "/");
assert(p.dirname().suffix() == ".dylan");
assert(p.suffix().suffix() == ".cpp.keep");
assert(p.basename(".1").basename(".keep") == "file.cpp");

etc. etc.

Dylan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk