utils.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef UTILS_H
  2. #define UTILS_H
  3. #include <string>
  4. #include <regex>
  5. #include <vector>
  6. const char *trim_path(const char *filepath);
  7. bool replace(std::string &str, const std::string &from, const std::string &to);
  8. bool replace(std::string &str, const char *from, const char *to);
  9. void ansi_clean(std::string &str);
  10. void high_ascii(std::string &str);
  11. void trim(std::string &str);
  12. std::smatch ansi_newline(const std::string &str);
  13. std::string clean_string(const std::string &source);
  14. std::vector<std::string> split(const std::string &line);
  15. std::vector<std::string> split(const std::string &line, const std::string &by);
  16. bool startswith(const std::string &line, const std::string &has);
  17. bool endswith(const std::string &line, const std::string &has);
  18. bool in(const std::string &line, const std::string &has);
  19. std::string repr(const std::string &source);
  20. bool density_clear(int sector, int density, int navhaz=0);
  21. bool file_exists(const std::string &name);
  22. bool at_command_prompt(const std::string &prompt);
  23. bool at_computer_prompt(const std::string &prompt);
  24. bool at_planet_prompt(const std::string &prompt);
  25. void str_toupper(std::string &text);
  26. void str_tolower(std::string &text);
  27. void remove_telnet_commands(std::string &text);
  28. /**
  29. * Safe stoi
  30. *
  31. * returns 0 on error/exception.
  32. *
  33. * @param text
  34. * @return int
  35. */
  36. int sstoi(const std::string &text, int failure=0);
  37. #endif