[Feature] Add Strings::BeginsWith() and Strings::EndsWith() (#3471)

* [Strings] Add Strings::BeginsWith() and Strings::EndsWith()

# Notes
- These are useful so that we don't have to manually calculate size or perform a substring.

* Update questmgr.cpp

* Update client.cpp
This commit is contained in:
Alex King
2023-07-03 09:40:44 -04:00
committed by GitHub
parent 2717fcc339
commit ee14aed8de
7 changed files with 73 additions and 68 deletions
+23
View File
@@ -695,8 +695,31 @@ std::string Strings::ConvertToDigit(int n, const std::string& suffix)
return NUM_TO_ENGLISH_X[n] + suffix;
}
}
bool Strings::BeginsWith(const std::string& subject, const std::string& search)
{
if (subject.length() < search.length()) {
return false;
}
return subject.starts_with(search);
}
bool Strings::EndsWith(const std::string& subject, const std::string& search)
{
if (subject.length() < search.length()) {
return false;
}
return subject.ends_with(search);
}
bool Strings::Contains(const std::string& subject, const std::string& search)
{
if (subject.length() < search.length()) {
return false;
}
return subject.find(search) != std::string::npos;
}
+2
View File
@@ -128,6 +128,8 @@ public:
static bool ToBool(const std::string& bool_string);
static inline bool EqualFold(const std::string &string_one, const std::string &string_two) { return strcasecmp(string_one.c_str(), string_two.c_str()) == 0; }
static std::string Random(size_t length);
static bool BeginsWith(const std::string& subject, const std::string& search);
static bool EndsWith(const std::string& subject, const std::string& search);
template<typename T>
static std::string