Add some more utils funcs
This commit is contained in:
@ -89,12 +89,13 @@ namespace Utils
|
||||
|
||||
bool StartsWith(const std::string& haystack, const std::string& needle)
|
||||
{
|
||||
return (haystack.size() >= needle.size() && haystack.substr(0, needle.size()) == needle);
|
||||
return haystack.find(needle) == 0; // If the pos of the first found char is 0, string starts with 'needle'
|
||||
}
|
||||
|
||||
bool EndsWith(const std::string& haystack, const std::string& needle)
|
||||
{
|
||||
return (haystack.size() >= needle.size() && haystack.substr(haystack.size() - needle.size()) == needle);
|
||||
if (needle.size() > haystack.size()) return false;
|
||||
return std::equal(needle.rbegin(), needle.rend(), haystack.rbegin());
|
||||
}
|
||||
|
||||
int IsSpace(int c)
|
||||
|
@ -77,10 +77,10 @@ namespace Utils
|
||||
int IsSpace(int c);
|
||||
std::string ToLower(std::string input);
|
||||
std::string ToUpper(std::string input);
|
||||
bool EndsWith(const std::string& haystack, const std::string& needle);
|
||||
std::vector<std::string> Split(const std::string& str, const char delim);
|
||||
void Replace(std::string& string, const std::string& find, const std::string& replace);
|
||||
bool EndsWith(const std::string& haystack, const std::string& needle);
|
||||
bool StartsWith(const std::string& haystack, const std::string& needle);
|
||||
std::vector<std::string> Split(const std::string& str, const char delim);
|
||||
|
||||
std::string& LTrim(std::string& str);
|
||||
std::string& RTrim(std::string& str);
|
||||
|
Reference in New Issue
Block a user