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.

42 lines
1.3KB

  1. #pragma once
  2. #include "common.hpp"
  3. namespace rack {
  4. /** Supplemental `std::string` functions
  5. */
  6. namespace string {
  7. /** Converts a `printf()` format string and optional arguments into a std::string
  8. Remember that "%s" must reference a `char *`, so use `.c_str()` for `std::string`s.
  9. */
  10. std::string f(const char *format, ...);
  11. /** Replaces all characters to lowercase letters */
  12. std::string lowercase(const std::string &s);
  13. /** Replaces all characters to uppercase letters */
  14. std::string uppercase(const std::string &s);
  15. /** Truncates and adds "..." to a string, not exceeding `len` characters */
  16. std::string ellipsize(const std::string &s, size_t len);
  17. bool startsWith(const std::string &str, const std::string &prefix);
  18. bool endsWith(const std::string &str, const std::string &suffix);
  19. /** Extracts portions of a path */
  20. std::string directory(const std::string &path);
  21. std::string filename(const std::string &path);
  22. /** Extracts the portion of a path without the extension */
  23. std::string basename(const std::string &path);
  24. /** Extracts the extension of a path */
  25. std::string extension(const std::string &path);
  26. struct CaseInsensitiveCompare {
  27. bool operator()(const std::string &a, const std::string &b) const {
  28. return lowercase(a) < lowercase(b);
  29. }
  30. };
  31. } // namespace string
  32. } // namespace rack