Skip to content
Snippets Groups Projects
Commit 54818e78 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Extract stringToUpper() function.

Place it in StringTools.
parent f1523c11
No related branches found
No related tags found
No related merge requests found
......@@ -12,10 +12,9 @@
*/
#include "FileTools.h"
#include "StringTools.h"
#include <sys/stat.h>
#include <algorithm>
#include <cctype>
namespace BaseLib
{
......@@ -114,13 +113,8 @@ std::string getFileExtension(const std::string &path)
bool hasFileExtension(std::string const& extension, std::string const& filename)
{
std::string ext = extension; // Copy for modification.
std::transform(ext.begin(), ext.end(), ext.begin(),
(int(*)(int)) std::toupper);
std::string file_ext = getFileExtension(filename);
std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(),
(int(*)(int)) std::toupper);
std::string ext = stringToUpper(extension); // Copy for modification.
std::string file_ext = stringToUpper(getFileExtension(filename));
return ext == file_ext;
}
......
......@@ -12,6 +12,9 @@
#include "StringTools.h"
#include <algorithm>
#include <cctype>
namespace BaseLib {
std::list<std::string> splitString(const std::string &str, char delim)
......@@ -49,6 +52,13 @@ void trim(std::string &str, char ch)
else str.erase(str.begin(), str.end());
}
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;
}
} // end namespace BaseLib
......
......@@ -70,6 +70,13 @@ template<typename T> T str2number (const std::string &str)
*/
void trim(std::string &str, char ch=' ');
/**
* Returs 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);
} // end namespace BaseLib
#ifdef MSVC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment