From 2fd270ff64f96203bf7b580a102e8a900240931c Mon Sep 17 00:00:00 2001 From: Dmitrij Naumov <dmitrij@naumov.de> Date: Wed, 31 Oct 2012 15:08:25 +0100 Subject: [PATCH] Replace getSuffixFromPath() with getFileExtension(). --- BaseLib/FileTools.cpp | 2 +- BaseLib/FileTools.h | 4 +- FileIO/readMeshFromFile.cpp | 2 +- SimpleTests/MeshTests/MeshRead.cpp | 2 +- .../TestFilePathStringManipulation.cpp | 92 +++++++++---------- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index f874ba670fe..88ec37f123a 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -90,7 +90,7 @@ std::string extractBaseNameWithoutExtension(std::string const& pathname) return dropFileExtension(basename); } -std::string getSuffixFromPath(const std::string &path) +std::string getFileExtension(const std::string &path) { const std::string str = extractBaseName(path); const size_t p = findLastDot(str); diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index b33a3571549..3153fc6bc1a 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -65,9 +65,9 @@ std::string extractBaseName(std::string const& pathname); std::string extractBaseNameWithoutExtension(std::string const& pathname); /** - * Extract the file type / suffix from a path + * Extract extension from filename */ -std::string getSuffixFromPath(const std::string &str); +std::string getFileExtension(std::string const& filename); /** diff --git a/FileIO/readMeshFromFile.cpp b/FileIO/readMeshFromFile.cpp index faa38a619bf..f7f74d1ac4e 100644 --- a/FileIO/readMeshFromFile.cpp +++ b/FileIO/readMeshFromFile.cpp @@ -24,7 +24,7 @@ namespace FileIO { MeshLib::Mesh* readMeshFromFile(const std::string &file_name) { MeshLib::Mesh* mesh (NULL); - std::string suffix (BaseLib::getSuffixFromPath(file_name)); + std::string suffix (BaseLib::getFileExtension(file_name)); if (suffix.compare("msh") == 0 || suffix.compare("MSH") == 0) { diff --git a/SimpleTests/MeshTests/MeshRead.cpp b/SimpleTests/MeshTests/MeshRead.cpp index a45edf5ffb6..0c47cc4b4ac 100644 --- a/SimpleTests/MeshTests/MeshRead.cpp +++ b/SimpleTests/MeshTests/MeshRead.cpp @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) BaseLib::RunTime run_time; run_time.start(); MeshLib::Mesh* mesh(NULL); - if (BaseLib::getSuffixFromPath(fname).compare("msh") == 0) { + if (BaseLib::getFileExtension(fname).compare("msh") == 0) { mesh = mesh_io.loadMeshFromFile(fname); } else { mesh = FileIO::RapidVtuInterface::readVTUFile(fname); diff --git a/Tests/BaseLib/TestFilePathStringManipulation.cpp b/Tests/BaseLib/TestFilePathStringManipulation.cpp index 3d98d074ea6..03952bdabe7 100644 --- a/Tests/BaseLib/TestFilePathStringManipulation.cpp +++ b/Tests/BaseLib/TestFilePathStringManipulation.cpp @@ -33,56 +33,56 @@ TEST(BaseLib, FindLastPathSeparatorUnix) ASSERT_EQ ( BaseLib::findLastPathSeparator("/path/path/path/"), 15 ); } -TEST(BaseLib, GetSuffixFromPathWin) +TEST(BaseLib, GetFileExtensionWin) { - ASSERT_EQ ( BaseLib::getSuffixFromPath("file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path\\"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path\\file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\path\\file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\path\\path\\"), "" ); - - ASSERT_EQ ( BaseLib::getSuffixFromPath("file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path.ext\\"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path.ext\\"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\path\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path\\path\\path.ext\\"), "" ); - - ASSERT_EQ ( BaseLib::getSuffixFromPath("path.wrong\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path.wrong\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path.wrong0\\path.wrong\\file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("\\path.wrong0\\path.wrong\\path.ext\\"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("path\\"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("path\\file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\path\\file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\path\\path\\"), "" ); + + ASSERT_EQ ( BaseLib::getFileExtension("file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("path.ext\\"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path.ext\\"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("path\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\path\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path\\path\\path.ext\\"), "" ); + + ASSERT_EQ ( BaseLib::getFileExtension("path.wrong\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path.wrong\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path.wrong0\\path.wrong\\file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("\\path.wrong0\\path.wrong\\path.ext\\"), "" ); } -TEST(BaseLib, GetSuffixFromPathUnix) +TEST(BaseLib, getFileExtensionUnix) { - ASSERT_EQ ( BaseLib::getSuffixFromPath("file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path/"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path/file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/path/file"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/path/path/"), "" ); - - ASSERT_EQ ( BaseLib::getSuffixFromPath("file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path.ext/"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path.ext/"), "" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("path/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/path/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path/path/path.ext/"), "" ); - - ASSERT_EQ ( BaseLib::getSuffixFromPath("path.wrong/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path.wrong/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path.wrong0/path.wrong/file.ext"), "ext" ); - ASSERT_EQ ( BaseLib::getSuffixFromPath("/path.wrong0/path.wrong/path.ext/"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("/file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("path/"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("path/file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/path/file"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/path/path/"), "" ); + + ASSERT_EQ ( BaseLib::getFileExtension("file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("path.ext/"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path.ext/"), "" ); + ASSERT_EQ ( BaseLib::getFileExtension("path/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/path/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path/path/path.ext/"), "" ); + + ASSERT_EQ ( BaseLib::getFileExtension("path.wrong/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path.wrong/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path.wrong0/path.wrong/file.ext"), "ext" ); + ASSERT_EQ ( BaseLib::getFileExtension("/path.wrong0/path.wrong/path.ext/"), "" ); } TEST(BaseLib, CopyPathToFileNameWin) -- GitLab