mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user