Utils.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #define CONTAINS(vec, val) (std::find(vec.begin(), vec.end(), val) != vec.end())
  8. std::string Trim(const std::string& str);
  9. bool StartsWith(const std::string& str, const std::string& value);
  10. bool EndsWith(const std::string& str, const std::string& value);
  11. std::string CutStart(const std::string& str, const std::string& value);
  12. std::string CutEnd(const std::string& str, const std::string& value);
  13. std::string GetFirstWord(const std::string& str);
  14. std::string ReplaceAll(const std::string& src, const std::string& from, const std::string& to);
  15. std::string RemoveAll(const std::string& src, const std::string& value);
  16. std::string ReplaceFirst(const std::string& src, const std::string& from, const std::string& to);
  17. std::string RemoveFirst(const std::string& src, const std::string& value);
  18. std::vector<std::string> Split(const std::string& str, char delim);
  19. std::vector<std::string> Split(const std::string& str, const std::string& delim);
  20. std::string Join(const std::vector<std::string>& values, const std::string& separator);
  21. bool Contains(const std::string& str, const std::string& substr);
  22. bool Contains(const std::string& str, char c);
  23. // Return all after last found substring
  24. std::string CutToLast(const std::string& src, const std::string& value, bool inclusive);
  25. // Return all after last /
  26. std::string GetFileName(const std::string& path);
  27. // Return all before last /
  28. std::string WithoutFileName(const std::string& path);
  29. // First letter to lower case. Works only for ASCII
  30. std::string FirstCharToLower(const std::string& str);
  31. std::string JoinNonEmpty(const std::vector<std::string>& strings, const std::string& separator);
  32. std::string ToIdentifier(const std::string& str);
  33. bool CreateDir(const std::string& pathName);