diff --git a/src/string.cpp b/src/string.cpp index 31db5642..d75f5595 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -1,5 +1,5 @@ #include // for tolower and toupper -#include // for transform +#include // for transform and equal #include // for dirname and basename #if defined ARCH_WIN @@ -78,12 +78,16 @@ std::string ellipsizePrefix(const std::string& s, size_t len) { bool startsWith(const std::string& str, const std::string& prefix) { - return str.substr(0, prefix.size()) == prefix; + if (str.size() < prefix.size()) + return false; + return std::equal(prefix.begin(), prefix.end(), str.begin()); } bool endsWith(const std::string& str, const std::string& suffix) { - return str.substr(str.size() - suffix.size(), suffix.size()) == suffix; + if (str.size() < suffix.size()) + return false; + return std::equal(suffix.begin(), suffix.end(), str.end() - suffix.size()); }