From 34e89bfcd3ce032bebc236e42dec208ac62c2c62 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 21 Jun 2020 14:25:23 -0700 Subject: [PATCH] Move endsWith() to UtilityClass.cpp and put it in header file This ensures that endsWith() can be used outside of editor.cpp. When leo60228 originally wrote endsWith(), it was static, but I asked him on Discord just now and he more-or-less confirmed that it's fine if it's not static. If it was static, it would be confined to UtilityClass.cpp now instead! --- desktop_version/src/UtilityClass.cpp | 13 +++++++++++++ desktop_version/src/UtilityClass.h | 2 ++ desktop_version/src/editor.cpp | 13 ------------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index f6931bf8..c677a10b 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -230,3 +230,16 @@ bool is_positive_num(const std::string& str, bool hex) } return true; } + +bool endsWith(const std::string& str, const std::string& suffix) +{ + if (str.size() < suffix.size()) + { + return false; + } + return str.compare( + str.size() - suffix.size(), + suffix.size(), + suffix + ) == 0; +} diff --git a/desktop_version/src/UtilityClass.h b/desktop_version/src/UtilityClass.h index dcd6c6cd..fc88e1c7 100644 --- a/desktop_version/src/UtilityClass.h +++ b/desktop_version/src/UtilityClass.h @@ -13,6 +13,8 @@ std::vector split(const std::string &s, char delim); bool is_positive_num(const std::string& str, bool hex); +bool endsWith(const std::string& str, const std::string& suffix); + #define INBOUNDS(index, vector) ((int) index >= 0 && (int) index < (int) vector.size()) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 8140131e..7300c5d2 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -88,19 +88,6 @@ bool compare_nocase (std::string first, std::string second) return false; } -static bool endsWith(const std::string& str, const std::string& suffix) -{ - if (str.size() < suffix.size()) - { - return false; - } - return str.compare( - str.size() - suffix.size(), - suffix.size(), - suffix - ) == 0; -} - void editorclass::loadZips() { directoryList = FILESYSTEM_getLevelDirFileNames();