Refactor endsWith() to not use the STL

There's not really any reason for this function to use heap-allocated
strings. So I've refactored it to not do that.

I would've used SDL_strrstr(), if it existed. It does not appear to
exist. But that's okay.
This commit is contained in:
Misa
2021-02-26 15:29:37 -08:00
committed by Ethan Lee
parent 3171a97160
commit 5d4c1b7e9d
4 changed files with 11 additions and 11 deletions

View File

@@ -323,15 +323,15 @@ bool is_positive_num(const char* str, const bool hex)
return true;
}
bool endsWith(const std::string& str, const std::string& suffix)
bool endsWith(const char* str, const char* suffix)
{
if (str.size() < suffix.size())
const size_t str_size = SDL_strlen(str);
const size_t suffix_size = SDL_strlen(suffix);
if (str_size < suffix_size)
{
return false;
}
return str.compare(
str.size() - suffix.size(),
suffix.size(),
suffix
) == 0;
return SDL_strcmp(&str[str_size - suffix_size], suffix) == 0;
}