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.

48 lines
1.5KB

  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. std::string trim(const std::string &s);
  16. /** Truncates and adds "..." to a string, not exceeding `len` characters */
  17. std::string ellipsize(const std::string &s, size_t len);
  18. bool startsWith(const std::string &str, const std::string &prefix);
  19. bool endsWith(const std::string &str, const std::string &suffix);
  20. /** Extracts portions of a path */
  21. std::string directory(const std::string &path);
  22. std::string filename(const std::string &path);
  23. /** Extracts the portion of a path without the extension */
  24. std::string basename(const std::string &path);
  25. /** Extracts the extension of a path */
  26. std::string extension(const std::string &path);
  27. /** Scores how well a query matches a string.
  28. A score of 0 means no match.
  29. The score is arbitrary and is only meaningful for sorting.
  30. */
  31. float fuzzyScore(const std::string &s, const std::string &query);
  32. struct CaseInsensitiveCompare {
  33. bool operator()(const std::string &a, const std::string &b) const {
  34. return lowercase(a) < lowercase(b);
  35. }
  36. };
  37. } // namespace string
  38. } // namespace rack