From: curt Date: Wed, 26 Feb 2003 19:50:14 +0000 (+0000) Subject: Add some convenience functions to the SGPath function. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1dac4b2dc1c4f855eeb2dfa702cb5d79ecd667b7;p=simgear.git Add some convenience functions to the SGPath function. --- diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index d171c073..f18543a7 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -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 { diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 429097f4..045f584a 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -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 */