Add some convenience functions to the SGPath function.

This commit is contained in:
curt
2003-02-26 19:50:14 +00:00
parent 44e7b36a8b
commit 1dac4b2dc1
2 changed files with 45 additions and 8 deletions

View File

@@ -104,6 +104,17 @@ void SGPath::concat( const string& p ) {
}
// Get the file part of the path (everything after the last path sep)
string SGPath::file() {
int index = path.rfind(SG_PATH_SEP);
if (index >= 0) {
return path.substr(index + 1);
} else {
return "";
}
}
// get the directory part of the path.
string SGPath::dir() {
int index = path.rfind(SG_PATH_SEP);
@@ -114,10 +125,24 @@ string SGPath::dir() {
}
}
string SGPath::filename() {
int index = path.rfind(SG_PATH_SEP);
if (index < 0) index = 0;
return path.substr(index);
// get the base part of the path (everything but the extension.)
string SGPath::base() {
int index = path.rfind(".");
if (index >= 0) {
return path.substr(0, index);
} else {
return "";
}
}
// get the extention (everything after the final ".")
string SGPath::extension() {
int index = path.rfind(".");
if (index >= 0) {
return path.substr(index + 1);
} else {
return "";
}
}
bool SGPath::exists() const {

View File

@@ -94,6 +94,12 @@ public:
*/
void concat( const string& p );
/**
* Get the file part of the path (everything after the last path sep)
* @return file string
*/
string file();
/**
* Get the directory part of the path.
* @return directory string
@@ -101,11 +107,17 @@ public:
string dir();
/**
* Return the filename part of the path.
* @return file name string
* Get the base part of the path (everything but the extension.)
* @return the base string
*/
string filename();
string base();
/**
* Get the extention part of the path (everything after the final ".")
* @return the extention string
*/
string extension();
/** Get the path string
* @return path string
*/