Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

strings.cpp 1.0KB

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