summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorSebastien Barre <sebastien.barre@kitware.com>2001-05-25 01:17:02 (GMT)
committerSebastien Barre <sebastien.barre@kitware.com>2001-05-25 01:17:02 (GMT)
commit3546e5611c4dce84f604f0ca826f49b70c0cc73e (patch)
tree5725285b6dd83768501e8a7c160a633f1a240258 /Source/cmSystemTools.cxx
parent2533d55099a5f278fe9c84ead0996176d18b88a0 (diff)
downloadCMake-3546e5611c4dce84f604f0ca826f49b70c0cc73e.zip
CMake-3546e5611c4dce84f604f0ca826f49b70c0cc73e.tar.gz
CMake-3546e5611c4dce84f604f0ca826f49b70c0cc73e.tar.bz2
New functions used to extract the components of a full filename.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx85
1 files changed, 82 insertions, 3 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index f524750..4af4242 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -314,7 +314,7 @@ bool cmSystemTools::FileExists(const char* filename)
// Return a capitalized string (i.e the first letter is uppercased, all other
// are lowercased)
-std::string cmSystemTools::Capitalized(std::string& s)
+std::string cmSystemTools::Capitalized(const std::string& s)
{
std::string n;
n.resize(s.size());
@@ -874,8 +874,9 @@ std::string cmSystemTools::GetProgramPath(const char* in_name)
}
/**
- * Given the path to a program executable, get the directory part of the path with the
- * file stripped off. If there is no directory part, the empty string is returned.
+ * Given the path to a program executable, get the directory part of the path
+ * with the file stripped off. If there is no directory part, the empty
+ * string is returned.
*/
void cmSystemTools::SplitProgramPath(const char* in_name,
std::string& dir,
@@ -934,3 +935,81 @@ std::string cmSystemTools::CollapseFullPath(const char* in_name)
return newPath;
}
+/**
+ * Return path of a full filename (no trailing slashes).
+ * Warning: returned path is converted to Unix slashes format.
+ */
+std::string cmSystemTools::GetFilenamePath(const std::string& filename)
+{
+ std::string fn = filename;
+ cmSystemTools::ConvertToUnixSlashes(fn);
+
+ std::string::size_type slash_pos = fn.rfind("/");
+ if(slash_pos != std::string::npos)
+ {
+ return fn.substr(0, slash_pos);
+ }
+ else
+ {
+ return "";
+ }
+}
+
+
+/**
+ * Return file name of a full filename (i.e. file name without path).
+ */
+std::string cmSystemTools::GetFilenameName(const std::string& filename)
+{
+ std::string fn = filename;
+ cmSystemTools::ConvertToUnixSlashes(fn);
+
+ std::string::size_type slash_pos = fn.rfind("/");
+ if(slash_pos != std::string::npos)
+ {
+ return fn.substr(slash_pos + 1);
+ }
+ else
+ {
+ return filename;
+ }
+}
+
+
+/**
+ * Return file extension of a full filename (dot included).
+ * Warning: this is the longest extension (for example: .tar.gz)
+ */
+std::string cmSystemTools::GetFilenameExtension(const std::string& filename)
+{
+ std::string name = cmSystemTools::GetFilenameName(filename);
+ std::string::size_type dot_pos = name.find(".");
+ if(dot_pos != std::string::npos)
+ {
+ return name.substr(dot_pos);
+ }
+ else
+ {
+ return "";
+ }
+}
+
+
+/**
+ * Return file name without extension of a full filename (i.e. without path).
+ * Warning: it considers the longest extension (for example: .tar.gz)
+ */
+std::string cmSystemTools::GetFilenameNameWithoutExtension(const std::string& filename)
+{
+ std::string name = cmSystemTools::GetFilenameName(filename);
+ std::string::size_type dot_pos = name.find(".");
+ if(dot_pos != std::string::npos)
+ {
+ return name.substr(0, dot_pos);
+ }
+ else
+ {
+ return name;
+ }
+}
+