|
|
@@ -5,7 +5,7 @@
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
-namespace Utilities {
|
|
|
+namespace StringAlgorithm {
|
|
|
namespace Internal {
|
|
|
|
|
|
size_t find_nth(const std::string& haystack, size_t pos, const std::string& needle, size_t nth)
|
|
|
@@ -48,6 +48,24 @@ bool istarts_with(const std::string& subject, const std::string& find)
|
|
|
return starts_with(s, f);
|
|
|
}
|
|
|
|
|
|
+bool ends_with(const std::string& subject, const std::string& find)
|
|
|
+{
|
|
|
+ if (subject.size() >= find.size() && subject.compare(subject.size() - find.size(), find.size(), find) == 0)
|
|
|
+ return true;
|
|
|
+ else
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool iends_with(const std::string& subject, const std::string& find)
|
|
|
+{
|
|
|
+ std::string s(subject);
|
|
|
+ std::string f(find);
|
|
|
+ std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
|
|
+ std::transform(f.begin(), f.end(), f.begin(), ::tolower);
|
|
|
+
|
|
|
+ return ends_with(s, f);
|
|
|
+}
|
|
|
+
|
|
|
std::vector<std::string> split(const std::string& subject, const char& delimiter)
|
|
|
{
|
|
|
std::stringstream ss(subject);
|
|
|
@@ -100,4 +118,4 @@ std::string::const_iterator find_nth(const std::string& haystack, const std::str
|
|
|
return iterator;
|
|
|
}
|
|
|
|
|
|
-} // namespace Utilities
|
|
|
+} // namespace StringAlgorithm
|