mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-09 18:39:45 +01: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:
parent
3171a97160
commit
5d4c1b7e9d
4 changed files with 11 additions and 11 deletions
|
@ -204,7 +204,7 @@ void FILESYSTEM_mountassets(const char* path)
|
||||||
FILESYSTEM_mount(zippath.c_str());
|
FILESYSTEM_mount(zippath.c_str());
|
||||||
graphics.reloadresources();
|
graphics.reloadresources();
|
||||||
FILESYSTEM_assetsmounted = true;
|
FILESYSTEM_assetsmounted = true;
|
||||||
} else if (zip_path != "data.zip" && !endsWith(zip_path, "/data.zip") && endsWith(zip_path, ".zip")) {
|
} else if (zip_path != "data.zip" && !endsWith(zip_path.c_str(), "/data.zip") && endsWith(zip_path.c_str(), ".zip")) {
|
||||||
printf("Custom asset directory is .zip at %s\n", zip_path.c_str());
|
printf("Custom asset directory is .zip at %s\n", zip_path.c_str());
|
||||||
PHYSFS_File* zip = PHYSFS_openRead(zip_path.c_str());
|
PHYSFS_File* zip = PHYSFS_openRead(zip_path.c_str());
|
||||||
zip_path += ".data.zip";
|
zip_path += ".data.zip";
|
||||||
|
|
|
@ -323,15 +323,15 @@ bool is_positive_num(const char* str, const bool hex)
|
||||||
return true;
|
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 false;
|
||||||
}
|
}
|
||||||
return str.compare(
|
|
||||||
str.size() - suffix.size(),
|
return SDL_strcmp(&str[str_size - suffix_size], suffix) == 0;
|
||||||
suffix.size(),
|
|
||||||
suffix
|
|
||||||
) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ bool is_number(const char* str);
|
||||||
|
|
||||||
bool is_positive_num(const char* str, const bool hex);
|
bool is_positive_num(const char* str, const bool hex);
|
||||||
|
|
||||||
bool endsWith(const std::string& str, const std::string& suffix);
|
bool endsWith(const char* str, const char* suffix);
|
||||||
|
|
||||||
#define INBOUNDS_VEC(index, vector) ((int) index >= 0 && (int) index < (int) vector.size())
|
#define INBOUNDS_VEC(index, vector) ((int) index >= 0 && (int) index < (int) vector.size())
|
||||||
#define INBOUNDS_ARR(index, array) ((int) index >= 0 && (int) index < (int) SDL_arraysize(array))
|
#define INBOUNDS_ARR(index, array) ((int) index >= 0 && (int) index < (int) SDL_arraysize(array))
|
||||||
|
|
|
@ -82,7 +82,7 @@ static void levelZipCallback(const char* filename)
|
||||||
{
|
{
|
||||||
std::string filename_ = filename;
|
std::string filename_ = filename;
|
||||||
|
|
||||||
if (endsWith(filename_, ".zip"))
|
if (endsWith(filename_.c_str(), ".zip"))
|
||||||
{
|
{
|
||||||
PHYSFS_File* zip = PHYSFS_openRead(filename_.c_str());
|
PHYSFS_File* zip = PHYSFS_openRead(filename_.c_str());
|
||||||
|
|
||||||
|
@ -1822,7 +1822,7 @@ bool editorclass::load(std::string& _path)
|
||||||
// the linefeed + the extremely specific amount of
|
// the linefeed + the extremely specific amount of
|
||||||
// whitespace at the end of the contents.
|
// whitespace at the end of the contents.
|
||||||
|
|
||||||
if (endsWith(text, "\n ")) // linefeed + exactly 12 spaces
|
if (endsWith(text.c_str(), "\n ")) // linefeed + exactly 12 spaces
|
||||||
{
|
{
|
||||||
// 12 spaces + 1 linefeed = 13 chars
|
// 12 spaces + 1 linefeed = 13 chars
|
||||||
text = text.substr(0, text.length()-13);
|
text = text.substr(0, text.length()-13);
|
||||||
|
|
Loading…
Reference in a new issue