Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / utility / path.cpp
index 44fe331b60f2ca9a44cddc09483e06d9445bdcde..1302d30f978b57d323732f0d6e32c2eb6f5452f5 100644 (file)
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_utility
  */
+#include "gmxpre.h"
+
 #include "path.h"
 
+#include "config.h"
+
 #include <cctype>
 #include <cerrno>
 #include <cstdlib>
@@ -48,9 +52,8 @@
 
 #include <algorithm>
 
-#include "config.h"
-
 #include <sys/stat.h>
+
 #ifdef GMX_NATIVE_WINDOWS
 #include <direct.h>
 #else
@@ -165,6 +168,18 @@ std::string Path::getFilename(const std::string &path)
     return path.substr(pos+1);
 }
 
+std::string Path::stripExtension(const std::string &path)
+{
+    size_t dirSeparatorPos = path.find_last_of(cDirSeparators);
+    size_t extPos          = path.find_last_of('.');
+    if (extPos == std::string::npos
+        || (dirSeparatorPos != std::string::npos && extPos < dirSeparatorPos))
+    {
+        return path;
+    }
+    return path.substr(0, extPos);
+}
+
 std::string Path::normalize(const std::string &path)
 {
     std::string result(path);