From 0631b6567875730675d69bbe7519513fd15c66d1 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 30 Oct 2012 13:13:14 +0100
Subject: [PATCH] moved functions getFileNameFromPath(), getSuffixFromPath(),
 copyPathToFileName() and extractPath() from files StringTools.{cpp,h} to
 files FileTools.{cpp,h}

---
 BaseLib/FileTools.cpp                   | 52 ++++++++++++++++++++++++
 BaseLib/FileTools.h                     | 22 ++++++++++
 BaseLib/StringTools.cpp                 | 53 -------------------------
 BaseLib/StringTools.h                   | 24 -----------
 FileIO/GMSInterface.cpp                 |  5 ++-
 FileIO/Legacy/MeshIO.cpp                | 11 +++--
 FileIO/Legacy/OGSIOVer4.cpp             |  5 ++-
 FileIO/MeshIO/GMSHInterface.cpp         |  2 +-
 FileIO/RapidXmlIO/RapidStnInterface.cpp |  8 +++-
 FileIO/RapidXmlIO/RapidVtuInterface.cpp |  1 +
 FileIO/XmlIO/XmlStnInterface.cpp        |  9 +++--
 FileIO/readMeshFromFile.cpp             |  7 +++-
 SimpleTests/MeshTests/MeshRead.cpp      |  1 +
 13 files changed, 110 insertions(+), 90 deletions(-)

diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index 16d0ee3d59c..bbf7f4b14de 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -59,5 +59,57 @@ void truncateFile( std::string const& filename)
     ofs.close();
 }
 
+std::string getFileNameFromPath(const std::string &str, bool with_extension)
+{
+	std::string::size_type beg1 = str.find_last_of('/');
+	std::string::size_type beg2 = str.find_last_of('\\');
+	std::string::size_type beg;
+	if (beg1 == std::string::npos && beg2 == std::string::npos) beg = -1;
+	else if (beg1 == std::string::npos) beg = beg2;
+	else if (beg2 == std::string::npos) beg = beg1;
+	else beg = (beg1<beg2) ? beg2 : beg1;
+	std::string file ( str.substr(beg+1) );
+	if (with_extension) return file;
+	// cut extension
+	std::string::size_type end  = file.find_last_of('.');
+	return file.substr(0,end);
+}
+
+std::string getSuffixFromPath(const std::string &str)
+{
+	std::string::size_type beg(str.find_last_of('.'));
+	return str.substr(beg+1, str.length()-beg-1);
+}
+
+std::string copyPathToFileName(const std::string &file_name, const std::string &source)
+{
+	// check if file_name already contains a full path
+	size_t pos(file_name.rfind("/")); // linux, mac delimiter
+	if (pos == std::string::npos)
+	{
+		pos = file_name.rfind("\\"); // windows delimiter
+		if (pos == std::string::npos)
+		{
+			std::string path;
+			BaseLib::extractPath(source, path);
+			return path.append(file_name);
+		}
+		else return std::string(file_name);
+	}
+	else return std::string(file_name);
+}
+
+void extractPath(std::string const& fname, std::string& path)
+{
+	// extract path for reading external files
+	size_t pos(fname.rfind("/")); // linux, mac delimiter
+	if (pos == std::string::npos) {
+		pos = fname.rfind("\\"); // windows delimiter
+		if (pos == std::string::npos)
+			pos = 0;
+	}
+	path = fname.substr(0, pos==0 ? pos : pos + 1);
+}
+
 } // end namespace BaseLib
 
diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h
index efe52b9826a..2649ac0f81f 100644
--- a/BaseLib/FileTools.h
+++ b/BaseLib/FileTools.h
@@ -47,6 +47,28 @@ template <typename T> void writeValueBinary(std::ostream &out, T const& val)
  */
 void truncateFile( std::string const& file_path);
 
+/**
+ * Extract the filename from a path
+ */
+std::string getFileNameFromPath(const std::string &str, bool with_extension = false);
+
+/**
+ * Extract the file type / suffix from a path
+ */
+std::string getSuffixFromPath(const std::string &str);
+
+
+/**
+ * Checks if file_name already contains a qualified path and if not copies the path from source.
+ */
+std::string copyPathToFileName(const std::string &file_name, const std::string &source);
+
+/**
+ * extracts the path of a fully qualified path name of the file
+ * @param fname [input] the fully qualified path name of the file
+ * @param path [output] the path of the fully qualified path name of the file
+ */
+void extractPath(std::string const& fname, std::string& path);
 } // end namespace BaseLib
 
 #endif // FILETOOLS_H
diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp
index 63b2d79a495..e752f605f9e 100644
--- a/BaseLib/StringTools.cpp
+++ b/BaseLib/StringTools.cpp
@@ -49,59 +49,6 @@ void trim(std::string &str, char ch)
   else str.erase(str.begin(), str.end());
 }
 
