From f030650a78f4efc41051fa5610de87af68c4771c Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Thu, 30 Apr 2015 18:32:09 +0200
Subject: [PATCH] [BL] Use boost for case insensitive comparison.

---
 BaseLib/FileTools.cpp   | 6 ++----
 BaseLib/FileTools.h     | 3 +--
 BaseLib/StringTools.cpp | 7 -------
 BaseLib/StringTools.h   | 8 --------
 4 files changed, 3 insertions(+), 21 deletions(-)

diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index 81b02ea4bb3..821ea0f9263 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -17,6 +17,7 @@
 
 #include <sys/stat.h>
 #include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
 
 namespace BaseLib
 {
@@ -116,10 +117,7 @@ std::string getFileExtension(const std::string &path)
 
 bool hasFileExtension(std::string const& extension, std::string const& filename)
 {
-	std::string ext = stringToUpper(extension); // Copy for modification.
-	std::string file_ext = stringToUpper(getFileExtension(filename));
-
-	return ext == file_ext;
+	return boost::iequals(extension, getFileExtension(filename));
 }
 
 std::string copyPathToFileName(const std::string &file_name,
diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h
index 2ff36669be3..feac59e53a7 100644
--- a/BaseLib/FileTools.h
+++ b/BaseLib/FileTools.h
@@ -129,8 +129,7 @@ std::string getFileExtension(std::string const& filename);
 
 /**
  * Compares filename's extension with query extension. The comparison is case
- * insensitive done by converting to upper case with the std::toupper()
- * function.
+ * insensitive.
  */
 bool hasFileExtension(std::string const& extension,
                       std::string const& filename);
diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp
index 3fc1f3e6702..7e78d9e3da8 100644
--- a/BaseLib/StringTools.cpp
+++ b/BaseLib/StringTools.cpp
@@ -72,13 +72,6 @@ void simplify(std::string &str)
 	);
 }
 
-std::string stringToUpper(std::string const& str)
-{
-    std::string s = str;
-	std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::toupper);
-    return s;
-}
-
 std::string padLeft(std::string const& str, int maxlen, char ch)
 {
 	std::stringstream ss(str);
diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h
index 521858dba17..19704d26369 100644
--- a/BaseLib/StringTools.h
+++ b/BaseLib/StringTools.h
@@ -22,7 +22,6 @@
 #include <sstream>
 #include <fstream>
 #include <iostream>
-#include <ctype.h>
 
 namespace BaseLib {
 
@@ -69,13 +68,6 @@ void trim(std::string &str, char ch=' ');
  */
 void simplify(std::string &str);
 
-/**
- * Returns same string with all characters in upper case.
- *
- * This uses std::toupper() function, and does not care about unicode.
- */
-std::string stringToUpper(std::string const& str);
-
 /**
  * Returns the string which is right aligned with padding on the left.
  */
-- 
GitLab