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.

38 lines
1.2KB

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