Fix misidentification of dot in path name
authorRoland Schulz <roland@utk.edu>
Thu, 9 Oct 2014 01:20:47 +0000 (21:20 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 12 Oct 2014 13:17:25 +0000 (15:17 +0200)
Commit df876d6c7b5 added support for custom default extensions
but it didn't work correctly for directory names containing dots.

Change-Id: I427f694a36496bd8a6f59e3083feb5b8269a62c4

src/gromacs/commandline/pargs.cpp
src/gromacs/utility/path.cpp
src/gromacs/utility/path.h

index 8b7a459d8f3561038cbd1b4bf6f250c2922bb5b3..48c540e5a3f89bec7692fe499a987e5f7b1e6f4d 100644 (file)
@@ -60,6 +60,7 @@
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/path.h"
 #include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
@@ -334,7 +335,7 @@ void OptionsAdapter::filenmToOptions(Options *options, t_filenm *fnm)
     {
         defName = ftp2defnm(fnm->ftp);
     }
-    else if (std::strchr(defName, '.') != NULL)
+    else if (Path::hasExtension(defName))
     {
         defType = fn2ftp(defName);
         GMX_RELEASE_ASSERT(defType != efNR,
index 1302d30f978b57d323732f0d6e32c2eb6f5452f5..afbf81468f9fbe887d2d6791e65f89ad97f67b5e 100644 (file)
@@ -168,6 +168,11 @@ std::string Path::getFilename(const std::string &path)
     return path.substr(pos+1);
 }
 
+bool Path::hasExtension(const std::string &path)
+{
+    return getFilename(path).find('.') != std::string::npos;
+}
+
 std::string Path::stripExtension(const std::string &path)
 {
     size_t dirSeparatorPos = path.find_last_of(cDirSeparators);
index faadab1c49fe28ed277075b0babe0b682a43741c..fcecd2f866d68213e07c376820608256851f265b 100644 (file)
@@ -67,6 +67,7 @@ class Path
         static std::string normalize(const std::string &path);
         static std::string getParentPath(const std::string &path);
         static std::string getFilename(const std::string &path);
+        static bool hasExtension(const std::string &path);
         static std::string stripExtension(const std::string &path);
 
         static bool exists(const char *path);