StringBasics.cpp 871 B

1234567891011121314151617181920
  1. // Include own headers
  2. #include "StringBasics.hpp"
  3. // Include dependencies
  4. #include <algorithm>
  5. #include <cctype>
  6. // From https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c
  7. // Lowercase from https://stackoverflow.com/questions/313970/how-to-convert-an-instance-of-stdstring-to-lower-case
  8. bool StringBasics::endsWithCaseInsensitive(std::string const &fullStringInput, std::string const &endingInput) {
  9. std::string fullString = fullStringInput;
  10. std::transform(fullString.begin(), fullString.end(), fullString.begin(), ::tolower);
  11. std::string ending = endingInput;
  12. std::transform(ending.begin(), ending.end(), ending.begin(), ::tolower);
  13. if (fullString.length() >= ending.length()) {
  14. return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
  15. } else {
  16. return false;
  17. }
  18. }