-std::string getFileNameFromPath(const std::string &str, bool with_extension)
-{
-	std::string::size_type beg1 = str.find_last_of('/');
-	std::string::size_type beg2 = str.find_last_of('\\');
-	std::string::size_type beg;
-	if (beg1 == std::string::npos && beg2 == std::string::npos) beg = -1;
-	else if (beg1 == std::string::npos) beg = beg2;
-	else if (beg2 == std::string::npos) beg = beg1;
-	else beg = (beg1<beg2) ? beg2 : beg1;
-	std::string file ( str.substr(beg+1) );
-	if (with_extension) return file;
-	// cut extension
-	std::string::size_type end  = file.find_last_of('.');
-	return file.substr(0,end);
-}
-
-std::string getSuffixFromPath(const std::string &str)
-{
-	std::string::size_type beg (str.find_last_of('.'));
-	return str.substr(beg+1, str.length()-beg-1);
-}
-
-std::string copyPathToFileName(const std::string &file_name, const std::string &source)
-{
-	// check if file_name already contains a full path
-	size_t pos(file_name.rfind("/")); // linux, mac delimiter
-	if (pos == std::string::npos)
-	{
-		pos = file_name.rfind("\\"); // windows delimiter
-		if (pos == std::string::npos)
-		{
-			std::string path;
-			BaseLib::extractPath(source, path);
-			return path.append(file_name);
-		}
-		else return std::string(file_name);
-	}
-	else return std::string(file_name);
-}
-
-
-void extractPath (std::string const& fname, std::string& path)
-{
-	// extract path for reading external files
-	size_t pos(fname.rfind("/")); // linux, mac delimiter
-	if (pos == std::string::npos) {
-		pos = fname.rfind("\\"); // windows delimiter
-		if (pos == std::string::npos)
-			pos = 0;
-	}
-	path = fname.substr(0, pos==0 ? pos : pos + 1);
-}
-
 } // end namespace BaseLib
 
 
diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h
index 89af747bba5..29061d08d24 100644
--- a/BaseLib/StringTools.h
+++ b/BaseLib/StringTools.h
@@ -70,30 +70,6 @@ template<typename T> T str2number (const std::string &str)
  */
 void trim(std::string &str, char ch=' ');
 
-/**
- * Extract the filename from a path
- */
-std::string getFileNameFromPath(const std::string &str, bool with_extension = false);
-
-/**
- * Extract the file type / suffix from a path
- */
-std::string getSuffixFromPath(const std::string &str);
-
-
-/**
- * Checks if file_name already contains a qualified path and if not copies the path from source.
- */
-std::string copyPathToFileName(const std::string &file_name, const std::string &source);
-
-/**
- * extracts the path of a fully qualified path name of the file
- * @param fname [input] the fully qualified path name of the file
- * @param path [output] the path of the fully qualified path name of the file
- */
-void extractPath (std::string const& fname, std::string& path);
-
-
 } // end namespace BaseLib
 
 #ifdef MSVC
diff --git a/FileIO/GMSInterface.cpp b/FileIO/GMSInterface.cpp
index 47178575c90..a65c3cd2298 100644
--- a/FileIO/GMSInterface.cpp
+++ b/FileIO/GMSInterface.cpp
@@ -9,6 +9,8 @@
  * Created on 2010-06-08 by Karsten Rink
  */
 
+#include <fstream>
+
 #include "GMSInterface.h"
 #include "Station.h"
 #include "Mesh.h"
@@ -17,8 +19,9 @@
 #include "Elements/Pyramid.h"
 #include "Elements/Prism.h"
 #include "MshEnums.h"
+// BaseLib
 #include "StringTools.h"
-#include <fstream>
+#include "FileTools.h"
 
 int GMSInterface::readBoreholesFromGMS(std::vector<GeoLib::Point*>* boreholes,
                                        const std::string &filename)
diff --git a/FileIO/Legacy/MeshIO.cpp b/FileIO/Legacy/MeshIO.cpp
index 55a93e851cc..0717314aaf0 100644
--- a/FileIO/Legacy/MeshIO.cpp
+++ b/FileIO/Legacy/MeshIO.cpp
@@ -10,7 +10,13 @@
  * Created on 2012-05-08 by Karsten Rink
  */
 
+#include <iomanip>
+#include <sstream>
+
+// GeoLib
 #include "GEOObjects.h"
+
+// MeshLib
 #include "MeshIO.h"
 #include "Node.h"
 #include "Elements/Edge.h"
@@ -21,10 +27,9 @@
 #include "Elements/Pyramid.h"
 #include "Elements/Prism.h"
 
+// BaseLib
 #include "StringTools.h"
