Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strings.cpp 845B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*!
  2. * \file src/utils/strings.cpp
  3. * \brief String handling utilities
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "utils/filesystem.h"
  9. #include "utils/strings.h"
  10. std::string findAndReplace(std::string s, std::string find, std::string replace) {
  11. size_t p = s.find(find);
  12. while (p != std::string::npos) {
  13. s.erase(p, find.length());
  14. s.insert(p, replace);
  15. p = s.find(find);
  16. }
  17. return s;
  18. }
  19. std::string expandHomeDirectory(std::string s) {
  20. if ((s.length() > 0) && (s[0] == '~')) {
  21. s.erase(0, 1);
  22. s.insert(0, getHomeDirectory());
  23. }
  24. return s;
  25. }
  26. bool stringEndsWith(std::string s, std::string suffix) {
  27. if (s.length() >= suffix.length()) {
  28. std::string end = s.substr(s.length() - suffix.length());
  29. return (end == suffix);
  30. }
  31. return false;
  32. }