From 291baaf328bec2f099e7f1e2732aae1102b3fe7d Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Tue, 30 Oct 2012 14:05:32 +0100
Subject: [PATCH] Add findLastPathSeparator().

---
 BaseLib/FileTools.cpp | 5 +++++
 BaseLib/FileTools.h   | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index 2786933eac0..b37dc9603de 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -59,6 +59,11 @@ void truncateFile( std::string const& filename)
     ofs.close();
 }
 
+size_t findLastPathSeparator(std::string const& path)
+{
+	return path.find_last_of("/\\");
+}
+
 std::string getFileNameFromPath(const std::string &str, bool with_extension)
 {
 	std::string::size_type beg1 = str.find_last_of('/');
diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h
index 6cfb4f8e4ac..970146c5e69 100644
--- a/BaseLib/FileTools.h
+++ b/BaseLib/FileTools.h
@@ -21,6 +21,13 @@
 namespace BaseLib
 {
 
+/** Finds the position of last file path separator.
+ * Checks for unix or windows file path separators in given path and returns the
+ * position of the last one or std::string::npos if no file path separator was
+ * found.
+ */
+size_t findLastPathSeparator(std::string const& path);
+
 /**
  * \brief Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
  *
-- 
GitLab