-
-#include <iomanip>
-#include <sstream>
+#include "FileTools.h"
 
 namespace FileIO
 {
diff --git a/FileIO/Legacy/OGSIOVer4.cpp b/FileIO/Legacy/OGSIOVer4.cpp
index 47e65d3f293..2d41e601fdd 100644
--- a/FileIO/Legacy/OGSIOVer4.cpp
+++ b/FileIO/Legacy/OGSIOVer4.cpp
@@ -16,11 +16,12 @@
 #include "MeshIO/GMSHInterface.h"
 #include "OGSIOVer4.h"
 
-// Base
+// BaseLib
 #include "StringTools.h"
+#include "FileTools.h"
 #include "quicksort.h"
 
-// GEO
+// GeoLib
 #include "GEOObjects.h"
 #include "Point.h"
 #include "Polygon.h"
diff --git a/FileIO/MeshIO/GMSHInterface.cpp b/FileIO/MeshIO/GMSHInterface.cpp
index 8838ffc6545..7c60bad6f89 100644
--- a/FileIO/MeshIO/GMSHInterface.cpp
+++ b/FileIO/MeshIO/GMSHInterface.cpp
@@ -17,7 +17,7 @@
 #include "StringTools.h"
 #include "Configure.h"
 #include "BuildInfo.h"
-#include "StringTools.h"
+#include "FileTools.h"
 
 // FileIO
 #include "GMSHInterface.h"
diff --git a/FileIO/RapidXmlIO/RapidStnInterface.cpp b/FileIO/RapidXmlIO/RapidStnInterface.cpp
index 9b4d9dc3b3d..6bd313e7517 100644
--- a/FileIO/RapidXmlIO/RapidStnInterface.cpp
+++ b/FileIO/RapidXmlIO/RapidStnInterface.cpp
@@ -8,11 +8,17 @@
  *
  *  Created on 2012-08-16 by Karsten Rink
  */
+
+#include <iostream>
+
 //RapidXML
 #include "RapidStnInterface.h"
-#include <iostream>
 
+// BaseLib
 #include "StringTools.h"
+#include "FileTools.h"
+
+// GeoLib
 #include "Station.h"
 
 namespace FileIO
diff --git a/FileIO/RapidXmlIO/RapidVtuInterface.cpp b/FileIO/RapidXmlIO/RapidVtuInterface.cpp
index 83a05b7f58d..1dc0bd180c8 100644
--- a/FileIO/RapidXmlIO/RapidVtuInterface.cpp
+++ b/FileIO/RapidXmlIO/RapidVtuInterface.cpp
@@ -15,6 +15,7 @@
 
 #include "RapidXML/rapidxml_print.hpp"
 #include "StringTools.h"
+#include "FileTools.h"
 #include "ProjectData.h"
 
 // MSH
diff --git a/FileIO/XmlIO/XmlStnInterface.cpp b/FileIO/XmlIO/XmlStnInterface.cpp
index 52a0f085ebb..a4dd078c87f 100644
--- a/FileIO/XmlIO/XmlStnInterface.cpp
+++ b/FileIO/XmlIO/XmlStnInterface.cpp
@@ -10,14 +10,17 @@
  * Created on 2011-11-23 by Karsten Rink
  */
 
-#include "XmlStnInterface.h"
-#include "DateTools.h"
 #include <limits>
+#include <iostream>
 
 #include <QFile>
 #include <QtXml/QDomDocument>
 
-#include <iostream>
+#include "XmlStnInterface.h"
+
+// BaseLib
+#include "DateTools.h"
+#include "FileTools.h"
 
 namespace FileIO
 {
diff --git a/FileIO/readMeshFromFile.cpp b/FileIO/readMeshFromFile.cpp
index ad817c8a210..faa38a619bf 100644
--- a/FileIO/readMeshFromFile.cpp
+++ b/FileIO/readMeshFromFile.cpp
@@ -11,11 +11,14 @@
  */
 
 #include "readMeshFromFile.h"
-#include "StringTools.h"
 #include "Mesh.h"
 #include "RapidXmlIO/RapidVtuInterface.h"
 #include "Legacy/MeshIO.h"
 
+// BaseLib
+#include "StringTools.h"
+#include "FileTools.h"
+
 namespace FileIO {
 
 MeshLib::Mesh* readMeshFromFile(const std::string &file_name)
@@ -36,4 +39,4 @@ MeshLib::Mesh* readMeshFromFile(const std::string &file_name)
 	return mesh;
 }
 
-}
\ No newline at end of file
+}
diff --git a/SimpleTests/MeshTests/MeshRead.cpp b/SimpleTests/MeshTests/MeshRead.cpp
index dc14c0fac49..a45edf5ffb6 100644
--- a/SimpleTests/MeshTests/MeshRead.cpp
+++ b/SimpleTests/MeshTests/MeshRead.cpp
@@ -8,6 +8,7 @@
 #include "MemWatch.h"
 #include "RunTime.h"
 #include "StringTools.h"
+#include "FileTools.h"
 #include "tclap/CmdLine.h"
 #include "LogogSimpleFormatter.h"
 
-- 
GitLab