Make sure that a directory name containing a '.' doesn't screw up the ::base() and ::extension() functions.

This commit is contained in:
ehofman 2004-07-05 16:39:02 +00:00
parent 8fe37cea51
commit 66996711ae

View File

@ -154,7 +154,7 @@ string SGPath::dir() const {
// get the base part of the path (everything but the extension.) // get the base part of the path (everything but the extension.)
string SGPath::base() const { string SGPath::base() const {
int index = path.rfind("."); int index = path.rfind(".");
if (index >= 0) { if ((index >= 0) && (path.find("/", index) == string::npos)) {
return path.substr(0, index); return path.substr(0, index);
} else { } else {
return ""; return "";
@ -162,9 +162,11 @@ string SGPath::base() const {
} }
// get the extention (everything after the final ".") // get the extention (everything after the final ".")
// but make sure no "/" follows the "." character (otherwise it
// is has to be a directory name containing a ".").
string SGPath::extension() const { string SGPath::extension() const {
int index = path.rfind("."); int index = path.rfind(".");
if (index >= 0) { if ((index >= 0) && (path.find("/", index) == string::npos)) {
return path.substr(index + 1); return path.substr(index + 1);
} else { } else {
return ""; return "";