Created
June 20, 2024 05:50
-
-
Save juliarose/81fa81a3eefa15386cf948f98a325fe2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @brief Checks if a string ends with a given suffix. | |
* | |
* @param fullString The string to check. | |
* @param ending The suffix to check for. | |
* @return True if the string ends with the suffix, false otherwise. | |
*/ | |
bool hasEnding(std::string const &fullString, std::string const &ending) { | |
// Sourced from https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c | |
int fullStringLen = fullString.length(); | |
int endingLen = ending.length(); | |
// If the ending is longer than the full string, it can't be a suffix | |
if (endingLen > fullStringLen) { | |
return false; | |
} | |
int offset = fullString.compare(fullStringLen - endingLen, endingLen, ending); | |
return 0 == offset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment