> string ChangeExtension(string const & oldname, string const & extension,
> bool no_path)
> {
> string::size_type last_slash = oldname.rfind('/');
> string::size_type last_dot;
This is fine.
> if (last_slash != string::npos)
> last_dot = oldname.find('.', last_slash);
> // Note : I checked that changing this line to
> //
> // last_dot = oldname.rfind('.');
> //
> // make the exported file be "A.B.ps". But that may
> // break some other things ... Sorry, I do not know
> // the behavior of rfind() and find() when nothing is
> // found, so I cannot fix the problem for sure.
> else
> last_dot = oldname.rfind('.');
I think something like this is needed instead of the above
last_dot = oldname.rfind('.');
if (last_slash != string::npos &&
last_dot != string::npos &&
last_dot < last_slash) {
last_dot = string::npos;
}
The problem is that we have to handle a path like this
"/this.is.a/trickyfilename"
where the last dot is not part of the filename.
It that case, it's not correct to truncate from the last dot.
Greets,
Asger