diff --git a/include/sled/strings/utils.h b/include/sled/strings/utils.h index e6ea79c..b5e8aeb 100644 --- a/include/sled/strings/utils.h +++ b/include/sled/strings/utils.h @@ -20,6 +20,8 @@ std::string TrimLeft(const std::string &str, const std::string &chars = " \t\n\r"); std::string TrimRight(const std::string &str, const std::string &chars = " \t\n\r"); +bool EndsWith(const std::string &str, const std::string &suffix); +bool StartsWith(const std::string &str, const std::string &prefix); }// namespace sled #endif// SLED_STRINGS_UTILS_H diff --git a/src/strings/utils.cc b/src/strings/utils.cc index 54ee93f..ef66646 100644 --- a/src/strings/utils.cc +++ b/src/strings/utils.cc @@ -65,4 +65,18 @@ TrimRight(const std::string &str, const std::string &chars) return str.substr(0, end); } +bool +EndsWith(const std::string &str, const std::string &suffix) +{ + return str.size() >= suffix.size() + && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +bool +StartsWith(const std::string &str, const std::string &prefix) +{ + return str.size() >= prefix.size() + && str.compare(0, prefix.size(), prefix) == 0; +} + }// namespace sled