From: Roland Schulz Date: Thu, 9 Oct 2014 01:20:47 +0000 (-0400) Subject: Fix misidentification of dot in path name X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=6b359ba8c0025d16168da1af4e5479b6a5e2858f;p=alexxy%2Fgromacs.git Fix misidentification of dot in path name Commit df876d6c7b5 added support for custom default extensions but it didn't work correctly for directory names containing dots. Change-Id: I427f694a36496bd8a6f59e3083feb5b8269a62c4 --- diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 8b7a459d8f..48c540e5a3 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -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, diff --git a/src/gromacs/utility/path.cpp b/src/gromacs/utility/path.cpp index 1302d30f97..afbf81468f 100644 --- a/src/gromacs/utility/path.cpp +++ b/src/gromacs/utility/path.cpp @@ -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); diff --git a/src/gromacs/utility/path.h b/src/gromacs/utility/path.h index faadab1c49..fcecd2f866 100644 --- a/src/gromacs/utility/path.h +++ b/src/gromacs/utility/path.h @@ -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);