Implement starts_with and ends_with functions
There are many options for implementing these functions; using C++14 std::equals is the simplest one, and allows for marking the function as noexcept.
This commit is contained in:
parent
064108c9c4
commit
f49eb0904b
2 changed files with 18 additions and 4 deletions
|
@ -155,9 +155,7 @@ void upcase(std::string &str);
|
|||
void lowcase(std::string &str);
|
||||
void strip_punctuation(std::string &str);
|
||||
|
||||
template<size_t N>
|
||||
bool starts_with(const char (& pfx)[N], const std::string &str) noexcept {
|
||||
return (strncmp(pfx, str.c_str(), N) == 0);
|
||||
}
|
||||
bool starts_with(const std::string &prefix, const std::string &str) noexcept;
|
||||
bool ends_with(const std::string &suffix, const std::string &str) noexcept;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue