Last active
January 30, 2024 08:27
-
-
Save royratcliffe/670884e9d763f6ead09a50fb5121cd09 to your computer and use it in GitHub Desktop.
C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
/*! | |
* \brief True if the first string ends with the second string. | |
* \param ends String with some required ending for which to test. | |
* \param with Ending to test the first string against. | |
*/ | |
bool ends_with(const std::string &ends, const std::string &with) { | |
return ends.length() >= with.length() && | |
ends.compare(ends.length() - with.length(), with.length(), with) == 0; | |
} | |
int ends_with_test(int argc, char **argv) { | |
assert(ends_with("abc", "c")); | |
assert(ends_with("abc", "")); | |
assert(!ends_with("abc", "z")); | |
assert(ends_with("a.bmp", ".bmp")); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment