feat add StartsWith,EndsWith
Some checks failed
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 34s
linux-x64-gcc / linux-gcc (Release) (push) Failing after 37s

This commit is contained in:
tqcq 2024-03-03 17:19:11 +08:00
parent 333281ec06
commit d048a2676c
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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