From 6b359ba8c0025d16168da1af4e5479b6a5e2858f Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Wed, 8 Oct 2014 21:20:47 -0400 Subject: [PATCH] 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 --- src/gromacs/commandline/pargs.cpp | 3 ++- src/gromacs/utility/path.cpp | 5 +++++ src/gromacs/utility/path.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) 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); -- 2.22.0