strings: Helper to remove pattern from the end

This commit is contained in:
Cody Northrop
2017-07-18 16:19:27 -06:00
committed by Baldur Karlsson
parent cde58e7326
commit 296854da73
2 changed files with 14 additions and 0 deletions
+13
View File
@@ -107,3 +107,16 @@ bool endswith(const std::string &value, const std::string &ending)
return (0 == value.compare(value.length() - ending.length(), ending.length(), ending));
}
std::string removeFromEnd(const std::string &value, const std::string &ending)
{
string::size_type pos;
pos = value.rfind(ending);
// Create new string from beginning to pattern
if(string::npos != pos)
return value.substr(0, pos);
// If pattern not found, just return original string
return value;
}
+1
View File
@@ -38,6 +38,7 @@ std::string strupper(const std::string &str);
std::wstring strupper(const std::wstring &str);
std::string trim(const std::string &str);
std::string removeFromEnd(const std::string &value, const std::string &ending);
uint32_t strhash(const char *str, uint32_t existingHash = 5381);